From 22d664fd40c144925bf967508e999ec4486b04b9 Mon Sep 17 00:00:00 2001 From: Damien Nguyen Date: Wed, 19 Feb 2020 17:23:44 +0100 Subject: [PATCH 1/2] Accept keywords arguments for Matplotlib drawing --- projectq/backends/_circuits/_drawer_matplotlib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projectq/backends/_circuits/_drawer_matplotlib.py b/projectq/backends/_circuits/_drawer_matplotlib.py index 3b16d914e..1fd61df1f 100644 --- a/projectq/backends/_circuits/_drawer_matplotlib.py +++ b/projectq/backends/_circuits/_drawer_matplotlib.py @@ -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 @@ -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) From 92ac35d884aea4bf1c324116219910b89801e0dc Mon Sep 17 00:00:00 2001 From: Ari Jordan Date: Fri, 6 Mar 2020 12:12:02 +0100 Subject: [PATCH 2/2] fix circ drawer when depth == 1 --- projectq/backends/_circuits/_plot.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/projectq/backends/_circuits/_plot.py b/projectq/backends/_circuits/_plot.py index edc0a1f72..f972f605b 100644 --- a/projectq/backends/_circuits/_plot.py +++ b/projectq/backends/_circuits/_plot.py @@ -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