📚 The CoCalc Library - books, templates and other resources
License: OTHER
#!/usr/bin/env python1#2# Copyright 2019 the original author or authors.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16import pygame17from qiskit import BasicAer, execute18from qiskit.tools.visualization import plot_state_qsphere1920from vqe_playground.utils.resources import load_image212223class QSphere(pygame.sprite.Sprite):24"""Displays a qsphere"""25def __init__(self, circuit):26pygame.sprite.Sprite.__init__(self)27self.image = None28self.rect = None29self.set_circuit(circuit)3031# def update(self):32# # Nothing yet33# a = 13435def set_circuit(self, circuit):36backend_sv_sim = BasicAer.get_backend('statevector_simulator')37job_sim = execute(circuit, backend_sv_sim)38result_sim = job_sim.result()3940quantum_state = result_sim.get_statevector(circuit, decimals=3)41qsphere = plot_state_qsphere(quantum_state)42qsphere.savefig("vqe_playground/utils/data/bell_qsphere.png")4344self.image, self.rect = load_image('bell_qsphere.png', -1)45self.rect.inflate_ip(-100, -100)46self.image.convert()474849