Skip to content

QMapDataset demo - #1825

Open
rscadrien wants to merge 21 commits into
PennyLaneAI:masterfrom
rscadrien:master
Open

QMapDataset demo#1825
rscadrien wants to merge 21 commits into
PennyLaneAI:masterfrom
rscadrien:master

Conversation

@rscadrien

Copy link
Copy Markdown

Title: Solving the qubit mapping problem with machine learning

Summary: The demo introduces the qubit mapping problem, an NP-hard challenge in quantum computing systems with limited hardware connectivity, and explores machine learning-based approaches for solving it. It presents the QMapDataset available in PennyLane and shows how it can be used to train a Graph Neural Network to tackle the qubit mapping problem.

Relevant references:

Possible Drawbacks:

Related GitHub Issues:


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

  • GOALS — Why are we working on this now?

QMapDataset has been available in PennyLane since March 2026. The goal of this demo is to explain how to access QMapDataset in PennyLane and to show an example of how to use it for solving qubit mapping using machine learning approaches.

  • AUDIENCE — Who is this for?

Quantum scientists specializing in quantum compilation and/or the use of machine learning to improve quantum computing.

  • KEYWORDS — What words should be included in the marketing post?
    machine learning, quantum compilation, AI for Quantum

  • Which of the following types of documentation is most similar to your file?
    (more details here)

[ ] Demo

@rscadrien
rscadrien requested review from a team as code owners June 30, 2026 19:49
@github-actions

Copy link
Copy Markdown

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

Comment thread demonstrations_v2/QMapDataset_demo/metadata.json Outdated
Comment thread demonstrations_v2/QMapDataset_demo/metadata.json Outdated
Comment thread demonstrations_v2/QMapDataset_demo/demo.py
Comment on lines +552 to +554
from scipy.optimize import linear_sum_assignment

class QubitMapping_dot_Model(nn.Module):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The method make_edge_mlp has not been defined. Is this how you want it to work? Please insert your actual code here.

Suggested change
from scipy.optimize import linear_sum_assignment
class QubitMapping_dot_Model(nn.Module):
from scipy.optimize import linear_sum_assignment
def make_edge_mlp(edge_dim, out_dim, hidden=32):
return nn.Sequential(nn.Linear(edge_dim, hidden), nn.ReLU(),
nn.Linear(hidden, out_dim))
class QubitMapping_dot_Model(nn.Module):

Comment on lines +754 to +757
#

def train_loop(model, optimizer, loss_fn, loader_train, loader_valid, n_epoch, device):
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The training and test data are not defined. You may need to adjust the format of the data.

Suggested change
#
def train_loop(model, optimizer, loss_fn, loader_train, loader_valid, n_epoch, device):
"""
#
train_size, test_size = 0.8, 0.2
n = len(ds.circuits)
train_idx, val_idx = random_split(range(n), [train_size, test_size])
def train_loop(model, optimizer, loss_fn, loader_train, loader_valid, n_epoch, device):
"""

# and variance) of gradients.
#

optimizer = torch.optim.Adam(model.parameters(), lr=1e-3, weight_decay=1e-5)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You'll need to define this before you call it.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Your preview is ready 🎉!

You can view your changes here

Deployed at: 2026-07-02 18:58:44 UTC

Comment thread demonstrations_v2/QMapDataset_demo/demo.py Outdated
rscadrien and others added 2 commits July 2, 2026 14:47
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>

def make_edge_mlp(in_dim, out_dim, hid_dim=32):
"""
Create a small multilayer perceptron (MLP) used to process edge features.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This documentation might be excessive for a simple code snippet, and is incongruous with the other methods in this code block.

Comment thread demonstrations_v2/QMapDataset_demo/demo.py Outdated
Comment thread demonstrations_v2/QMapDataset_demo/demo.py Outdated
rscadrien and others added 3 commits July 2, 2026 15:06
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
Co-authored-by: drdren <104710745+drdren@users.noreply.github.com>
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.

2 participants