Skip to content

Commit

Permalink
Alessandro's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Sep 18, 2024
1 parent b0fa293 commit fa9bca8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ def _update_draw_matrix(self, matrix, idx, gate, gate_symbol=None):

return matrix, idx

def __str__(self, line_wrap: int = 70, legend: bool = False) -> str:
def _diagram(self, line_wrap: int = 70, legend: bool = False) -> str:
# build string representation of gates
matrix = [[] for _ in range(self.nqubits)]
idx = [0] * self.nqubits
Expand Down Expand Up @@ -1360,6 +1360,9 @@ def chunkstring(string, length):

return output.rstrip("\n")

def __str__(self):
return self._diagram()

def draw(self, line_wrap: int = 70, legend: bool = False):
"""Draw text circuit using unicode symbols.
Expand All @@ -1380,7 +1383,7 @@ def draw(self, line_wrap: int = 70, legend: bool = False):
+ "In release 0.2.12, the in-place print of circuits is accessible as "
+ "``Circuit._display``."
)
return self.__str__(line_wrap, legend)
return self._diagram(line_wrap, legend)

def _display(self, line_wrap: int = 70, legend: bool = False):
"""Draw text circuit using unicode symbols.
Expand All @@ -1395,4 +1398,4 @@ def _display(self, line_wrap: int = 70, legend: bool = False):
Returns:
String containing text circuit diagram.
"""
sys.stdout.write(self.__str__(line_wrap, legend))
sys.stdout.write(self._diagram(line_wrap, legend))

0 comments on commit fa9bca8

Please sign in to comment.