Skip to content

Commit

Permalink
added draw method to circuit (#266)
Browse files Browse the repository at this point in the history
* added draw method to circuit (warning about font comes up in linux env)
  • Loading branch information
JamesB-1qbit authored Jan 25, 2023
1 parent 260735e commit 3cc81c8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tangelo/linq/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import List

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

from tangelo.linq import Gate

Expand Down Expand Up @@ -144,6 +145,15 @@ 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
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

0 comments on commit 3cc81c8

Please sign in to comment.