Skip to content

Fix QASM Pauli exponential Rz angle#1343

Open
marko1olo wants to merge 1 commit into
quantumlib:mainfrom
marko1olo:fix-qasm-pauli-rz-angle
Open

Fix QASM Pauli exponential Rz angle#1343
marko1olo wants to merge 1 commit into
quantumlib:mainfrom
marko1olo:fix-qasm-pauli-rz-angle

Conversation

@marko1olo
Copy link
Copy Markdown

Fixes #721.

Summary

  • doubles the uncontrolled Rz angle emitted by pauli_exp_to_qasm so it implements exp(-i * theta * Z) rather than exp(-i * theta * Z / 2)
  • updates existing QASM expectations for Pauli-Z strings
  • adds a direct regression test with non-default evolution_time

Validation

  • C:\hades\oss\.venvs\openfermion-1317\Scripts\python.exe -m pytest src\openfermion\circuits\trotter_exp_to_qgates_test.py -q
  • C:\hades\oss\.venvs\openfermion-1317\Scripts\python.exe -m black --check src\openfermion\circuits\trotter_exp_to_qgates.py src\openfermion\circuits\trotter_exp_to_qgates_test.py
  • C:\hades\oss\.venvs\openfermion-1317\Scripts\python.exe -m compileall -q src\openfermion\circuits\trotter_exp_to_qgates.py src\openfermion\circuits\trotter_exp_to_qgates_test.py
  • git diff --check

AI-assisted contribution: implemented with OpenAI Codex and reviewed locally before submission.

Use the doubled Rz angle needed to implement exp(-i theta Z) in the uncontrolled Pauli exponential path, and update QASM regression expectations accordingly.

Co-authored-by: OpenAI Codex <codex@openai.com>
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Jun 6, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request doubles the Rz rotation angle in pauli_exp_to_qasm for uncontrolled exponentiation to correct the rotation angle, updating the corresponding test cases and adding a new test. However, the reviewer identified that the controlled version of the exponentiation (when ancilla is not None) still contains a sign inversion bug, implementing exp(i * theta * P) instead of exp(-i * theta * P). To resolve this, the signs of the angles in the controlled block should be inverted, and the corresponding tests should be updated.

Comment on lines +258 to +260
ret_list = ret_list + [
"Rz {} {}".format(2 * term_coeff * evolution_time, qids[-1])
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While doubling the uncontrolled Rz angle correctly fixes the rotation for the uncontrolled case, the controlled version of the exponentiation (when ancilla is not None on lines 242-255) still contains a sign inversion bug.

Specifically, to implement $\exp(-i \theta P)$ controlled on the ancilla, the relative phase on the ancilla should be $e^{-i \theta \lambda}$ (where $\lambda \in {1, -1}$ is the eigenvalue of the target state):

  • For $\lambda = 1$, we need a relative phase of $e^{-i \theta}$.
  • For $\lambda = -1$, we need a relative phase of $e^{i \theta}$.

With the current implementation:

  • Rz on the ancilla has angle $\theta$, giving a base relative phase of $e^{i \theta}$.
  • C-Phase has angle $-2\theta$, giving an additional phase of $e^{-2i \theta}$ when the target is $|1\rangle$ ($\lambda = -1$).
    This results in:
  • For $\lambda = 1$: relative phase is $e^{i \theta}$ (should be $e^{-i \theta}$).
  • For $\lambda = -1$: relative phase is $e^{-i \theta}$ (should be $e^{i \theta}$).

This means the controlled version implements $\exp(i \theta P)$ instead of $\exp(-i \theta P)$. To fix this, the signs of the angles in the ancilla is not None block should be inverted:

  1. Change the C-Phase angle to 2 * term_coeff * evolution_time.
  2. Change the Rz angle on the ancilla to -1 * term_coeff * evolution_time (both in the if len(qids) > 0 and else branches).

Note that you will also need to update the corresponding tests in trotter_exp_to_qgates_test.py (such as test_qasm_string_Controlled_XYZ and test_qasm_string_Controlled_XYZ_ancilla_list) to reflect the corrected signs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angle of rotation in trotterize_exp_qubop_to_qasm is off by a factor of 2

1 participant