-
Notifications
You must be signed in to change notification settings - Fork 37
Remove get plot method #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
502ddc4
7f78a2a
749bc3c
18d3788
47cb297
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,54 +31,6 @@ | |
| UPPER_BOUND_DURATION, LOWER_BOUND_DURATION) | ||
|
|
||
|
|
||
| def get_plot_data_from_segments(segments): | ||
| """ | ||
| Generates arrays that can be used to produce a plot representing the shape of the driven control | ||
| constructed from the segments. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| segments : list | ||
| List of segments formatted as described in qctrlopencontrols.driven_controls.DrivenControl | ||
|
|
||
| Returns | ||
| ------- | ||
| tuple | ||
| Tuple made up of arrays for plotting formatted as | ||
| (amplitude_x,amplitude_y,amplitude_z,time) where: | ||
| - amplitude_k is the amplitude values. | ||
| - times the time corresponding to each amplitude_k coordinate. | ||
| Note that plot will have repeated times and for amplitudes, this is because it is | ||
| expected that these coordinates are to be used with plotting software that 'joins | ||
| the dots' with linear lines between each coordinate. The time array gives the x | ||
| values for all the amplitude arrays, which give the y values. | ||
|
|
||
| """ | ||
| segment_times = np.insert(np.cumsum(segments[:, 3]), 0, 0.) | ||
| coords = len(segment_times) | ||
| coord_amplitude_x = np.concatenate([[0.], segments[:, 0], [0.]]) | ||
| coord_amplitude_y = np.concatenate([[0.], segments[:, 1], [0.]]) | ||
| coord_amplitude_z = np.concatenate([[0.], segments[:, 2], [0.]]) | ||
| plot_time = [] | ||
| plot_amplitude_x = [] | ||
| plot_amplitude_y = [] | ||
| plot_amplitude_z = [] | ||
| for i in range(coords): | ||
| plot_time.append(segment_times[i]) | ||
| plot_time.append(segment_times[i]) | ||
| plot_amplitude_x.append(coord_amplitude_x[i]) | ||
| plot_amplitude_x.append(coord_amplitude_x[i + 1]) | ||
| plot_amplitude_y.append(coord_amplitude_y[i]) | ||
| plot_amplitude_y.append(coord_amplitude_y[i + 1]) | ||
| plot_amplitude_z.append(coord_amplitude_z[i]) | ||
| plot_amplitude_z.append(coord_amplitude_z[i + 1]) | ||
|
|
||
| return (np.array(plot_amplitude_x), | ||
| np.array(plot_amplitude_y), | ||
| np.array(plot_amplitude_z), | ||
| np.array(plot_time)) | ||
|
|
||
|
|
||
| class DrivenControl(QctrlObject): #pylint: disable=too-few-public-methods | ||
| """ | ||
| Creates a driven control. A driven is a set of segments made up of amplitude vectors | ||
|
|
@@ -545,43 +497,64 @@ def get_plot_formatted_arrays(self, coordinates=CARTESIAN, dimensionless_rabi_ra | |
| 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 | ||
|
|
||
| if coordinates == CARTESIAN: | ||
| (x_amplitudes, y_amplitudes, detunings, times) = get_plot_data_from_segments( | ||
| np.vstack((self.amplitude_x / normalizer, self.amplitude_y / normalizer, | ||
| self.detunings, self.durations)).T | ||
| ) | ||
| control_segments = np.vstack(( | ||
| self.amplitude_x / normalizer, | ||
| self.amplitude_y / normalizer, | ||
| self.detunings, | ||
| self.durations)).T | ||
| elif coordinates == CYLINDRICAL: | ||
| control_segments = np.vstack(( | ||
| self.rabi_rates / normalizer, | ||
| self.azimuthal_angles, | ||
| self.detunings, | ||
| self.durations)).T | ||
|
|
||
| segment_times = np.insert(np.cumsum(control_segments[:, 3]), 0, 0.) | ||
| plot_time = (segment_times[:, np.newaxis] * np.ones((1, 2))).flatten() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional: since this trick for duplicating the arrays is used in a few places, and isn't super intuitive (to me, anyway) you could pull it out into a little private helper function (which could even be defined inside this method). That lets you save some code, and implicitly gives a little bit of documentation (in the function name). |
||
| plot_amplitude_x = control_segments[:, 0] | ||
| plot_amplitude_y = control_segments[:, 1] | ||
| plot_amplitude_z = control_segments[:, 2] | ||
|
|
||
| plot_amplitude_x = np.concatenate( | ||
| ([0.], (plot_amplitude_x[:, np.newaxis] * np.ones((1, 2))).flatten(), [0.])) | ||
| plot_amplitude_y = np.concatenate( | ||
| ([0.], (plot_amplitude_y[:, np.newaxis] * np.ones((1, 2))).flatten(), [0.])) | ||
| plot_amplitude_z = np.concatenate( | ||
| ([0.], (plot_amplitude_z[:, np.newaxis] * np.ones((1, 2))).flatten(), [0.])) | ||
|
|
||
| plot_dictionary = {} | ||
| if coordinates == CARTESIAN: | ||
| plot_dictionary = { | ||
| 'amplitudes_x': x_amplitudes, | ||
| 'amplitudes_y': y_amplitudes, | ||
| 'detunings': detunings, | ||
| 'times': times | ||
| } | ||
| 'amplitudes_x': plot_amplitude_x, | ||
| 'amplitudes_y': plot_amplitude_y, | ||
| 'detunings': plot_amplitude_z, | ||
| 'times': plot_time} | ||
|
|
||
| elif coordinates == CYLINDRICAL: | ||
| (x_plot, y_plot, detunings, times) = get_plot_data_from_segments( | ||
| np.vstack((self.rabi_rates / normalizer, self.azimuthal_angles, | ||
| self.detunings, self.durations)).T | ||
| ) | ||
| 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, | ||
| 'detunings': detunings, | ||
| 'times': times | ||
| } | ||
| else: | ||
| raise ArgumentsValueError( | ||
| 'Unsupported coordinates provided: ', | ||
| arguments={'coordinates': coordinates}) | ||
|
|
||
| 'detunings': plot_amplitude_z, | ||
| 'times': plot_time} | ||
| return plot_dictionary | ||
|
|
||
| def __str__(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,7 +95,7 @@ def _check_maximum_rotation_rate( | |
| 'allowed_maximum_detuning_rate': UPPER_BOUND_DETUNING_RATE}) | ||
|
|
||
|
|
||
| def convert_dds_to_driven_controls( | ||
| def convert_dds_to_driven_control( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same story here -- if an external package is using the old method, they'll now be broken (which might be fine, I'm just not sure).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid concern. This method was public. IMHO - we should be more consistent in naming from the start. |
||
| dynamic_decoupling_sequence=None, | ||
| maximum_rabi_rate=2*np.pi, | ||
| maximum_detuning_rate=2*np.pi, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By deleting this we're changing the API in a backwards-incompatible way, so could potentially break other packages that depend on open controls. I'm not sure how releases of the package are handled -- do we need a version bump or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this method was never used anywhere and hence should be removed anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used anywhere by us, but what if there's a third party package depending on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a helper function to another method that actually gets the data for plotting. So the user should use this other method instead. I am pretty sure this should not be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sounds good. As this package matures I expect we'll need to introduce a proper versioning scheme, so that we can have proper deprecation policies for this sort of change, but in these early days I can't imagine too much going wrong.