PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.29k stars 590 forks source link

DefaultQutritMixed measurement error #5842

Closed Gabriel-Bottrill closed 2 months ago

Gabriel-Bottrill commented 3 months ago

Context: This adds measurement error to DefaultQutritMixed device. It uses both amplitude damping and TritFlip error channels to add a realistic for qutrits measurement errror noise model.

Description of the Change: Added two keywords to qml.DefaultQutritMixed, damping_measurement_gammas and trit_flip_measurement_probs, if left as None, nothing changes. Both inputs, however, can have a list of three floats as inputs. If damping_measurement_gammas is inputted then qml.QutritAmplitudeDamping is applied with these inputs after measurement diagonalization. If trit_flip_measurement_probs is inputted then qml.TritFlip is applied after measurement diagonalization. If both are inputted then amplitude damping is applied first.

Benefits: Allows for easier and more clear measurement error applications, also allows for measurment error to be applied to non diagonal observables.

Possible Drawbacks: This method is not fully generalizable, but a more general measurement error could be applied before measurement if that is necessary. The output depends on the diagonalizing gates of the observable.

Related GitHub Issues: N/A

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.65%. Comparing base (94b5533) to head (22693de). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5842 +/- ## ========================================== - Coverage 99.66% 99.65% -0.01% ========================================== Files 427 427 Lines 40983 40730 -253 ========================================== - Hits 40845 40591 -254 - Misses 138 139 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Gabriel-Bottrill commented 3 months ago

Hi @albi3ro, @glassnotes, @mudit2812, and @trbromley, sorry for the wait, this should be my last PR for a while, I implemented measurement/readout error. I added some comments on the implementation and a few questions and would love y'alls feedback as always!

P.S. Is measurement_error ok or would you prefer readout_error?

Gabriel-Bottrill commented 3 months ago

Hi @trbromley, @glassnotes and I were discussing the best way for users to input error channels. There is the way that it is now where a user inputs a list or list of inputs for qml.QutritAmplitudeDamping and qml.TritFlip. The other way we were thinking was having a quantum function input that requires a wire as input that would be applied for each input. Finally, we talked about potentially having both inputs. Along with what the inputs are do you have an opinion about how a user should input them, especially in the case that it isn't just a quantum function? Do you think it would be best to have seperate inputs, a dictionary input, **kwargs like input, or something else?

trbromley commented 3 months ago

Hi @trbromley, @glassnotes and I were discussing the best way for users to input error channels. There is the way that it is now where a user inputs a list or list of inputs for qml.QutritAmplitudeDamping and qml.TritFlip. The other way we were thinking was having a quantum function input that requires a wire as input that would be applied for each input. Finally, we talked about potentially having both inputs. Along with what the inputs are do you have an opinion about how a user should input them, especially in the case that it isn't just a quantum function? Do you think it would be best to have seperate inputs, a dictionary input, **kwargs like input, or something else?

@Gabriel-Bottrill here are you mainly thinking about readout/measurement noise? For our NoiseModel addition in Q2/Q3, we'll be adding support for:

qml.NoiseModel({c0: n0, c1: n1, c2: n2}, meas={c3: n3}, t1=0.04)

where n3 would be a quantum function that adds channel-based noise. You can check out our progress on NoiseModels so far by going here.

With that in mind, I think we could stick with default.qutrit.mixed having some built-in arguments like damping_measurement_gammas for ease-of-use. If users want a more flexible approach, they can use a noise model.

Let me know if it would be helpful to walk you through our noise models plans!

Gabriel-Bottrill commented 3 months ago

@trbromley, thank you, I will remove the change to **readout_probs then.

mlxd commented 2 months ago

Hi @Gabriel-Bottrill We are aiming to do a release right now, and the CI runners are needed to finalise the release. I will temporarily close this PR to free the runners, so that we have the capacity to finish the release. Feel free to reopen the PR on Wednesday morning.

Gabriel-Bottrill commented 2 months ago

Hi @mlxd sorry about that, hope the release goes well!

mlxd commented 2 months ago

Hey @Gabriel-Bottrill no problem at all, and thanks again for understanding. The final PRs will be merged this evening, so you can reopen the PR as planned tomorrow morning without a problem. Feel free to reach out if there are any issues.

mudit2812 commented 2 months ago

@Gabriel-Bottrill The issue with the failing tensorflow test is resolved. I've enabled auto merge and once you update your branch CI should pass.

Gabriel-Bottrill commented 2 months ago

Thank you @mudit2812