-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Generalize X and Z to Weyl–Heisenberg gates #4919
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
Conversation
|
Not opposed (though outside the scope of this PR I think). Though it only saves ~10% on calculating the unitary, and calculating the unitary is only ~10% of simulating the gate, even on a single-qubit system (and obviously becomes negligible on more than ~2 qubits). |
From Cirq sync:
|
Yes, they will be non-Hermitian outside of dimension 2. |
@MichaelBroughton I tested and it does continue to work for MPS simulator. I don't think it's necessary to add regression tests since it's just a sanity check. But the following passes (as does dim 4, and zpow). def test_xpow_dim_3():
x = cirq.XPowGate(dimension=3)
sim = ccq.mps_simulator.MPSSimulator()
circuit = cirq.Circuit([x(cirq.LineQid(0, 3)) ** 0.5] * 6)
svs = [step.state.state_vector() for step in sim.simulate_moment_steps(circuit)]
expected = [
[0.67, 0.67, 0.33],
[0.0, 1.0, 0.0],
[0.33, 0.67, 0.67],
[0.0, 0.0, 1.0],
[0.67, 0.33, 0.67],
[1.0, 0.0, 0.0],
]
assert np.allclose(np.abs(svs), expected, atol=1e-2) Or if the concern is that wider circuits that include these things wouldn't "merge" properly when entangled, the above test doesn't really check that. (We'd have to figure out what such a test would even look like; might require #4512 first). |
@dabacon @maffoo Where do you configure the formatter not to reformat matrices for a file? I think it's better without the format change: https://github.com/quantumlib/Cirq/runs/6029681451?check_suite_focus=true |
You can do this with |
Bump for @95-martin-orion to review! |
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 think I'll be comfortable approving this since the dimension
parameter separates this from existing use cases, but let's verify with tests (see comment below).
@@ -1116,3 +1116,170 @@ def test_approx_eq(): | |||
assert not cirq.approx_eq(cirq.Y**0.1, cirq.Y**0.2, atol=0.05) | |||
assert cirq.approx_eq(cirq.X**0.1, cirq.X**0.2, atol=0.3) | |||
assert not cirq.approx_eq(cirq.X**0.1, cirq.X**0.2, atol=0.05) | |||
|
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.
Could you add tests demonstrating how a dim-3 qudit interacts with dim-2 X/Z, and vice versa?
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.
It just fails .on(wrong_shape_qubit)
because GateOperation checks the shapes match. However I added a test.
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.
Also note @cduck has a SingleQubitSubspaceGate
that would allow dim-K gates to be applied to a subspace of a dim-N qubit where N >= K (https://github.com/cduck/cirqtools/blob/2fbff43fa945dfa6155e83f4a72c16774ca26e42/cirqtools/qudit/common_gates.py#L85). That applies to any gate, not just these X/Z additions. However it sounds like that's not on the roadmap (#3190 (comment)).
Closes quantumlib#4782, xref quantumlib#3190 Implements X and Z as Weyl-Heisenberg gates, allowing them to operate on qudits of arbitrary dimension. The implementations are done via eigen_components, thus allowing interoperability with arbitrary exponents and global phase. Tests are done to ensure the unitaries at exponent 1 correspond to the standard definitions of Shift and Clock, at dimension 3 and 4. We also test simulations at non-integral exponents to make sure they perform as expected. Following the precedent set by the identity gate, the diagram labels remain X and Z when applied to qudits, as the qudit dimension itself is already labeled in the diagram. There is no negative impact on standard X and Z performance. In fact the performance is slightly improved over the existing X and Z gate implementations because we now cache the eigen_components rather than generate them each time. Testing shows a roughly 10% improvement in unitary calculation due to this change. Additionally this removes all the existing `PlusGate` definitions and replaces their use with the new `X` gate functionality instead.
Closes quantumlib#4782, xref quantumlib#3190 Implements X and Z as Weyl-Heisenberg gates, allowing them to operate on qudits of arbitrary dimension. The implementations are done via eigen_components, thus allowing interoperability with arbitrary exponents and global phase. Tests are done to ensure the unitaries at exponent 1 correspond to the standard definitions of Shift and Clock, at dimension 3 and 4. We also test simulations at non-integral exponents to make sure they perform as expected. Following the precedent set by the identity gate, the diagram labels remain X and Z when applied to qudits, as the qudit dimension itself is already labeled in the diagram. There is no negative impact on standard X and Z performance. In fact the performance is slightly improved over the existing X and Z gate implementations because we now cache the eigen_components rather than generate them each time. Testing shows a roughly 10% improvement in unitary calculation due to this change. Additionally this removes all the existing `PlusGate` definitions and replaces their use with the new `X` gate functionality instead.
Closes #4782, xref #3190
Implements X and Z as Weyl-Heisenberg gates, allowing them to operate on qudits of arbitrary dimension. The implementations are done via eigen_components, thus allowing interoperability with arbitrary exponents and global phase.
Tests are done to ensure the unitaries at exponent 1 correspond to the standard definitions of Shift and Clock, at dimension 3 and 4. We also test simulations at non-integral exponents to make sure they perform as expected.
Following the precedent set by the identity gate, the diagram labels remain X and Z when applied to qudits, as the qudit dimension itself is already labeled in the diagram.
There is no negative impact on standard X and Z performance. In fact the performance is slightly improved over the existing X and Z gate implementations because we now cache the eigen_components rather than generate them each time. Testing shows a roughly 10% improvement in unitary calculation due to this change.
Additionally this removes all the existing
PlusGate
definitions and replaces their use with the newX
gate functionality instead.