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

PauliMeasurementGate fails to construct when given an empty observable #6136

Open
Strilanc opened this issue Jun 11, 2023 · 1 comment
Open
Labels
kind/bug-report Something doesn't seem to work. status/needs-agreed-design We want to do this, but it needs an agreed upon design before implementation triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@Strilanc
Copy link
Contributor

The following should not raise an exception. It should produce a circuit which, when sampled, samples a=0 and b=1.

import cirq
circuit = cirq.Circuit(
    cirq.PauliMeasurementGate(cirq.DensePauliString(""), key="a").on(),
    cirq.PauliMeasurementGate(-cirq.DensePauliString(""), key="b").on(),
)

Failing to measure the empty pauli string is sort of like failing to search for matches to the empty string. It's a corner case but it should still work.

@Strilanc Strilanc added the kind/bug-report Something doesn't seem to work. label Jun 11, 2023
@tanujkhattar
Copy link
Collaborator

Since cirq.PauliMeasurementGate currently decomposes into a cirq.MeasurementGate, this would require us to also extend support for empty qubits to cirq.MeasurementGate so that cirq.MeasurementGate(key="a") samples a=0 and cirq.MeasurementGate(key="b", invert_mask=1) measures b=1. Although, for now invert_mask expects a tuple with 1 entry per qubit. In this case, the number of qubits are 0 so that breaks down.

Another approach would be to not change the interface of cirq.MeasurementGate and instead have a special decomposition / override the _act_on_ protocol on PauliMeasurementGate here to achieve the desired effect, but from a quick glance it looks like SimulationState.measure also expects a non-zero qubits parameter to be measured.

We can also consider leveraging the newly added capabilities of allocating a new ancilla qubit within _decompose_with_context_ to perform the measurement using a clean ancilla and that would allow us to reuse all the existing infrastructure of making measurements on non-zero qubits; at the cost of a performance penalty.

Further investigation is needed to decide what's the best way to achieve this without breaking backwards compatibility and hopefully with minimal API changes.

@tanujkhattar tanujkhattar added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on status/needs-agreed-design We want to do this, but it needs an agreed upon design before implementation labels Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-report Something doesn't seem to work. status/needs-agreed-design We want to do this, but it needs an agreed upon design before implementation triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

No branches or pull requests

2 participants