diff --git a/tangelo/linq/circuit.py b/tangelo/linq/circuit.py index 7e21b1e58..e0368960c 100644 --- a/tangelo/linq/circuit.py +++ b/tangelo/linq/circuit.py @@ -22,6 +22,7 @@ from typing import List import numpy as np +from cirq.contrib.svg import SVGCircuit from tangelo.linq import Gate @@ -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)