From 8fb5f2eed2039f036b6f1fbbad87e4e048f25f0f Mon Sep 17 00:00:00 2001 From: Leonardo Andreta de Castro Date: Wed, 27 Nov 2019 11:51:19 +1100 Subject: [PATCH 1/4] Added an export method to driven_control to be used to plot with the package qctrlvisualizer. --- .../driven_controls/driven_control.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/qctrlopencontrols/driven_controls/driven_control.py b/qctrlopencontrols/driven_controls/driven_control.py index 42d32683..2d48240d 100644 --- a/qctrlopencontrols/driven_controls/driven_control.py +++ b/qctrlopencontrols/driven_controls/driven_control.py @@ -472,6 +472,65 @@ def export_to_file(self, filename=None, file_type=file_type, coordinates=coordinates) + def export(self, coordinates=CYLINDRICAL, dimensionless_rabi_rate=True): + """ Returns a dictionary formatted for plotting using the qctrl-visualizer package. + + Parameters + ---------- + dimensionless_rabi_rate: boolean + If True, normalizes the Rabi rate so that its largest absolute value is 1. + coordinates: string + Indicates whether the Rabi frequency should be plotted in terms of its + 'cylindrical' or 'cartesian' components. + + Returns + ------- + dict + Dictionary with plot data that can be used by the plot_controls + method of the qctrl-visualizer package. It has keywords 'Rabi rate' + and 'Detuning' for 'cylindrical' coordinates and 'X amplitude', 'Y amplitude', + and 'Detuning' for 'cartesian' coordinates. + + Raises + ------ + ArgumentsValueError + Raised when an argument is invalid. + """ + + if coordinates not in [CARTESIAN, CYLINDRICAL]: + raise ArgumentsValueError( + 'Unsupported coordinates provided: ', + arguments={'coordinates': coordinates}) + + if dimensionless_rabi_rate: + normalizer = self.maximum_rabi_rate + else: + normalizer = 1 + + plot_dictionary = {} + + plot_x = self.amplitude_x/normalizer + plot_y = self.amplitude_y/normalizer + plot_r = self.rabi_rates/normalizer + plot_theta = self.azimuthal_angles + plot_durations = self.durations + plot_detunings = self.detunings + + if coordinates==CARTESIAN: + plot_dictionary["X amplitude"] = [{'value': v, 'duration': t} + for v, t in zip(plot_x, plot_durations) ] + plot_dictionary["Y amplitude"] = [{'value': v, 'duration': t} + for v, t in zip(plot_y, plot_durations) ] + + if coordinates==CYLINDRICAL: + plot_dictionary["Rabi rate"] = [{'value': r*np.exp(1.j*theta), 'duration': t} + for r, theta, t in zip(plot_r, plot_theta, plot_durations) ] + + plot_dictionary["Detuning"] = [{'value': v, 'duration': t} + for v, t in zip(plot_detunings, plot_durations) ] + + return plot_dictionary + def get_plot_formatted_arrays(self, coordinates=CARTESIAN, dimensionless_rabi_rate=True): """ Gets arrays for plotting a driven control. From a7067ee3516b2d3a85ab64a779831dd4ebe8a817 Mon Sep 17 00:00:00 2001 From: Leonardo Andreta de Castro Date: Wed, 27 Nov 2019 12:35:03 +1100 Subject: [PATCH 2/4] Bug fix for method get_plot_formatted_arrays(). --- qctrlopencontrols/driven_controls/driven_control.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/qctrlopencontrols/driven_controls/driven_control.py b/qctrlopencontrols/driven_controls/driven_control.py index 2d48240d..49f5684f 100644 --- a/qctrlopencontrols/driven_controls/driven_control.py +++ b/qctrlopencontrols/driven_controls/driven_control.py @@ -606,17 +606,9 @@ def get_plot_formatted_arrays(self, coordinates=CARTESIAN, dimensionless_rabi_ra 'times': plot_time} if coordinates == CYLINDRICAL: - - x_plot = plot_amplitude_x - y_plot = plot_amplitude_y - x_plot[np.equal(x_plot, -0.0)] = 0. - y_plot[np.equal(y_plot, -0.0)] = 0. - azimuthal_angles_plot = np.arctan2(y_plot, x_plot) - amplitudes_plot = np.sqrt(np.abs(x_plot**2 + y_plot**2)) - plot_dictionary = { - 'rabi_rates': amplitudes_plot, - 'azimuthal_angles': azimuthal_angles_plot, + 'rabi_rates': plot_amplitude_x, + 'azimuthal_angles': plot_amplitude_y, 'detunings': plot_amplitude_z, 'times': plot_time} return plot_dictionary From 33b3a3d96327aba6d038ecd6557b63503465e32c Mon Sep 17 00:00:00 2001 From: Leonardo Andreta de Castro Date: Wed, 27 Nov 2019 17:07:06 +1100 Subject: [PATCH 3/4] Adds an export method to dynamical decoupling sequences that allows plotting with the qctrlvisualizer package. --- .../dynamic_decoupling_sequence.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py b/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py index 5e5fab8c..ee94a280 100644 --- a/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py +++ b/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py @@ -144,6 +144,32 @@ def number_of_offsets(self): return len(self.offsets) + def export(self): + """ Returns a dictionary formatted for plotting using the qctrl-visualizer package. + + Returns + ------- + dict + Dictionary with plot data that can be used by the plot_series + method of the qctrl-visualizer package. It has keywords 'Rabi' + and 'Detuning'. + """ + + plot_dictionary = {} + + plot_r = self.rabi_rotations + plot_theta = self.azimuthal_angles + plot_offsets = self.offsets + plot_detunings = self.detuning_rotations + + plot_dictionary["Rabi"] = [{'rotation': r*np.exp(1.j*theta), 'offset': t} + for r, theta, t in zip(plot_r, plot_theta, plot_offsets) ] + + plot_dictionary["Detuning"] = [{'rotation': v, 'offset': t} + for v, t in zip(plot_detunings, plot_offsets) ] + + return plot_dictionary + def get_plot_formatted_arrays(self, plot_format=MATPLOTLIB): """Gets arrays for plotting a pulse. From 0808d2b4dbb41d1a911d95174e953dd317941a99 Mon Sep 17 00:00:00 2001 From: Leonardo Andreta de Castro Date: Wed, 27 Nov 2019 17:23:24 +1100 Subject: [PATCH 4/4] Fixing typo in description. --- .../dynamic_decoupling_sequences/dynamic_decoupling_sequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py b/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py index ee94a280..5d71e132 100644 --- a/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py +++ b/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py @@ -150,7 +150,7 @@ def export(self): Returns ------- dict - Dictionary with plot data that can be used by the plot_series + Dictionary with plot data that can be used by the plot_sequences method of the qctrl-visualizer package. It has keywords 'Rabi' and 'Detuning'. """