Claude Code Plugins

Community-maintained marketplace

Feedback

Map logical to physical qubits for hardware connectivity. Use when handling SWAP routing, layout optimization, or adapting to topologies (linear, grid, heavy-hex).

Install Skill

1Download skill
2Enable skills in Claude

Open claude.ai/settings/capabilities and find the "Skills" section

3Upload to Claude

Click "Upload skill" and select the downloaded ZIP file

Note: Please verify skill by going through its instructions before using it.

SKILL.md

name qubit-mapping
description Map logical to physical qubits for hardware connectivity. Use when handling SWAP routing, layout optimization, or adapting to topologies (linear, grid, heavy-hex).

Qubit Mapping

pip install qiskit qiskit-aer numpy

Quick Start

from qiskit import transpile
from qiskit.transpiler import CouplingMap

coupling_map = CouplingMap([(0, 1), (1, 2), (2, 3)])  # Define connectivity
mapped = transpile(circuit, coupling_map=coupling_map, optimization_level=2)  # Auto-map

Topologies

from qiskit.transpiler import CouplingMap

def linear_topology(n):
    """Linear chain: 0-1-2-3"""
    return CouplingMap([(i, i+1) for i in range(n - 1)])

def grid_topology(rows, cols):
    """2D grid connectivity."""
    edges = []
    for r in range(rows):
        for c in range(cols):
            idx = r * cols + c
            if c < cols - 1: edges.append((idx, idx + 1))
            if r < rows - 1: edges.append((idx, idx + cols))
    return CouplingMap(edges)

def all_to_all(n):
    """Fully connected."""
    return CouplingMap([(i, j) for i in range(n) for j in range(i+1, n)])

Layout & Routing

from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import TrivialLayout, DenseLayout, SabreLayout, SabreSwap

def apply_layout(circuit, coupling_map, method='sabre'):
    """Choose initial qubit placement: trivial (i->i), dense (minimize distance), sabre (heuristic)."""
    layouts = {'trivial': TrivialLayout(coupling_map), 'dense': DenseLayout(coupling_map),
               'sabre': SabreLayout(coupling_map)}
    return PassManager([layouts[method]]).run(circuit)

def apply_routing(circuit, coupling_map):
    """Insert SWAPs to satisfy connectivity."""
    return PassManager([SabreSwap(coupling_map)]).run(circuit)

Full Pipeline

def full_mapping(circuit, coupling_map):
    """Complete: layout + routing + optimization."""
    from qiskit import transpile
    return transpile(circuit, coupling_map=coupling_map, layout_method='sabre',
                    routing_method='sabre', optimization_level=2)

def analyze_overhead(original, routed):
    """Measure SWAP cost."""
    return {'swaps': routed.count_ops().get('swap', 0),
            'depth_overhead': routed.depth() - original.depth()}

def compare_strategies(circuit, coupling_map):
    """Benchmark different approaches."""
    from qiskit import transpile
    strategies = {'sabre': {'layout_method': 'sabre', 'routing_method': 'sabre'},
                  'dense': {'layout_method': 'dense', 'routing_method': 'stochastic'}}
    results = {}
    for name, params in strategies.items():
        m = transpile(circuit, coupling_map=coupling_map, **params)
        results[name] = {'depth': m.depth(), 'swaps': m.count_ops().get('swap', 0)}
    return results