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

Fix pulse to signal converter #164

Merged

Conversation

to24toro
Copy link
Contributor

@to24toro to24toro commented Dec 13, 2022

Summary

This PR fixes the behavior of InstructionToSignals.get_signals.
Related with #140

Details and comments

Fix the behavior of get_signals when using Delay in qiskit-pulse.
Add a phase accumulation term when using shift or set frequency in qiskit-pulse.

@CLAassistant
Copy link

CLAassistant commented Dec 13, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@DanPuzzuoli DanPuzzuoli left a comment

Choose a reason for hiding this comment

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

Thanks for these very important fixes.

I've added a couple of comments in the code, but aside from this, I think we need more tests to make sure that the behaviour you're putting in is actually being implemented. The test you've added is a good test, but it doesn't test the interaction between delays and SetFrequency/ShiftFrequency instructions. Can you add another test like test_delay, but where you do ShiftFrequency before and after the delay, to test the correct signal is being generated as in the Ramsi experiment? I'd also like to see tests with multiple ShiftFrequency and SetFrequency instructions.

I also think we should update the doc string for InstructionToSignals to be very clear about what rules it is using to generate samples. You could either do this here, or it can be done in a subsequent PR.

qiskit_dynamics/pulse/pulse_to_signals.py Outdated Show resolved Hide resolved
Comment on lines +145 to +150
phase_accumulations[chan] -= (
(inst.frequency - (frequency_shifts[chan] + signals[chan].carrier_freq))
* start_sample
* self._dt
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change this to:

Suggested change
phase_accumulations[chan] -= (
(inst.frequency - (frequency_shifts[chan] + signals[chan].carrier_freq))
* start_sample
* self._dt
)
phase_accumulations[chan] += (
((frequency_shifts[chan] + signals[chan].carrier_freq) - inst.frequency)
* start_sample
* self._dt
)

I just find the negative slightly confusing in this case.

Copy link
Contributor Author

@to24toro to24toro Dec 14, 2022

Choose a reason for hiding this comment

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

I adapt this to phase_accumulations[chan] -= inst.frequency * start_sample * self._dt.
Do I also need to change the sign to plus ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No that's okay - you can actually leave both as is - it was only a slight preference on my part, but doesn't really matter.

@to24toro
Copy link
Contributor Author

Thank you for reviewing.
I added tests about the combination of ShiftFrequency, Set Frequency, and delay to confirm a phase accumulation. It may be a little bit too specific...

Comment on lines 129 to 130
duration = 20
dt = 0.222
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 defined variables often used here. We can find other frequently used number in other tests. So We can define these variables often used at setUp method. I may refactor after merging this PR.

Copy link
Collaborator

@DanPuzzuoli DanPuzzuoli left a comment

Choose a reason for hiding this comment

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

Nice changes to the tests - I think this pretty much covers everything.

I found the tests somewhat confusing to verify; the parentheses were a bit confusing and how the phase accumulation was calculated was not explicit. I've just opened a PR to your branch that changes the tests to how I'd like them to look.

If you can take a look at that and merge it if it looks fine, then the only things left to do are:

  • It seems you need to sign the CLA still.
  • Make sure this PR passes the linter.

@to24toro to24toro force-pushed the fix_pulse_to_signal_converter branch from 65ab244 to 4440c98 Compare December 15, 2022 04:35
@to24toro
Copy link
Contributor Author

Thank you for improving my codes.
Definitely, predefining phase_accumulation and freq_shift is more readable.

I fixed the author committing to this PR because I used the wrong one.

@DanPuzzuoli DanPuzzuoli self-requested a review December 15, 2022 18:01
DanPuzzuoli
DanPuzzuoli previously approved these changes Dec 15, 2022
Copy link
Collaborator

@DanPuzzuoli DanPuzzuoli left a comment

Choose a reason for hiding this comment

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

I just made some final documentation changes, and it looks good to me! Will merge once tests pass.

@DanPuzzuoli DanPuzzuoli merged commit 0229a2f into qiskit-community:main Dec 15, 2022
to24toro added a commit to to24toro/qiskit-dynamics that referenced this pull request Feb 2, 2023
Co-authored-by: Daniel Puzzuoli <dan.puzzuoli@gmail.com>
to24toro added a commit to to24toro/qiskit-dynamics that referenced this pull request Feb 2, 2023
Co-authored-by: Daniel Puzzuoli <dan.puzzuoli@gmail.com>
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.

3 participants