Mixed-Y two-qubit gates use the opposite rotation angle
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- numpy, python, tensorflow
- Domain
- backend, machine-learning
Research direction
Read applications.layers.generate_double_gate() and compare the Y-basis rotations with the other basis transformations. Check the generated gates against the stated Pauli-product matrix exponentials for all nine pairs, including the four mixed-Y cases. Done means every abgate(theta) implements the specified negative-angle convention.
Written by the indexing model from the issue text.
Description
Issue Description
xygate, yxgate, yzgate, and zygate, generated by applications.layers.generate_double_gate(), implement
$$
U_{P}(\theta)=\exp\left(+\frac{i\theta}{2}P\right)
$$
instead of the family convention
$$
U_{P}(\theta)=\exp\left(-\frac{i\theta}{2}P\right),
$$
where $P$ is the corresponding two-qubit Pauli product. The Y-basis transformation uses $R_x(-\pi/2)$ before the ZZ rotation and $R_x(+\pi/2)$ after it, which maps $Z$ to $-Y$ instead of $Y$. A Pauli product containing exactly one $Y$ therefore has its angle reversed; the two minus signs in $Y\otimes Y$ cancel.
For every $a,b\in{X,Y,Z}$, abgate(theta) should implement
$$
\exp\left(-\frac{i\theta}{2}(\sigma_a\otimes\sigma_b)\right).
$$
The fix is to exchange the signs of the Y-basis rotations in generate_double_gate().
How to Reproduce
import itertools
import numpy as np
from scipy.linalg import expm
import tensorcircuit as tc
from tensorcircuit.applications import layers
tc.set_backend("numpy")
tc.set_dtype("complex128")
paulis = {
"x": np.array([[0, 1], [1, 0]], dtype=complex),
"y": np.array([[0, -1j], [1j, 0]], dtype=complex),
"z": np.diag([1, -1]),
}
theta = 0.7
print("gate error vs exp(-i theta P/2) error vs exp(+i theta P/2)")
for a, b in itertools.product("xyz", repeat=2):
c = tc.Circuit(2)
getattr(layers, a + b + "gate")(c, 0, 1, theta)
actual = np.asarray(c.matrix())
p = np.kron(paulis[a], paulis[b])
expected = expm(-0.5j * theta * p)
reversed_angle = expm(0.5j * theta * p)
print(f"{a+b} {np.linalg.norm(actual - expected):.9f}"
f" {np.linalg.norm(actual - reversed_angle):.9f}")
Error Output
gate error vs exp(-i theta P/2) error vs exp(+i theta P/2)
xx 0.000000000 1.371591230
xy 1.371591230 0.000000000
xz 0.000000000 1.371591230
yx 1.371591230 0.000000000
yy 0.000000000 1.371591230
yz 1.371591230 0.000000000
zx 0.000000000 1.371591230
zy 1.371591230 0.000000000
zz 0.000000000 1.371591230
Environment Context
TensorCircuit checkout: a6662d56c7aa8f39c12f2056dba69a6bf6c439bf.
Additional dependencies: NumPy backend, complex128; tensorflow-cpu==2.20.0 is required to import applications.layers.
Output of tc.about() and tc.__version__:
TensorCircuit version: 1.10.0
OS: Linux-6.2.0-39-generic-x86_64-with-glibc2.37
Python: 3.10.14
NumPy: 2.2.6
SciPy: 1.15.3
TensorNetwork: 0.5.3
TensorFlow: 2.20.0
JAX/JAXlib: 0.6.2/0.6.2
- Dominant language
- Python
- Stars
- 92
- Forks
- 25
- Avg merge
- 21h 12m
- Merged PRs (30d)
- 57
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorcircuit/tensorcircuit-ng
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
tensorcircuit/tensorcircuit-ng#236 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
tensorcircuit/tensorcircuit-ng#176 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
tensorcircuit/tensorcircuit-ng#175 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
tensorcircuit/tensorcircuit-ng#174 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
tensorcircuit/tensorcircuit-ng#165 · 6 comments ·
Maintainers usually reply within 1 day
All issues in tensorcircuit/tensorcircuit-ng
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OCA/account-invoicing#2529 ·
Maintainers usually reply within 1 day
-
area/ci
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textOpenbug imagen skills
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Email validation accepts a trailing newlinePossibly taken @marcello-pichini claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day