Mixed-Y two-qubit gates use the opposite rotation angle

Open Beginner friendly
#259 2 comments 0 reactions 0 assignees View on GitHub

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

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

bug

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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tensorcircuit/tensorcircuit-ng

All issues in tensorcircuit/tensorcircuit-ng

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.