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 ResetGate to work with MPS, StabilizerSampler #4765

Merged
merged 4 commits into from
Dec 28, 2021

Conversation

daxfohl
Copy link
Contributor

@daxfohl daxfohl commented Dec 18, 2021

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_.

@daxfohl daxfohl requested review from cduck, vtomole and a team as code owners December 18, 2021 18:41
@daxfohl daxfohl requested a review from tanujkhattar December 18, 2021 18:41
@CirqBot CirqBot added the size: M 50< lines changed <250 label Dec 18, 2021
@daxfohl
Copy link
Contributor Author

daxfohl commented Dec 23, 2021

cc @95-martin-orion since you seem to be on a mission today

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

The mission continues.

cirq-core/cirq/ops/common_channels.py Show resolved Hide resolved
cirq-core/cirq/ops/common_channels_test.py Show resolved Hide resolved
if args.state._measure(axe, args.prng):
ops.X._act_on_(args, qubits)
return True
class PlusGate(raw_types.Gate):
Copy link
Collaborator

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?

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 was just thinking, maybe it makes sense to have a public PlusGate? This code is copied and pasted in several places, mostly tests.

Copy link
Collaborator

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.

Copy link
Collaborator

@95-martin-orion 95-martin-orion 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 from here. I continue to be reminded that qsim needs to support ActOnArgs :p

@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 28, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 28, 2021
@CirqBot CirqBot merged commit d58b58b into quantumlib:master Dec 28, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Dec 28, 2021
@daxfohl daxfohl deleted the reset branch December 29, 2021 20:14
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
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_`.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
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_`.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
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_`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants