Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate control_wires in ControlledQubitUnitary #6839

Conversation

JerryChen97
Copy link
Contributor

@JerryChen97 JerryChen97 commented Jan 15, 2025

Context:
We are in favor of wires, just like what we did with MultiControlledX.

!Note: this involves a big user-interface change. With PL version <=0.40, for ControlledQubitUnitary, we have arg wires to be the target_wires, and the arg control_wires is a positional arg. To be consistent with all the other interfaces, we would like to alter this into wires to be positional and to represent control_wires+target_wires

Before:

mat = np.eye(2)
control_wires = [0]
wires = [1]
ControlledQubitUnitary(mat, control_wires, wires=wires, control_values=...)

After:

mat = np.eye(2)
wires = [0, 1]
ControlledQubitUnitary(mat, wires, control_values=...)

where the new wires should be the concatenate of old control_wires and wires

Description of the Change:
Besides the modified test files across the whole codebase involving ControlledQubitUnitary, we made the following necessary adjustments beyond the __init__ method:

  • classmethod _unflatten, _primitive_bind_call and method _controlled were adjusted accordingly following the new interface
  • move the TypeError regarding empty arg wires to the beginning.
  • add a register for ControlledQubitUnitary in bind_new_parameters.py following the pattern of CRX
  • modified the direct calls of ControlledQubitUnitary inside src files metric_tensor.py, controlled.py and matrix_ops.py.

Eco-System

This is an inevitable breaking change, so we need to immediately inform the affected repos that depend on latest PennyLane but only apply corresponding changes after this PR gets merged.

Plugins

  • Pennylane-AQT: No instances of deprecated code found.
  • Pennylane-Qiskit: No instances of deprecated code found.
  • Pennylane-IonQ: No instances of deprecated code found.
  • Pennylane-Qrack: No instances of deprecated code found.
  • Pennylane-Cirq: No instances of deprecated code found.
  • Pennylane-Qulacs: No instances of deprecated code found.

Benefits:
Unified interfaces with other controlled ops.

Possible Drawbacks:
This is a hard change to deprecate this arg. Would have to introduce errors for testing matrices.

Related GitHub Issues:
[sc-80842]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@JerryChen97 JerryChen97 self-assigned this Jan 15, 2025
@JerryChen97 JerryChen97 changed the title Deprecate control_wires in ControlledQubitUnitary in favour of `w… Deprecate control_wires in ControlledQubitUnitary Jan 15, 2025
@JerryChen97 JerryChen97 added the deprecation 🗑️ Deprecating an API or user-facing feature/behaviour label Jan 15, 2025
@JerryChen97 JerryChen97 marked this pull request as ready for review January 16, 2025 22:39
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.59%. Comparing base (4e30605) to head (9e1371d).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6839   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files         479      479           
  Lines       45339    45372   +33     
=======================================
+ Hits        45156    45189   +33     
  Misses        183      183           

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

@JerryChen97
Copy link
Contributor Author

JerryChen97 commented Jan 29, 2025

There has been some necessary changes (order change of control_wires and wires, back to previous bascially) made since our approvals yesterday. Just for standard process may I ask approvals again? @albi3ro @astralcai

JerryChen97 and others added 4 commits January 29, 2025 15:25
…#6840)

**Context:**
Providing a `QubitUnitary` as the base operator defeats the purpose
entirely and is just a messier way of using
`qml.ctrl(qml.QubitUnitary(...), ...)`

For richer context, check
#6839 for better
illustration; this PR should in principle be an add-on to it.

Note: this deprecation is related with a previous bug. Trace via
attached story link to see full discussions.

**Description of the Change:**
`__init__` and `_unflatten`: If get a `QubitUnitary` base, raise PLDW
and then get matrix by `base.matrix()`.

Added an overloading method `_flatten`. This is a fix to
#6839.

Deleted two tests that restrictively replied on the support of
`QubitUnitary` base.



**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-80843]

---------

Co-authored-by: Astral Cai <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
@JerryChen97 JerryChen97 removed the labs 🧑‍🔬 This includes changes to `qml.labs` source code label Jan 29, 2025
@JerryChen97
Copy link
Contributor Author

OK all good with current full CI tests + GPU tests. I'll remove the labels for faster CI later

@JerryChen97 JerryChen97 removed gpu ci:run-full-test-suite Run the full test-suite on the pull request labels Jan 30, 2025
@JerryChen97
Copy link
Contributor Author

CodeCov is not working properly

@JerryChen97 JerryChen97 enabled auto-merge (squash) January 31, 2025 23:01
@JerryChen97 JerryChen97 merged commit edb7545 into master Jan 31, 2025
46 checks passed
@JerryChen97 JerryChen97 deleted the Deprecate-`control_wires`-in-`ControlledQubitUnitary`-in-favour-of-`wires` branch January 31, 2025 23:16
Alex-Preciado added a commit to PennyLaneAI/catalyst that referenced this pull request Feb 1, 2025
**Context:**
PennyLaneAI/pennylane#6839
In the PR above PL deprecated the interface of
`ControlledQubitUnitary(base, control_wires, wires=target_wires)` and
use the new interface `ControlledQubitUnitary(base, wires)`.
Here we need to adjust the corresponding usage in Catalyst.

**Description of the Change:**
frontend/test/pytest/device/test_decomposition.py ln52

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-80842]

---------

Co-authored-by: Alex Preciado <[email protected]>
JerryChen97 added a commit to PennyLaneAI/pennylane-lightning that referenced this pull request Feb 3, 2025
**Context:**
Due to the deprecations of `ControlledQubitUnitary` input args
PennyLaneAI/pennylane#6839
PennyLaneAI/pennylane#6840, we need to update
several tests of lightning that use deprecated interfaces.

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-80842]

---------

Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: Alex Preciado <[email protected]>
zGoldthorpe pushed a commit to zGoldthorpe/catalyst that referenced this pull request Feb 5, 2025
**Context:**
PennyLaneAI/pennylane#6839
In the PR above PL deprecated the interface of
`ControlledQubitUnitary(base, control_wires, wires=target_wires)` and
use the new interface `ControlledQubitUnitary(base, wires)`.
Here we need to adjust the corresponding usage in Catalyst.

**Description of the Change:**
frontend/test/pytest/device/test_decomposition.py ln52

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-80842]

---------

Co-authored-by: Alex Preciado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation 🗑️ Deprecating an API or user-facing feature/behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants