Skip to content

fix: apply control and power modifiers to Unitary in OpenQASM - #1367

Open
Iamsohungrynow wants to merge 1 commit into
amazon-braket:mainfrom
Iamsohungrynow:fix/unitary-gate-modifiers
Open

Iamsohungrynow wants to merge 1 commit into
amazon-braket:mainfrom
Iamsohungrynow:fix/unitary-gate-modifiers

Conversation

@Iamsohungrynow

Copy link
Copy Markdown

Issue #, if available:
none, found while checking how gate modifiers export to OpenQASM

Description of changes:
Unitary._to_openqasm ignored control, control_state and power, so a controlled Unitary(X) dropped its control and flipped q1 from |00> on LocalSimulator. i fold the power and the controlled block into the pragma matrix, control qubits first

Testing done:
added Unitary cases to test_gate_control and test_gate_power plus a fractional power round trip, all failing on main. full unit suite passes at 100% coverage, ruff and mypy clean

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Unitary._to_openqasm (src/braket/circuits/gates.py:3681) took control,
control_state and power as **kwargs and never used them, so a modified
Unitary was serialized as the bare matrix on its targets. On
LocalSimulator, Unitary(X) on q1 controlled on q0 flipped q1 from |00>,
and Unitary(X) with power=2 flipped |0>.

The pragma takes no modifiers, so I fold them into the matrix: the power
the same way to_unitary does, then the controlled block, with the control
qubits listed before the targets. Circuit.unitary() still has no control
argument; I left that alone.
@Iamsohungrynow
Iamsohungrynow requested a review from a team as a code owner October 14, 2026 18:33
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fe9cb10) to head (a164d09).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1367   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          171       171           
  Lines        11667     11680   +13     
  Branches      1539      1541    +2     
=========================================
+ Hits         11667     11680   +13     

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant