-
Notifications
You must be signed in to change notification settings - Fork 1k
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 ResetGate to work with MPS, StabilizerSampler #4765
Conversation
cc @95-martin-orion since you seem to be on a mission today |
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.
The mission continues.
if args.state._measure(axe, args.prng): | ||
ops.X._act_on_(args, qubits) | ||
return True | ||
class PlusGate(raw_types.Gate): |
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.
[No change needed] Adding a new internal gate class just for this interaction feels heavy-handed, but I guess it's necessary so we can use act_on
with the other simulator types?
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.
I was just thinking, maybe it makes sense to have a public PlusGate? This code is copied and pasted in several places, mostly tests.
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.
Just saw the test from your other comment. I wouldn't be opposed to a public PlusGate (there might even be hardware examples of such a gate), but it can be added in a separate PR.
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.
Looks good from here. I continue to be reminded that qsim needs to support ActOnArgs :p
This abstracts the implementation of ResetGate to be a measurment and then a PlusGate with an offset that gets the qubit back to the zero state (for 2-dimensional qubits, this is equivalent to X iff measurement==1). This allows Reset to work for all simulators, not just the specific ones whose cases were implemented in the existing code. There is a special consideration for density-matrix-like simulators. For these, we do not want to actually perform the measurement, as a density matrix can represent the mixed state of all measurement results. Performing the measurement would lose that information. Therefore, here we add a `can_represent_mixed_states` property to the ActOnArgs, and if that is true, then we allow the simulator to fall back to its own apply_channel implementation. This new property allows other density-matrix-like state representations (say a superoperator simulator) to adopt the same behavior without having to update `ResetGate._act_on_`.
This abstracts the implementation of ResetGate to be a measurment and then a PlusGate with an offset that gets the qubit back to the zero state (for 2-dimensional qubits, this is equivalent to X iff measurement==1). This allows Reset to work for all simulators, not just the specific ones whose cases were implemented in the existing code. There is a special consideration for density-matrix-like simulators. For these, we do not want to actually perform the measurement, as a density matrix can represent the mixed state of all measurement results. Performing the measurement would lose that information. Therefore, here we add a `can_represent_mixed_states` property to the ActOnArgs, and if that is true, then we allow the simulator to fall back to its own apply_channel implementation. This new property allows other density-matrix-like state representations (say a superoperator simulator) to adopt the same behavior without having to update `ResetGate._act_on_`.
This abstracts the implementation of ResetGate to be a measurment and then a PlusGate with an offset that gets the qubit back to the zero state (for 2-dimensional qubits, this is equivalent to X iff measurement==1). This allows Reset to work for all simulators, not just the specific ones whose cases were implemented in the existing code. There is a special consideration for density-matrix-like simulators. For these, we do not want to actually perform the measurement, as a density matrix can represent the mixed state of all measurement results. Performing the measurement would lose that information. Therefore, here we add a `can_represent_mixed_states` property to the ActOnArgs, and if that is true, then we allow the simulator to fall back to its own apply_channel implementation. This new property allows other density-matrix-like state representations (say a superoperator simulator) to adopt the same behavior without having to update `ResetGate._act_on_`.
This abstracts the implementation of ResetGate to be a measurment and then a PlusGate with an offset that gets the qubit back to the zero state (for 2-dimensional qubits, this is equivalent to X iff measurement==1).
This allows Reset to work for all simulators, not just the specific ones whose cases were implemented in the existing code.
There is a special consideration for density-matrix-like simulators. For these, we do not want to actually perform the measurement, as a density matrix can represent the mixed state of all measurement results. Performing the measurement would lose that information. Therefore, here we add a
can_represent_mixed_states
property to the ActOnArgs, and if that is true, then we allow the simulator to fall back to its own apply_channel implementation. This new property allows other density-matrix-like state representations (say a superoperator simulator) to adopt the same behavior without having to updateResetGate._act_on_
.