Skip to content

Commit

Permalink
Fix bugs with matplotlib drawer (#361)
Browse files Browse the repository at this point in the history
* Accept keywords arguments for Matplotlib drawing

* fix circ drawer when depth == 1

Co-authored-by: Damien Nguyen <damien1@huawei.com>
  • Loading branch information
AriJordan and Takishima committed Mar 25, 2020
1 parent dfff0f3 commit 67ce24b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions projectq/backends/_circuits/_drawer_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def receive(self, command_list):
if not self.is_last_engine:
self.send([cmd])

def draw(self, qubit_labels=None, drawing_order=None):
def draw(self, qubit_labels=None, drawing_order=None, **kwargs):
"""
Generates and returns the plot of the quantum circuit stored so far
Expand Down Expand Up @@ -228,4 +228,5 @@ def draw(self, qubit_labels=None, drawing_order=None):

return to_draw(self._qubit_lines,
qubit_labels=qubit_labels,
drawing_order=drawing_order)
drawing_order=drawing_order,
**kwargs)
14 changes: 8 additions & 6 deletions projectq/backends/_circuits/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ def calculate_gate_grid(axes, qubit_lines, plot_params):
]

gate_grid = np.array([0] * (depth + 1), dtype=float)

gate_grid[0] = plot_params['labels_margin'] + (width_list[0]) * 0.5
for idx in range(1, depth):
gate_grid[idx] = gate_grid[idx - 1] + column_spacing + (
width_list[idx] + width_list[idx - 1]) * 0.5
gate_grid[-1] = gate_grid[-2] + column_spacing + width_list[-1] * 0.5

gate_grid[0] = plot_params['labels_margin']
if depth > 0:
gate_grid[0] += width_list[0] * 0.5
for idx in range(1, depth):
gate_grid[idx] = gate_grid[idx - 1] + column_spacing + (
width_list[idx] + width_list[idx - 1]) * 0.5
gate_grid[-1] = gate_grid[-2] + column_spacing + width_list[-1] * 0.5
return gate_grid


Expand Down

0 comments on commit 67ce24b

Please sign in to comment.