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 Problem with Y gates in Clifford Simulator #2960

Merged
merged 1 commit into from
May 6, 2020

Conversation

alexisshaw
Copy link
Contributor

I found a bug in the Y gate for the tableau circuit simulator. Here is a fix and a test

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label May 4, 2020
Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -291,6 +291,19 @@ def test_clifford_stabilizerStateChForm_repr():
assert repr(state) == 'StabilizerStateChForm(num_qubits=2)'


def test_clifforf_circuit_SHSYSHS():
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose a simple test would check whether XZ and Y yield the same state up to global phase, but this should work just as well.

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 looking for something that could be exposed as a measurement. The error in the Y gate can only be exposed when there is a Y stabilize, and this is not the case in the proposed test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough. Thank you for adding the test!

wave_function_simulator = cirq.Simulator()

np.testing.assert_almost_equal(
clifford_simulator.simulate(circuit).final_state.wave_function(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@viathor Not related to this PR: What do you think about the fact that the clifford simulator needs a .wave_function() appended while the wave_function_simulator does not from a usability perpective? Should we make these consistent?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Such inconsistency is definitely a problem in the API. Would you like to file an issue about this?

Thanks for catching.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should there be an exponential cost in this otherwise polynomial simulator?
Generating the state vector is exponential in the number of qubits, but everything else is quadratic in the number of qubits? You would need to work around this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree exponential cost computation should not be executed implicitly in a surprising context. This does not conflict with API consistency. For example, some simulators already require that a user calls wave_function explicitly if they wish to see the reconstructed wavefunction.

In any case, none of this blocks this PR.

@alexisshaw
Copy link
Contributor Author

Was trying to consolidate into a single commit.

@alexisshaw alexisshaw requested a review from vtomole May 5, 2020 01:36
@@ -291,6 +291,19 @@ def test_clifford_stabilizerStateChForm_repr():
assert repr(state) == 'StabilizerStateChForm(num_qubits=2)'


def test_clifforf_circuit_SHSYSHS():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough. Thank you for adding the test!

wave_function_simulator = cirq.Simulator()

np.testing.assert_almost_equal(
clifford_simulator.simulate(circuit).final_state.wave_function(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree exponential cost computation should not be executed implicitly in a surprising context. This does not conflict with API consistency. For example, some simulators already require that a user calls wave_function explicitly if they wish to see the reconstructed wavefunction.

In any case, none of this blocks this PR.

@vtomole vtomole added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 5, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label May 5, 2020
@CirqBot
Copy link
Collaborator

CirqBot commented May 5, 2020

Automerge cancelled: A required status check is not present.

Missing statuses: ['Build docs', 'Build protos', 'Changed files test', 'Coverage check', 'Doc test', 'Format check', 'Lint check', 'Misc check', 'Pytest MacOS', 'Pytest Ubuntu', 'Pytest Windows', 'Type check']

@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 May 5, 2020
@alexisshaw
Copy link
Contributor Author

As there seems to be a problem with the automatic testing, would you mind if I close the PR and then re-send it?

@alexisshaw alexisshaw closed this May 5, 2020
@alexisshaw alexisshaw reopened this May 5, 2020
@alexisshaw alexisshaw requested a review from vtomole May 6, 2020 00:41
@vtomole vtomole added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 6, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label May 6, 2020
@CirqBot CirqBot merged commit 0915ac2 into quantumlib:master May 6, 2020
@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 May 6, 2020
tonybruguier pushed a commit to tonybruguier/Cirq that referenced this pull request Aug 23, 2020
I found a bug in the Y gate for the tableau circuit simulator. Here is a fix and a test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants