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

Map wires #2: Add top-level qml.map_wires function #3145

Merged
merged 38 commits into from Oct 27, 2022

Conversation

AlbertMitjans
Copy link
Collaborator

@AlbertMitjans AlbertMitjans commented Oct 6, 2022

NOTE: Review after the following PR is merged into master:

Added the qml.map_wires function, that changes the wires of the given operator, QNode, QuantumTape or quantum function according to the given wire map.

Using qml.map_wires with an operator:

>>> op = qml.RX(0.54, wires=0) + qml.PauliX(1) + (qml.PauliZ(2) @ qml.RY(1.23, wires=3))
>>> op
(RX(0.54, wires=[0]) + PauliX(wires=[1])) + (PauliZ(wires=[2]) @ RY(1.23, wires=[3]))
>>> wire_map = {0: 3, 1: 2, 2: 1, 3: 0}
>>> qml.map_wires(op, wire_map)
(RX(0.54, wires=[3]) + PauliX(wires=[2])) + (PauliZ(wires=[1]) @ RY(1.23, wires=[0]))

Using qml.map_wires with a QNode:

>>> dev = qml.device("default.qubit", wires=4)
>>> @qml.qnode(dev)
    def circuit():
        qml.RX(0.54, wires=0) @ qml.PauliX(1) @ qml.PauliZ(2) @ qml.RY(1.23, wires=3)
        return qml.probs(wires=0)
>>> mapped_circuit = qml.map_wires(circuit, wire_map)
>>> mapped_circuit()
tensor([0.92885434, 0.07114566], requires_grad=True)
>>> list(mapped_circuit.tape)
[((RX(0.54, wires=[3]) @ PauliX(wires=[2])) @ PauliZ(wires=[1])) @ RY(1.23, wires=[0]),
probs(wires=[3])]

@AlbertMitjans AlbertMitjans added the do not merge ⚠️ Do not merge the pull request until this label is removed label Oct 6, 2022
@AlbertMitjans AlbertMitjans changed the title Add top-level qml.map_wires function Map wires #2: Add top-level qml.map_wires function Oct 6, 2022
@codecov
Copy link

codecov bot commented Oct 6, 2022

Codecov Report

Merging #3145 (f227e98) into master (4e1aabc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3145   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         275      276    +1     
  Lines       24170    24216   +46     
=======================================
+ Hits        24097    24143   +46     
  Misses         73       73           
Impacted Files Coverage Δ
pennylane/measurements.py 100.00% <100.00%> (ø)
pennylane/ops/functions/__init__.py 100.00% <100.00%> (ø)
pennylane/ops/functions/map_wires.py 100.00% <100.00%> (ø)
pennylane/tape/tape.py 97.58% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@AlbertMitjans
Copy link
Collaborator Author

[sc-27112]

@AlbertMitjans AlbertMitjans marked this pull request as ready for review October 7, 2022 14:54
@AlbertMitjans AlbertMitjans added review-ready 👌 PRs which are ready for review by someone from the core team. and removed do not merge ⚠️ Do not merge the pull request until this label is removed labels Oct 18, 2022
@Jaybsoni Jaybsoni self-requested a review October 24, 2022 17:21
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Looks good to go for me 💯! Just a few small comments and failing tests to address then happy to approve

pennylane/tape/tape.py Show resolved Hide resolved
tests/ops/functions/test_map_wires.py Show resolved Hide resolved
tests/ops/functions/test_map_wires.py Show resolved Hide resolved
tests/ops/functions/test_map_wires.py Show resolved Hide resolved
Co-authored-by: Christina Lee <christina@xanadu.ai>
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Left a couple of comments about switching references from QuantumTape to QuantumScript in the documentation.

But looks great! Glad to have this 🚀

AlbertMitjans and others added 3 commits October 26, 2022 09:52
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
@AlbertMitjans
Copy link
Collaborator Author

@Jaybsoni I will wait for your approval before merging

@albi3ro albi3ro added this to the v0.27.0 milestone Oct 27, 2022
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

💯

@AlbertMitjans AlbertMitjans merged commit 9c04eef into master Oct 27, 2022
@AlbertMitjans AlbertMitjans deleted the map-wires-function branch October 27, 2022 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants