Skip to content

[WIP] Qubit mapping #7390

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

[WIP] Qubit mapping #7390

wants to merge 6 commits into from

Conversation

KetpuntoG
Copy link
Contributor

@KetpuntoG KetpuntoG commented May 7, 2025

Transform that maps a circuit to a specific architecture:

import pennylane as qml

graph = {"a": ["b"], "b": ["a", "c"], "c": ["b"]}
init_mapping = {0: "a", 1: "b", 2: "c"} # optional

dev = qml.device('default.qubit')

@partial(qml.transforms.qubit_mapping, graph = graph, init_mapping = init_mapping)
@qml.qnode(dev)
def circuit():
    qml.Hadamard(0)
    qml.CNOT([0, 2])
    return qml.expval(qml.Z(2))

print(qml.draw(circuit)())
a: ──H────╭●─┤
b: ─╭SWAP─╰X─┤  <Z>
c: ─╰SWAP────┤

The algorithm has been implemented following scalability as the main requirement.
Below is a comparison with Qiskit in time and CNOTs gates added in the routing for the case of an NxN grid architecture. In all grids we are applying 5000 two-qubit gates randomly

Screenshot 2025-05-07 at 3 04 03 PM

After some trails, the naive approach is looking better in large circuits
Copy link
Contributor

github-actions bot commented May 7, 2025

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.

Copy link

codecov bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 88.00000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 99.61%. Comparing base (31647e3) to head (bb5cac1).
Report is 36 commits behind head on master.

Files with missing lines Patch % Lines
pennylane/transforms/optimization/qubit_mapping.py 87.91% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7390      +/-   ##
==========================================
- Coverage   99.64%   99.61%   -0.04%     
==========================================
  Files         514      530      +16     
  Lines       50088    50762     +674     
==========================================
+ Hits        49912    50568     +656     
- Misses        176      194      +18     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant