PennyLaneAI / pennylane

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.
https://pennylane.ai
Apache License 2.0
2.17k stars 568 forks source link

Fix wire handling on special control wires #5856

Closed albi3ro closed 2 weeks ago

albi3ro commented 2 weeks ago

Context:

A user was doing qml.CRY(0.1, wires=((0,1), 2). In this case, the control wire should be a single wire with a value (0,1). Yes, this is weird, but this is how wires work in pennylane. Instead, it was being interpretted as having two control wires, even though CRY is only for singly-controlled RY gates.

Description of the Change:

Some minor slicing changes in how we handle special controlled ops.

Now we have:

>>> qml.CZ(wires=((0,1), 2))
CZ(wires=[(0, 1), 2])

Which is consistent with how we treat wires elsewhere in pennylane.

Benefits:

Don't end up with a two qubit gate on three qubits.

Possible Drawbacks:

Still weird, and still not what the user was looking for when they provided wires like that. But at least now they'll get a better error.

Related GitHub Issues:

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.67%. Comparing base (9b3060f) to head (204ff56). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5856 +/- ## ========================================== - Coverage 99.67% 99.67% -0.01% ========================================== Files 421 421 Lines 40189 39893 -296 ========================================== - Hits 40060 39763 -297 - Misses 129 130 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.