Skip to content
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

Removing complex values support from Calibrations #1067

Merged
merged 38 commits into from
May 9, 2023

Conversation

TsafrirA
Copy link
Contributor

@TsafrirA TsafrirA commented Mar 2, 2023

Summary

This PR aims to remove the use of complex amplitude for SymbolicPulse in calibration experiments. Most notable changes are to the HalfAngleCal experiment and the FixedFrquencyTransmon library. With these changes, support of complex values in general raises a PendingDeprecationWarning.

Details and comments

Qiskit Terra recently changed the representation of SymbolicPulse from complex amplitude to (amp,angle). Once the deprecation is completed, some calibration experiments will fail. Additionally, assignment of complex parameters in general has caused problems recently (See Qiskit-Terra issue 9187), and is also being phased out (See Qiskit-Terra PR 9735).

Most calibration experiments are oblivious to these changes, with the exception of HalfAngleCal and RoughAmplitudeCal. The library FixedFrequencyTransmon also has to conform with the new representation.

To create as little breaking changes as possible, the following were changed:

  • FixedFrequencyTransmon library was converted to the new representation. All experiments will work as they have been with it.
  • RoughAmplitudeCal was changed such that it will work for both real or complex amp, without changing the type of the value.
  • HalfAngleCal was changed to calibrate 'angle' instead of the complex amplitude. A user which uses the FixedFrequencyTransmon library will experience no change (except for the added parameters). A user which uses custom built schedules will experience an error. To simplify the transition, most likely scenarios (schedule with no angle parameter, cal_parameter_name="amp") will raise an informative error with explanation about the needed changes.

A PendingDeprecationWarning is raised with every initialization of ParameterValue with complex type value (which also covers addition of parameter value to a calibration). Note that Qiskit-Terra PR 9897 will also raise a warning from the Terra side, for all assignment of complex parameters.

Handling of loaded calibrations which do not conform to the new representation will be sorted out once PR #1120 is merged, as it introduces a major change in calibration loading.

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2023

CLA assistant check
All committers have signed the CLA.

@wshanks
Copy link
Collaborator

wshanks commented Mar 2, 2023

Regarding deprecation warnings, I have not seen much community use of Calibrations so far, so I would not put too much effort into backwards compatibility or a transition period. Some things that could be done:

  • I think one of the most likely cases of a user having a problem is trying to load old calibrations. If BasisGateLibrary.config stored the qiskit-experiments version (like BaseExperiment.config does), we could check for this and warn about the incompatibility if attempting to load an old library. We should consider adding the qiskit-experiments version to Calibrations.config and BasisGateLibrary.config.
  • Outside of warning at library load time, we could warn at Calibration.add_parameter_value if we see a complex valued parameter being added since after loading the libraries Calibrations.from_config will load all the values with add_parameter_value. This warning makes sense if we are completely dropping support for complex parameters (in user defined calibrations) and not just in the calibrations and libraries in the qiskit-experiments package.
  • We could possibly provide a conversion function that would take an old calibrations config and split out the complex amp parameters into amp and angle parameters. I don't know that there is enough demand for this though.

@TsafrirA TsafrirA changed the title [WIP] Removing complex amplitude from Calibrations Removing complex values support from Calibrations Apr 4, 2023
Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TsafrirA , this PR looks great. I really wanted to upgrade library pulses before terra 0.25 which we start actual deprecation for complex parameters.


if self._link_parameters:
y_amp, y_beta = 1.0j * x_amp, x_beta
y_amp, y_beta, y_angle = x_amp, x_beta, x_angle + np.pi / 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think angle must be separated to cope with mixer skew, i.e. angle difference is not exactly pi/2. So they should have independent angles but default value can be angle + pi/2 for y gate. Please confirm @wshanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, but I think that would contradict the logic which was in place before. If the amplitudes were linked, then the angles were also linked in the previous implementation. Linking the angles will preserve the previous logic. This doesn't mean that the previous logic is bullet-proof. What do you think @wshanks ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair point. Since (sx, rz, cx) are enough to compose a universal set, I think experimentalist who requested sy to the library wants to correct for the mixer skew. But we can keep the logical change minimum and do this in the follow up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think mixer skew is a lower level concern that we don't need to worry about too much in the qiskit layer where some details about the signal generation hardware are abstracted. If a user is worried about it, they could choose not to link the parameters. Perhaps a user would like to link amp but not angle...we can wait until someone requests that.

The main thing regarding angle is that sx and x can have different angles to account for non-linearity in the mixer or other components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. The user has the option to unlink the parameters and therefore has full flexibility. We could be more granular as to what parameters we link and do not link but I would not go down that rabbit hole here.

qiskit_experiments/library/calibration/half_angle_cal.py Outdated Show resolved Hide resolved
TsafrirA and others added 6 commits April 16, 2023 11:33
…tion-f5c40007416cf938.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
…tion-f5c40007416cf938.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
…tion-f5c40007416cf938.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TsafrirA this looks almost good to me. Minor comments for docs. If you are happy with them I'll merge this PR. We can come back to handling of sy angle link in future.

TsafrirA and others added 3 commits April 19, 2023 02:49
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
…tion-f5c40007416cf938.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Tsafrir. I think this PR is good to go. @eggerdj @wshanks if you are happy with this upgrade I'll merge this PR.


if self._link_parameters:
y_amp, y_beta = 1.0j * x_amp, x_beta
y_amp, y_beta, y_angle = x_amp, x_beta, x_angle + np.pi / 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think mixer skew is a lower level concern that we don't need to worry about too much in the qiskit layer where some details about the signal generation hardware are abstracted. If a user is worried about it, they could choose not to link the parameters. Perhaps a user would like to link amp but not angle...we can wait until someone requests that.

The main thing regarding angle is that sx and x can have different angles to account for non-linearity in the mixer or other components.

from qiskit_experiments.test.pulse_backend import SingleTransmonTestBackend


class TestHalfAngleCal(QiskitExperimentsTestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but it would be good to have a basic test of the class working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I already opened an issue - #1123 .

qiskit_experiments/library/calibration/half_angle_cal.py Outdated Show resolved Hide resolved
qiskit_experiments/library/calibration/half_angle_cal.py Outdated Show resolved Hide resolved
@coruscating coruscating added this to the Release 0.6 milestone Apr 19, 2023
Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Minor comments only.


if self._link_parameters:
y_amp, y_beta = 1.0j * x_amp, x_beta
y_amp, y_beta, y_angle = x_amp, x_beta, x_angle + np.pi / 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. The user has the option to unlink the parameters and therefore has full flexibility. We could be more granular as to what parameters we link and do not link but I would not go down that rabbit hole here.

TsafrirA and others added 12 commits April 25, 2023 21:51
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
Co-authored-by: Will Shanks <wshaos@posteo.net>
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>
Co-authored-by: Will Shanks <wshaos@posteo.net>
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
Copy link
Collaborator

@wshanks wshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I just suggested one small grammar change.

I wonder if we should have a release note when we increase the minimum version of terra?

@wshanks
Copy link
Collaborator

wshanks commented May 8, 2023

Oops, in my last comment, I meant "release note", not "release" (I edited it now but I am just commenting since the meaning is so different).

TsafrirA and others added 2 commits May 8, 2023 16:47
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
TsafrirA and others added 2 commits May 8, 2023 22:16
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
…tion-f5c40007416cf938.yaml

Co-authored-by: Will Shanks <wshaos@posteo.net>
Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@eggerdj eggerdj added this pull request to the merge queue May 9, 2023
Merged via the queue into qiskit-community:main with commit 5459cc1 May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants