`ppr-to-mbqc` changes the Y basis with constants rounded to two decimals

Open Beginner friendly
#3,489 0 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
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
compilers

Research direction

Start with the hardcoded gate parameters in mlir/lib/PBC/Transforms/PPRToMBQC.cpp around lines 101–111, then read the related expectations in mlir/test/PBC/PPRToMBQCTest.mlir. Replace the rounded angles with full-precision values that implement the stated basis changes, and update the pass test expectations. Done means the emitted gates match the expected PPR rotation, including for a PauliRot with a Y factor.

Written by the indexing model from the issue text.

Description

Issue description

ppr-to-mbqc changes the basis of a Y factor with RotXZX(11.33, 0.00, 2.80) in front of the Z rotation or measurement and RotXZX(1.23, 0.00, 9.76) behind it. With a middle angle of zero these are RX(14.13) and RX(10.99). The angles that map Y to Z and back are 9π/2 = 14.137167 and 7π/2 = 10.995574, so the two gates are off by about 0.007 and 0.006 rad, and every PPR or PPM with a Y factor is lowered with a small error.

  • Expected behavior: The gates emitted for a PPR implement that rotation up to a global phase.

  • Actual behavior: For PauliRot(π/4, "Y") the emitted gates differ from the rotation by 8.3e-3 (Frobenius norm after removing the global phase). With 9π/2 and 7π/2 in place of 14.13 and 10.99 the difference is 0. On |0> the probabilities are [0.853519 0.146481] instead of [0.853553 0.146447].

  • Reproduces how often: Always.

  • System information:

Name: pennylane
Version: 0.45.1
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: 
Author: 
License: 
Location: <venv>/lib/python3.12/site-packages
Platform info:           macOS-26.5.1-arm64-arm-64bit
Python version:          3.12.13
Numpy version:           2.5.5
Scipy version:           1.18.1
JAX version:             0.7.1
Catalyst version:        0.15.0
Installed devices:
- nvidia.custatevec (pennylane_catalyst-0.15.0)
- nvidia.cutensornet (pennylane_catalyst-0.15.0)
- oqc.cloud (pennylane_catalyst-0.15.0)
- softwareq.qpp (pennylane_catalyst-0.15.0)
- default.clifford (pennylane-0.45.1)
- default.gaussian (pennylane-0.45.1)
- default.mixed (pennylane-0.45.1)
- default.qubit (pennylane-0.45.1)
- default.qutrit (pennylane-0.45.1)
- default.qutrit.mixed (pennylane-0.45.1)
- default.tensor (pennylane-0.45.1)
- null.qubit (pennylane-0.45.1)
- reference.qubit (pennylane-0.45.1)
- lightning.qubit (pennylane_lightning-0.45.0)

The script below gives the same output with the development wheel pennylane-catalyst 0.16.0.dev48. On main at 60970d7 the constants are the same.

Source code and tracebacks

The lowered program does not link for lightning.qubit in 0.15.0 on macOS arm64 (the symbol __catalyst__qis__RotXZX is missing), so the script reads the constants from the compiled IR and compares the gate matrices.

import numpy as np
import pennylane as qp

ppr_to_mbqc = qp.transform(pass_name="ppr-to-mbqc")
theta = np.pi / 4


def circuit():
    qp.PauliRot(theta, "Y", wires=0)
    return qp.probs()


f = ppr_to_mbqc(qp.transforms.to_ppr(qp.qnode(qp.device("null.qubit", wires=1))(circuit)))
text = qp.qjit(capture=True, target="mlir", pipelines=[("pipe", ["quantum-compilation-stage"])])(f).mlir_opt
for line in text.split("\n"):
    if "arith.constant" in line and "f64" in line or "quantum.custom" in line:
        print(line.strip())

# RotXZX(a, b, c) = RX(c) RZ(b) RX(a), see pennylane.ftqc.RotXZX
rx = lambda a: qp.matrix(qp.RX(a, wires=0))
rz = lambda a: qp.matrix(qp.RZ(a, wires=0))
emitted = rx(1.23 + 9.76) @ rz(theta) @ rx(11.33 + 2.80)
exact = rx(7 * np.pi / 2) @ rz(theta) @ rx(9 * np.pi / 2)
target = qp.matrix(qp.PauliRot(theta, "Y", wires=0))
phase_free = lambda u, v: np.linalg.norm(u - v * (np.vdot(v, u) / abs(np.vdot(v, u))))
print("distance to PauliRot(pi/4, Y) with the emitted constants:", round(float(phase_free(emitted, target)), 6))
print("distance to PauliRot(pi/4, Y) with 9 pi / 2 and 7 pi / 2:", round(float(phase_free(exact, target)), 6))
print("probabilities on |0>: emitted", np.round(np.abs(emitted[:, 0]) ** 2, 6), "| PauliRot", np.round(np.abs(target[:, 0]) ** 2, 6))

Output with Catalyst 0.15.0:

%cst = arith.constant 9.7599999999999997 : f64
%cst_0 = arith.constant 1.230000e+00 : f64
%cst_1 = arith.constant 0.78539816339744828 : f64
%cst_2 = arith.constant 2.800000e+00 : f64
%cst_3 = arith.constant 0.000000e+00 : f64
%cst_4 = arith.constant 1.133000e+01 : f64
%out_qubits = quantum.custom "RotXZX"(%cst_4, %cst_3, %cst_2) %1 : !quantum.bit
%out_qubits_5 = quantum.custom "RZ"(%cst_1) %out_qubits : !quantum.bit
%out_qubits_6 = quantum.custom "RotXZX"(%cst_0, %cst_3, %cst) %out_qubits_5 : !quantum.bit
distance to PauliRot(pi/4, Y) with the emitted constants: 0.008335
distance to PauliRot(pi/4, Y) with 9 pi / 2 and 7 pi / 2: 0.0
probabilities on |0>: emitted [0.853519 0.146481] | PauliRot [0.853553 0.146447]
Additional information

The constants are hardcoded here:

https://github.com/PennyLaneAI/catalyst/blob/60970d789f2233b90bbc7a1b38c388ce73a73d17/mlir/lib/PBC/Transforms/PPRToMBQC.cpp#L101-L111

The comment above them says that the values were generated by convert_to_mbqc_gateset and shows them as a drawn circuit, RotXZX(11.33,0.00,2.80)────RZ(PHI/2)────RotXZX(1.23,0.00,9.76). A circuit drawing prints two decimals, so the values seem to have been copied from the drawing rather than from the gate parameters. Since the middle angle is zero, RotXZX(π/2, 0, 0) in front and RotXZX(-π/2, 0, 0) behind (or the full-precision values) would be exact.

mlir/test/PBC/PPRToMBQCTest.mlir expects the same constants (arith.constant 1.13, 0.00, 2.80), so the tests of the pass agree with the current output.

For scale: of 1,500 random programs lowered with to_ppr and then ppr-to-mbqc, 1,070 are not equivalent to their input when both are simulated densely. Each of them has a Y factor at that point, and none of the 430 others differs.

Following the PennyLane AI tool use policy: this report was drafted with an AI assistant. I reviewed it and ran the examples myself.

Dominant language
Python
Stars
234
Forks
84
Avg merge
2d 12h
Merged PRs (30d)
84

Getting set up

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 PennyLaneAI/catalyst

All issues in PennyLaneAI/catalyst

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.