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

Add qubits to PauliStringPhasor #5565

Merged
merged 25 commits into from Jun 24, 2022
Merged

Add qubits to PauliStringPhasor #5565

merged 25 commits into from Jun 24, 2022

Conversation

dabacon
Copy link
Collaborator

@dabacon dabacon commented Jun 21, 2022

Currently PauliStringPhasor determines its qubits from the PauliString passed in to it. PauliStringPhasorGate is based on DensePauliString, which allows Pauli Identity gates. When PauliStringPhasorGate is used create a PauliStringPhasor, the DensePauliString is converted to a PauliString, dropping identity gates. This causes #5167, which fails gate(*qubits).gate == gate.

This fixes this problem by including all of the qubits when going from a PauliStringPhasorGate into the qubits on the PauliStringPhasor operation, and including these in the operation's gate.

This also fixes a #5564 where PauliString does preserve qubit order in it's repr.

Fixes #5167
Fixes #5564

This is a breaking change because it updates the reprs of PauliStringPhasor and PauliString. It also changes the json, though it is backwards compatible in this case.

@dabacon dabacon requested review from a team, vtomole and cduck as code owners June 21, 2022 06:00
@dabacon dabacon requested a review from pavoljuhas June 21, 2022 06:00
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jun 21, 2022
@tanujkhattar tanujkhattar self-assigned this Jun 21, 2022
Copy link
Collaborator

@tanujkhattar tanujkhattar 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 overall. Can you please also mark this PR as a breaking change because it changes the diagrams, repr and json of PauliStringPhasor?

cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_string_phasor.py Show resolved Hide resolved
cirq-core/cirq/ops/pauli_string_phasor.py Show resolved Hide resolved
@dabacon dabacon added BREAKING CHANGE For pull requests that are important to mention in release notes. area/gates labels Jun 21, 2022
dabacon and others added 4 commits June 21, 2022 09:03
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
@dabacon
Copy link
Collaborator Author

dabacon commented Jun 21, 2022

Thanks @tanujkhattar for the quick review!

@daxfohl
Copy link
Contributor

daxfohl commented Jun 21, 2022

Nice, +1 to this approach!

@dabacon
Copy link
Collaborator Author

dabacon commented Jun 22, 2022

OK, ready for rereview

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

LGTM % nits

cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
gate = PauliStringPhasorGate(
pauli_string.dense(pauli_string.qubits),
pauli_string.dense(qubits or pauli_string.qubits),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pauli_string.dense(qubits or pauli_string.qubits),
pauli_string.dense(qubits),

exponent_neg=exponent_neg,
exponent_pos=exponent_pos,
)
super().__init__(gate, pauli_string.qubits)
super().__init__(gate, qubits or pauli_string.qubits)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
super().__init__(gate, qubits or pauli_string.qubits)
super().__init__(gate, qubits)

cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_string_phasor.py Outdated Show resolved Hide resolved
Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

LGTM after mypy error is resolved.

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

CirqBot commented Jun 24, 2022

Automerge cancelled: A status check is failing.

@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 Jun 24, 2022
@dabacon dabacon merged commit 4594a1f into quantumlib:master Jun 24, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gates BREAKING CHANGE For pull requests that are important to mention in release notes. size: M 50< lines changed <250
Projects
None yet
5 participants