Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added draw method to circuit #266

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tangelo/linq/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import copy
from typing import List
import warnings

import numpy as np
from cirq.contrib.svg import SVGCircuit

from tangelo.linq import Gate

Expand Down Expand Up @@ -144,6 +146,16 @@ def is_mixed_state(self):
"""
return "MEASURE" in self.counts

def draw(self):
"""Method to output a prettier version of the circuit for use in jupyter notebooks that uses cirq SVGCircuit"""
# circular import
from tangelo.linq.translator.translate_cirq import translate_c_to_cirq
warnings.filterwarnings("ignore", message=".*findfont.*")
ValentinS4t1qbit marked this conversation as resolved.
Show resolved Hide resolved
cirq_circ = translate_c_to_cirq(self)
# Remove identity gates that are added in translate_c_to_cirq (to ensure all qubits are initialized) before drawing.
cirq_circ.__delitem__(0)
return SVGCircuit(cirq_circ)

def copy(self):
"""Return a deepcopy of circuit"""
return Circuit(copy.deepcopy(self._gates), n_qubits=self._qubits_simulated, name=self.name)
Expand Down