-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Deprecate limit_amplitude
constructor argument
#7948
Deprecate limit_amplitude
constructor argument
#7948
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 2185123677
💛 - Coveralls |
I don't actually use the code, so I'm not the best-placed person to be involved in the decision, but certainly from the outside it feels like instance-level control of limiting the amplitude is a useful thing to have. Setting the class-level attribute affects already-instantiated classes, which is (to me) very surprising to be the suggested path. |
From control electronics point of view, instance level amplitude limit is bit unrealistic. Historically this control parameter is introduced to manage pulse amplitude in SI value, which is based upon the request from the community. Usually, when we design the controller, we decide how we control the pulse amplitude. In IBM provider, amplitude indicates gradation of quantized amplitude (i.e. level of AWG output) in the digital world which will be converted into analog signal by mixing with local oscillator or LO signal (the power of the oscillator is not controllable from Qiskit). This means amplitude beyond 1.0 should not exist because we cannot output power exceeding LO power, i.e. 1.0 indicates 100% of LO power. As such, we cannot mix different amplitude representations in the same pulse channel because of physically implemented hardware. This means The assumption behind the PR is -- if one design a control electronics that employs SI amplitude, then one will not implement the whole control system with channels with different amplitude representations. Then, |
This makes me think we can delay the validation of amplitude or entire pulse parameters. If |
with self.assertRaises(PulseError): | ||
Gaussian(duration=100, sigma=1.0, amp=1.1 + 0.8j, limit_amplitude=True) | ||
GaussianSquare(duration=100, sigma=1.0, amp=1.1 + 0.8j, width=10) |
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.
Why the change to GaussianSqure?
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.
Good catch this is a typo.
warnings.warn( | ||
"Instantiating a pulse instance with 'limit_amplitude' has been deprecated. " | ||
f"Please directly update class variable '{self.__class__.__name__}.limit_amplitude.'", | ||
DeprecationWarning, | ||
stacklevel=4, | ||
) |
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.
Would it not be more flexible to deprecate the class variable instead and do this validation from one instance to the next? With this PR you either validate all your pulses or none of them. On the other hand, I'm not sure if we need the flexibility.
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.
Yeah that's the point I'd like to hear your thought. I think instance wise validation is not realistic from viewpoint of hardware, because we cannot dynamically change representation in the same channel. I think limit_amplitude
is more like a instance variable of channel rather than pulse.
#7948 (comment)
I tend to agree with @jakelishman, why are we switching this to a class variable? What about the situation where we might have two users (say one a simulator, the other a real-backend) in the same process? Or the situation where we don't want to limit to 1 due to an optimization routine, that we later rewrite all pulses that exceed 1 to be 1? |
The issue of current implementation is delegation that @jakelishman pointed out. I'm currently cleaning up the data structure of pulse schedule before starting the QPY serialization (i.e. in circuit QPY we have to maintain tons of branching logic to cover many variants of instruction data, so I'm trying to make pulse data structure bit more strict). In this sense, I find the Another simple option would be just turning it into instance variable, but this means a coder must set
this could be argument of |
If it's just the delegation and QPY serialisation we're primarily worried about, then the instance-level attributes will probably be easiest to standardise around rather than the class-level attributes - QPY currently deals with objects that can be serialised with no global state. Perhaps a more sensible state is if the class-level attribute is used during object instantiation as the default, but there's no delegation after that (e.g. something like That doesn't solve the problem you mentioned about the amplitude limiting being more a property of a |
In #7821 limit_amplitude is turned into an instance variable ( |
I'll just throw my opinion in here in case the larger design gets revisited later. I don't see much of a use case for setting @taalexander imagined a more interesting case where amplitudes could be rescaled. An interesting variant would be a provider that silently scaled down amplitudes to the max values. Perhaps you would not care that some pulses were getting scaled but would want to make sure others were exactly as specified and so marking individual pulses would make sense? I agree that basing the behavior off a class level variable is not good. @nkanazawa1989 has talked about adding a pass manager for pulse schedules. I think amplitude limit checking would fit better as a validation pass than something that is checked at class instantation and parameter assignment. Perhaps such a pass could take filtering arguments for choosing which pulses to limit or not so that this does not need to be set on each individual pulse. |
I think you're right about how to approach amplitude verification @wshanks it should also have performance improvements |
Summary
This PR deprecates
limit_amplitude
which is a constructor argument of pulse subclass. This option is confusing because user may unintentionally update class variable, or sometime instance variable.Details and comments
Fix #7932