📚 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 pygame1718from vqe_playground.utils.resources import load_image192021class CircuitDiagram(pygame.sprite.Sprite):22"""Displays a circuit diagram"""23def __init__(self, circuit):24pygame.sprite.Sprite.__init__(self)25self.image = None26self.rect = None27self.set_circuit(circuit)2829# def update(self):30# # Nothing yet31# a = 13233def set_circuit(self, circuit):34circuit_drawing = circuit.draw(output='mpl')3536# TODO: Create a save_fig method that works cross-platform37# and has exception handling38circuit_drawing.savefig("vqe_playground/utils/data/bell_circuit.png")3940self.image, self.rect = load_image('bell_circuit.png', -1)41self.image.convert()424344