diff --git a/qctrlopencontrols/driven_controls/driven_control.py b/qctrlopencontrols/driven_controls/driven_control.py index 42d32683..49f5684f 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. @@ -547,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 diff --git a/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py b/qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py index 5e5fab8c..5d71e132 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_sequences + 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.