Skip to content

Conversation

@ACE07-Sev
Copy link
Contributor

@ACE07-Sev ACE07-Sev commented Oct 27, 2025

Adjust QasmUGate to have the same unitary as qiskit U3Gate.

Fixes #7634 and #5959

@ACE07-Sev ACE07-Sev requested review from a team and vtomole as code owners October 27, 2025 11:46
@ACE07-Sev ACE07-Sev requested a review from mpharrigan October 27, 2025 11:46
@github-actions github-actions bot added the size: S 10< lines changed <50 label Oct 27, 2025
@ACE07-Sev
Copy link
Contributor Author

To check correctness:

from cirq.circuits.qasm_output import QasmUGate
import cirq

from qiskit.circuit.library import U3Gate
from qiskit.quantum_info import Operator

import numpy as np

np.allclose(
    cirq.unitary(QasmUGate(0.1/np.pi, 0.2/np.pi, 0.3/np.pi)),
    Operator(U3Gate(0.1, 0.2, 0.3)).data
)

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (12b3906) to head (fa75343).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7717   +/-   ##
=======================================
  Coverage   99.38%   99.38%           
=======================================
  Files        1091     1091           
  Lines       97901    97907    +6     
=======================================
+ Hits        97295    97301    +6     
  Misses        606      606           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pavoljuhas pavoljuhas changed the title - Native Support for U3 Gate Provide native support for U3 gate Oct 29, 2025
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

LGTM after adding tests and simplifying global phase evaluation.

Please let me know if it looks ok from your side.

@ACE07-Sev
Copy link
Contributor Author

ACE07-Sev commented Oct 29, 2025

Should I add gamma as well to enable cu from qelib1.inc ? It's basically just missing a phase gate on the control index. We can add it as an additional parameter to QasmUGate and just add it to the global phase.
https://github.com/Qiskit/qiskit/blob/main/qiskit/qasm/libs/qelib1.inc#L130C1-L152

So instead of

phase_correction_half_turns = (self.phi + self.lmda) / 2

it would be

phase_correction_half_turns = (self.phi + self.lmda) / 2 + self.gamma

To minimize changes here we can make it have a default value of 0.

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

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Support for U3 Gate

2 participants