Agent skill

Mq Circuit Compiler

by mindspore-ai in mindspore-ai/mindquantum

Compile and optimize quantum circuits for hardware execution using MindQuantum's compiler pipeline.

Apache-2.0Auto-check passedResearch & Science

Install Mq Circuit Compiler

skills CLI
$ npx skills add mindspore-ai/mindquantum --skill mq-circuit-compiler -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install mindspore-ai/mindquantum mq-circuit-compiler --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/mindspore-ai/mindquantum.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/mq-circuit-compiler .claude/skills/mq-circuit-compiler && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mq-circuit-compiler
GitHub stars
102
Token cost
~1.7k tokens
SKILL.md length
246 words
Files
1
Skills in repo
6
Repo updated
First seen
Licence
Apache-2.0

At a glance

Compile and optimize quantum circuits for hardware execution using MindQuantum's compiler pipeline.

  • Works in 4 steps: SABRE iterations: solver.solve() exposes… → Topology input: SABRE requires a… → Inserted SWAPs: The returned circuit may… → …
  • The user needs to compile a circuit for a specific quantum processor
  • SKILL.md covers Compilation Pipeline Overview, Hardware Topology, SABRE Qubit Mapping and Gate Decomposition, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Mq Circuit Compiler is an agent skill from mindspore-ai/mindquantum. Compile and optimize quantum circuits for hardware execution using MindQuantum's compiler pipeline. Covers gate decomposition into native gate sets, DAG-based circuit optimization, SABRE qubit mapping for hardware topologies (grid, linear, custom), and circuit equivalence checking. Use when the user needs to compile a circuit for a specific quantum processor, map logical qubits to physical qubits, decompose gates, optimize circuit depth, define hardware topology, or check circuit equivalence.

Its SKILL.md is about 1.7k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Research & Science, covering Quantum computing. The repository describes itself as: MindQuantum is a quantum machine learning library that can be used to build and train different quantum neural networks. The licence is Apache-2.0.

When your agent uses it

  • The user needs to compile a circuit for a specific quantum processor
  • Map logical qubits to physical qubits
  • Decompose gates
  • Optimize circuit depth

Example prompts

  • “/mq-circuit-compiler”

Requirements

  • Python 3

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. SABRE iterations: solver.solve() exposes iter_num; increasing it runs more SABRE search iterations and increases compile time.
  2. Topology input: SABRE requires a connected QubitsTopology; disconnected topologies raise ValueError.
  3. Inserted SWAPs: The returned circuit may contain SWAP gates inserted by the mapper to satisfy topology constraints.
  4. Equivalence checks: For small circuits, compare matrices at fixed parameter values to validate a compilation workflow.

What it can do on your machine

Read from SKILL.md and the folder at commit 2a0ca08. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Mq Circuit Compiler loads about 1.7k tokens when it runs. Until then it costs about 129 tokens; SKILL.md has 246 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~129
When it runs · the whole SKILL.md, loaded when a task matches
~1.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from mindspore-ai/mindquantum at commit 2a0ca08, republished under its Apache-2.0 licence (© mindspore-ai). 246 words, ~1,737 tokens.

Download SKILL.mdSave it as .claude/skills/mq-circuit-compiler/SKILL.md (or your agent's skills folder).
name
mq-circuit-compiler
description
Compile and optimize quantum circuits for hardware execution using MindQuantum's compiler pipeline. Covers gate decomposition into native gate sets, DAG-based circuit optimization, SABRE qubit mapping for hardware topologies (grid, linear, custom), and circuit equivalence checking. Use when the user needs to compile a circuit for a specific quantum processor, map logical qubits to physical qubits, decompose gates, optimize circuit depth, define hardware topology, or check circuit equivalence.

Circuit Compilation and Hardware Mapping

MindQuantum provides compiler and mapping APIs for gate decomposition, DAG-based circuit processing, and topology-aware qubit mapping.

Compilation Pipeline Overview

text
Logical Circuit → Gate Decomposition → DAG Optimization → Qubit Mapping → Physical Circuit
                  (to native gate set)   (simplify)         (SABRE)        (with SWAPs)

Hardware Topology

Define the qubit connectivity of your target device:

python
from mindquantum.device import QubitsTopology, GridQubits, LinearQubits, QubitNode

# Predefined topologies
linear = LinearQubits(5)  # 0-1-2-3-4 chain
grid = GridQubits(3, 3)  # 3×3 grid (9 qubits)

# Custom topology
topo = QubitsTopology([QubitNode(i) for i in range(5)])
topo[0] >> topo[1]  # Connect qubit 0 ↔ 1
topo[1] >> topo[2]  # Connect qubit 1 ↔ 2
topo[2] >> topo[3]
topo[3] >> topo[4]
topo[0] >> topo[3]  # Add diagonal connection

# Inspect
print(topo.edges_with_id())  # List of (qubit_a, qubit_b) pairs
print(topo.all_qubit_id())  # List of qubit IDs
Modifying Topologies
python
# Remove a qubit (e.g., defective qubit on hardware)
topo.remove_qubit_node(2)

# Isolate a qubit (break all its connections)
topo.isolate_with_near(3)
Visualizing Topologies
python
from mindquantum.io.display import draw_topology

draw_topology(grid)  # Show topology graph
draw_topology(grid, compiled_circuit)  # Highlight used edges

SABRE Qubit Mapping

The SABRE algorithm maps logical qubits to physical qubits and inserts SWAP gates to satisfy connectivity constraints.

python
from mindquantum.core.circuit import Circuit
from mindquantum.core.gates import H, RX, X
from mindquantum.device import GridQubits
from mindquantum.algorithm.mapping import SABRE

# 1. Define logical circuit (may have non-local gates)
circ = Circuit()
circ += H.on(0)
circ += X.on(2, 0)  # CNOT: target 2, control 0; may not be connected
circ += RX("a").on(1)
circ += X.on(3, 1)
circ += X.on(0, 3)  # qubits 0 and 3 may not be connected

# 2. Define hardware topology
topo = GridQubits(2, 2)
# Grid:  0 - 1
#         |   |
#         2 - 3

# 3. Run SABRE
solver = SABRE(circ, topo)
new_circ, init_mapping, final_mapping = solver.solve(
    iter_num=5,  # SABRE iterations
    w=0.5,  # Weight for lookahead heuristic
    delta1=0.3,  # Decay parameter for single-qubit gates
    delta2=0.2,  # Decay parameter for two-qubit gates
)

# 4. Results
print(f"Original gates: {len(circ)}")
print(f"Compiled gates: {len(new_circ)}")  # includes inserted SWAPs
print(f"Initial mapping: {init_mapping}")  # logical → physical
print(f"Final mapping: {final_mapping}")

# 5. View compiled circuit
new_circ.svg()
SABRE Parameters
ParameterTypeDescription
iter_numintNumber of SABRE iterations. Increasing it runs more search iterations. Default 5.
wfloatWeight for front-layer vs lookahead cost. Range [0, 1].
delta1floatDecay parameter for single-qubit gates.
delta2floatDecay parameter for two-qubit gates.

Gate Decomposition

Decompose complex gates into a native gate set:

python
from mindquantum.algorithm.compiler import decompose
Decomposition Rules

The compiler package provides decomposition and rewrite rules, including:

  • Multi-controlled gates → cascaded Toffoli → CX + single-qubit
  • Arbitrary unitary → U3 + CX decomposition
  • Named gates (SWAP, Toffoli, etc.) → native primitives
Using the DAG Representation

The compiler converts circuits to Directed Acyclic Graphs for optimization:

python
from mindquantum.algorithm.compiler import DAGCircuit

# Convert circuit to DAG
dag = DAGCircuit(circ)

# DAGCircuit exposes circuit dependency structure for compiler rules and inspection.

Circuit Equivalence Checking

Verify that compilation preserved circuit semantics:

Numerical Verification
python
import numpy as np
from mindquantum.core.circuit import Circuit, dagger

# Method 1: Matrix comparison (small circuits)
original = Circuit().h(0).x(1, 0).rx("a", 0)
compiled = Circuit().h(0).x(1, 0).rx("a", 0)  # Replace with your compiled circuit

# For fixed parameters
params = {"a": 0.5}
m1 = original.matrix(params)
m2 = compiled.matrix(params)
assert np.allclose(m1, m2), "Circuits are not equivalent!"

# Method 2: Identity check
# If A† · B = I, then A ≡ B
check = dagger(original) + compiled
m_check = check.matrix(params)
assert np.allclose(m_check, np.eye(m_check.shape[0])), "Not equivalent!"
Random Parameter Verification

For parameterized circuits, test with multiple random parameter sets:

python
param_names = original.params_name
for _ in range(10):
    pr = {name: np.random.uniform(-np.pi, np.pi) for name in param_names}
    m1 = original.matrix(pr)
    m2 = compiled.matrix(pr)
    assert np.allclose(m1, m2, atol=1e-10), f"Mismatch at params={pr}"

Complete Compilation Workflow

python
from mindquantum.core.circuit import Circuit
from mindquantum.core.gates import H, RY, RZ, X
from mindquantum.device import GridQubits
from mindquantum.algorithm.mapping import SABRE
from mindquantum.io.display import draw_topology

# 1. Build your algorithm circuit
n_qubits = 6
circ = Circuit()
for i in range(n_qubits):
    circ += H.on(i)
for i in range(n_qubits - 1):
    circ += X.on(i + 1, i)
for i in range(n_qubits):
    circ += RY(f"theta_{i}").on(i)
# Long-range gate (not nearest-neighbor)
circ += X.on(5, 0)

# 2. Define target hardware topology
topo = GridQubits(2, 3)  # 2×3 grid for 6 qubits

# 3. Map to hardware
solver = SABRE(circ, topo)
compiled, init_map, final_map = solver.solve(10, 0.5, 0.3, 0.2)

# 4. Report
print(f"SWAPs inserted: {len(compiled) - len(circ)}")
print(f"Logical → Physical mapping: {init_map}")

# 5. Visualize
draw_topology(topo, compiled)
compiled.svg()

Notes

  1. SABRE iterations: solver.solve() exposes iter_num; increasing it runs more SABRE search iterations and increases compile time.
  2. Topology input: SABRE requires a connected QubitsTopology; disconnected topologies raise ValueError.
  3. Inserted SWAPs: The returned circuit may contain SWAP gates inserted by the mapper to satisfy topology constraints.
  4. Equivalence checks: For small circuits, compare matrices at fixed parameter values to validate a compilation workflow.

© mindspore-ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/mq-circuit-compiler of mindspore-ai/mindquantum.

Open the folder on GitHubat commit 2a0ca08

Compare with similar skills

Mq Circuit Compiler next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mq Circuit Compiler compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mq Circuit Compiler this skillmindspore-ai/mindquantum102—~1.7kAutomated safety check: PassApache-2.0
Qiskit 2.x Quantum ML Referenceaiming-lab/AutoResearchClaw15k—~4.7kAutomated safety check: PassMIT
QutipzLanqing/codex-claude-academic-skills4.7k8 repos~2.3kAutomated safety check: PassBSD-3-Clause
Cirqdavila7/claude-code-templates33k11 repos~2.7kAutomated safety check: PassMIT
Qiskitdavila7/claude-code-templates33k9 repos~2.2kAutomated safety check: PassMIT
Pennylanedavila7/claude-code-templates33k7 repos~1.9kAutomated safety check: PassMIT

Similar skills

  • Qiskit 2.x Quantum ML Reference

    aiming-lab/AutoResearchClaw

    Reference patterns for writing qiskit 2.x code for variational quantum machine learning: feature maps, VQC training, VQE for chemistry, MPS circuits and noise models.

    15k GitHub stars~4.7k tokensUpdated 1 mo ago
    Research & ScienceAuto-check passed
  • Qutip

    zLanqing/codex-claude-academic-skills

    Quantum physics simulation library for open quantum systems.

    4.7k GitHub starsUsed in 8 repos~2.3k tokens
    Research & ScienceAuto-check passed
  • Cirq

    davila7/claude-code-templates

    Quantum computing framework for building, simulating, optimizing, and executing quantum circuits.

    33k GitHub starsUsed in 11 repos~2.7k tokens
    Research & ScienceAuto-check passed
  • Qiskit

    davila7/claude-code-templates

    Comprehensive quantum computing toolkit for building, optimizing, and executing quantum circuits.

    33k GitHub starsUsed in 9 repos~2.2k tokens
    Research & ScienceAuto-check passed
  • Pennylane

    davila7/claude-code-templates

    Cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry.

    33k GitHub starsUsed in 7 repos~1.9k tokens
    Research & ScienceAuto-check passed
  • Qiskit

    K-Dense-AI/scientific-agent-skills

    Builds, simulates, transpiles, and executes quantum circuits with Qiskit and IBM Quantum Runtime.

    48k GitHub starsUsed in 1 repo~3.3k tokens
    Research & ScienceAuto-check passed

More from mindspore-ai/mindquantum

  • Mindquantum

    mindspore-ai/mindquantum

    Build, simulate, and analyze quantum circuits with MindQuantum.

    102 GitHub stars~2.3k tokensUpdated 19 days ago
    Auto-check passed
  • Mq Noisy Simulation

    mindspore-ai/mindquantum

    Simulate noisy quantum circuits with MindQuantum. An agent skill from mindspore-ai/mindquantum.

    102 GitHub stars~2.2k tokensUpdated 19 days ago
    Auto-check passed
  • Mq Qaia Solver

    mindspore-ai/mindquantum

    Solve Ising/QUBO-style combinatorial optimization problems using MindQuantum's Quantum Annealing-Inspired Algorithms (QAIA).

    102 GitHub stars~2.2k tokensUpdated 19 days ago
    Auto-check passed
  • Mq Quantum Chemistry

    mindspore-ai/mindquantum

    Run quantum chemistry simulations with MindQuantum. An agent skill from mindspore-ai/mindquantum.

    102 GitHub stars~2.2k tokensUpdated 19 days ago
    Auto-check passed
  • Mq Variational Training

    mindspore-ai/mindquantum

    Build and train variational quantum algorithms (VQE, QAOA, QML, QNN) with MindQuantum.

    102 GitHub stars~2.5k tokensUpdated 19 days ago
    Auto-check passed

Questions about Mq Circuit Compiler

What does Mq Circuit Compiler do?

Compile and optimize quantum circuits for hardware execution using MindQuantum's compiler pipeline. Mq Circuit Compiler is an agent skill from mindspore-ai/mindquantum. Compile and optimize quantum circuits for hardware execution using MindQuantum's compiler pipeline.

When should I use Mq Circuit Compiler?

Mq Circuit Compiler fits situations like: the user needs to compile a circuit for a specific quantum processor; map logical qubits to physical qubits; decompose gates; optimize circuit depth.

How do I install Mq Circuit Compiler in Claude Code?

Run `npx skills add mindspore-ai/mindquantum --skill mq-circuit-compiler -a claude-code`. Or copy the skill folder (skills/mq-circuit-compiler in mindspore-ai/mindquantum) into .claude/skills/mq-circuit-compiler in your project. Claude Code loads it when a task matches its description.

How do I install Mq Circuit Compiler in Codex?

Run `npx skills add mindspore-ai/mindquantum --skill mq-circuit-compiler -a codex`. Or copy the skill folder (skills/mq-circuit-compiler in mindspore-ai/mindquantum) into .agents/skills/mq-circuit-compiler in your project. Codex loads it when a task matches its description.

Can I use Mq Circuit Compiler in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add mindspore-ai/mindquantum --skill mq-circuit-compiler -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mq-circuit-compiler, .gemini/skills/mq-circuit-compiler, .github/skills/mq-circuit-compiler and .opencode/skills/mq-circuit-compiler in your project.

What does Mq Circuit Compiler need to run?

SKILL.md names no scripts, command-line tools or credentials: Mq Circuit Compiler is instructions for the agent only. Our summary lists: Python 3.

Does Mq Circuit Compiler access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Mq Circuit Compiler safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mq Circuit Compiler use?

Mq Circuit Compiler is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mq Circuit Compiler use?

About 1.7k tokens (SKILL.md is roughly 6.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Mq Circuit Compiler?

Skills that share tags, products or a category with Mq Circuit Compiler: Qiskit 2.x Quantum ML Reference (aiming-lab/AutoResearchClaw, 15k stars), Qutip (zLanqing/codex-claude-academic-skills, 4.7k stars), Cirq (davila7/claude-code-templates, 33k stars) and Qiskit (davila7/claude-code-templates, 33k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mq Circuit Compiler?

mindspore-ai (a GitHub organization) maintains it in mindspore-ai/mindquantum, which has 102 GitHub stars. The repository holds 6 skills in this directory. The repository was last updated on September 21, 2026.

Source: mindspore-ai/mindquantum on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.