-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing factor of pi to parameterized Quil gate output (#3206)
This PR addresses a bug in Quil output. The current code doesn't distinguish between Cirq's `PowGate` exponents and the angle parameters for Quil gates, but they differ by a factor of pi. This is verified by comparing program unitaries before and after conversion to Quil (see below). Adds a test for this change that depends on pyQuil, so `pyquil` is added to `pip-list-dev-tools.txt`, but in the event that pyQuil is not available for import, the test is [skipped](https://docs.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency). Additionally sneaks in a change to Quil output for `ISwapPowGate` -- uses the native `XY` Quil gate when the exponent of the `ISwapPowGate` does not equal 1. ```python In [1]: import numpy as np ...: from pyquil import Program ...: from pyquil.simulation.tools import program_unitary ...: ...: from cirq import Circuit, LineQubit, QuilOutput, rx ...: ...: q0 = LineQubit(0) ...: ...: # rx(pi/2) creates an XPowGate with exponent 0.5 (and global_shift -0.5) ...: circ = Circuit(rx(np.pi/2)(q0)) ...: print(circ) ...: ...: pyquil_program = Program(str(QuilOutput(circ, (q0,)))) ...: print(pyquil_program) ...: ...: pyquil_unitary = program_unitary(pyquil_program, n_qubits=1) ...: print(pyquil_unitary) ...: ...: cirq_unitary = circ.unitary() ...: print(cirq_unitary) ...: ...: np.allclose(pyquil_unitary, cirq_unitary) ``` on `master`: ``` 0: ───Rx(0.5π)─── RX(0.5) 0 [[0.96891242+0.j 0. -0.24740396j] [0. -0.24740396j 0.96891242+0.j ]] [[0.70710678+0.j 0. -0.70710678j] [0. -0.70710678j 0.70710678+0.j ]] Out[1]: False ``` this PR: ``` 0: ───Rx(0.5π)─── RX(pi/2) 0 [[0.70710678+0.j 0. -0.70710678j] [0. -0.70710678j 0.70710678+0.j ]] [[0.70710678+0.j 0. -0.70710678j] [0. -0.70710678j 0.70710678+0.j ]] Out[1]: True ``` Related to #1742, #2386, #2983
- Loading branch information
Showing
6 changed files
with
101 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,6 @@ docs/generated | |
|
||
# Default pycharm virtual env | ||
.venv/ | ||
|
||
# pyenv configuration | ||
.python-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters