Skip to content

Commit c58eb96

Browse files
authored
Merge pull request #35 from qctrl/enhanced-figures
Added figure compatibility with the qctrl-visualizer package
2 parents f105ea7 + 0808d2b commit c58eb96

File tree

2 files changed

+87
-10
lines changed

2 files changed

+87
-10
lines changed

qctrlopencontrols/driven_controls/driven_control.py

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,65 @@ def export_to_file(self, filename=None,
472472
file_type=file_type,
473473
coordinates=coordinates)
474474

475+
def export(self, coordinates=CYLINDRICAL, dimensionless_rabi_rate=True):
476+
""" Returns a dictionary formatted for plotting using the qctrl-visualizer package.
477+
478+
Parameters
479+
----------
480+
dimensionless_rabi_rate: boolean
481+
If True, normalizes the Rabi rate so that its largest absolute value is 1.
482+
coordinates: string
483+
Indicates whether the Rabi frequency should be plotted in terms of its
484+
'cylindrical' or 'cartesian' components.
485+
486+
Returns
487+
-------
488+
dict
489+
Dictionary with plot data that can be used by the plot_controls
490+
method of the qctrl-visualizer package. It has keywords 'Rabi rate'
491+
and 'Detuning' for 'cylindrical' coordinates and 'X amplitude', 'Y amplitude',
492+
and 'Detuning' for 'cartesian' coordinates.
493+
494+
Raises
495+
------
496+
ArgumentsValueError
497+
Raised when an argument is invalid.
498+
"""
499+
500+
if coordinates not in [CARTESIAN, CYLINDRICAL]:
501+
raise ArgumentsValueError(
502+
'Unsupported coordinates provided: ',
503+
arguments={'coordinates': coordinates})
504+
505+
if dimensionless_rabi_rate:
506+
normalizer = self.maximum_rabi_rate
507+
else:
508+
normalizer = 1
509+
510+
plot_dictionary = {}
511+
512+
plot_x = self.amplitude_x/normalizer
513+
plot_y = self.amplitude_y/normalizer
514+
plot_r = self.rabi_rates/normalizer
515+
plot_theta = self.azimuthal_angles
516+
plot_durations = self.durations
517+
plot_detunings = self.detunings
518+
519+
if coordinates==CARTESIAN:
520+
plot_dictionary["X amplitude"] = [{'value': v, 'duration': t}
521+
for v, t in zip(plot_x, plot_durations) ]
522+
plot_dictionary["Y amplitude"] = [{'value': v, 'duration': t}
523+
for v, t in zip(plot_y, plot_durations) ]
524+
525+
if coordinates==CYLINDRICAL:
526+
plot_dictionary["Rabi rate"] = [{'value': r*np.exp(1.j*theta), 'duration': t}
527+
for r, theta, t in zip(plot_r, plot_theta, plot_durations) ]
528+
529+
plot_dictionary["Detuning"] = [{'value': v, 'duration': t}
530+
for v, t in zip(plot_detunings, plot_durations) ]
531+
532+
return plot_dictionary
533+
475534
def get_plot_formatted_arrays(self, coordinates=CARTESIAN, dimensionless_rabi_rate=True):
476535
""" Gets arrays for plotting a driven control.
477536
@@ -547,17 +606,9 @@ def get_plot_formatted_arrays(self, coordinates=CARTESIAN, dimensionless_rabi_ra
547606
'times': plot_time}
548607

549608
if coordinates == CYLINDRICAL:
550-
551-
x_plot = plot_amplitude_x
552-
y_plot = plot_amplitude_y
553-
x_plot[np.equal(x_plot, -0.0)] = 0.
554-
y_plot[np.equal(y_plot, -0.0)] = 0.
555-
azimuthal_angles_plot = np.arctan2(y_plot, x_plot)
556-
amplitudes_plot = np.sqrt(np.abs(x_plot**2 + y_plot**2))
557-
558609
plot_dictionary = {
559-
'rabi_rates': amplitudes_plot,
560-
'azimuthal_angles': azimuthal_angles_plot,
610+
'rabi_rates': plot_amplitude_x,
611+
'azimuthal_angles': plot_amplitude_y,
561612
'detunings': plot_amplitude_z,
562613
'times': plot_time}
563614
return plot_dictionary

qctrlopencontrols/dynamic_decoupling_sequences/dynamic_decoupling_sequence.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ def number_of_offsets(self):
144144

145145
return len(self.offsets)
146146

147+
def export(self):
148+
""" Returns a dictionary formatted for plotting using the qctrl-visualizer package.
149+
150+
Returns
151+
-------
152+
dict
153+
Dictionary with plot data that can be used by the plot_sequences
154+
method of the qctrl-visualizer package. It has keywords 'Rabi'
155+
and 'Detuning'.
156+
"""
157+
158+
plot_dictionary = {}
159+
160+
plot_r = self.rabi_rotations
161+
plot_theta = self.azimuthal_angles
162+
plot_offsets = self.offsets
163+
plot_detunings = self.detuning_rotations
164+
165+
plot_dictionary["Rabi"] = [{'rotation': r*np.exp(1.j*theta), 'offset': t}
166+
for r, theta, t in zip(plot_r, plot_theta, plot_offsets) ]
167+
168+
plot_dictionary["Detuning"] = [{'rotation': v, 'offset': t}
169+
for v, t in zip(plot_detunings, plot_offsets) ]
170+
171+
return plot_dictionary
172+
147173
def get_plot_formatted_arrays(self, plot_format=MATPLOTLIB):
148174
"""Gets arrays for plotting a pulse.
149175

0 commit comments

Comments
 (0)