qiskit-hardware

Advanced sub-skill for Qiskit focused on executing circuits on physical quantum processing units (QPUs). Covers IBM Quantum Runtime, error mitigation techniques (TREX, ZNE), hardware-aware transpilation, and low-level pulse control (OpenPulse).

9 stars

Best use case

qiskit-hardware is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Advanced sub-skill for Qiskit focused on executing circuits on physical quantum processing units (QPUs). Covers IBM Quantum Runtime, error mitigation techniques (TREX, ZNE), hardware-aware transpilation, and low-level pulse control (OpenPulse).

Teams using qiskit-hardware should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/qiskit-hardware/SKILL.md --create-dirs "https://raw.githubusercontent.com/tondevrel/scientific-agent-skills/main/skills/qiskit-hardware/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/qiskit-hardware/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How qiskit-hardware Compares

Feature / Agentqiskit-hardwareStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Advanced sub-skill for Qiskit focused on executing circuits on physical quantum processing units (QPUs). Covers IBM Quantum Runtime, error mitigation techniques (TREX, ZNE), hardware-aware transpilation, and low-level pulse control (OpenPulse).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Qiskit - Real Hardware & Pulse Control

Moving from simulators to real hardware requires a shift in mindset. You are no longer working with perfect "ideal" qubits, but with superconducting circuits that suffer from decoherence, readout errors, and crosstalk. This guide covers how to get the most science out of noisy intermediate-scale quantum (NISQ) devices.

## When to Use

- Executing quantum algorithms on real IBM Quantum backends.
- Characterizing hardware noise (T1, T2 relaxation times).
- Implementing Error Mitigation to improve result accuracy.
- Using Qiskit Pulse to define custom microwave pulses (OpenPulse).
- Optimizing circuits for specific hardware topologies (coupling maps).
- Benchmarking quantum advantage in real-world conditions.

## Reference Documentation

- **IBM Quantum Learning**: https://learning.quantum.ibm.com/
- **Qiskit Runtime Docs**: https://docs.quantum.ibm.com/run
- **Qiskit Pulse Guide**: https://docs.quantum.ibm.com/build/pulse
- **Search patterns**: `QiskitRuntimeService`, `Sampler`, `Estimator`, `transpile`, `InstructionScheduleMap`

## Core Principles

### 1. Qiskit Runtime (Primitives)

The modern way to interact with hardware. Instead of sending raw circuits, you use Primitives:

- **Sampler**: Returns quasi-probabilities (bitstrings).
- **Estimator**: Returns expectation values of observables (e.g., energy).

### 2. Transpilation (Hardware Mapping)

Physical backends only support a small set of "Basis Gates" (e.g., `rz`, `x`, `sx`, `ecr`). The Transpiler rewrites your abstract math into these specific instructions and maps virtual qubits to physical ones based on error rates.

### 3. Error Mitigation

Unlike Error Correction (which requires thousands of qubits), Mitigation uses statistical tricks (like TREX or ZNE) to "clean" the results after execution.

## Quick Reference: Connecting to Hardware

### Installation

```bash
pip install qiskit-ibm-runtime
```

### Setup and Job Execution

```python
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as Sampler

# 1. Initialize service (requires API key from quantum.ibm.com)
# service = QiskitRuntimeService(channel="ibm_quantum", token="YOUR_TOKEN")
service = QiskitRuntimeService() # Uses saved credentials

# 2. Select backend
backend = service.least_busy(operational=True, simulator=False)

# 3. Run job using Primitives
sampler = Sampler(backend=backend)
job = sampler.run([my_circuit])
result = job.result()
```

## Critical Rules

### ✅ DO

- **Check Calibration Data** - Backends change daily. Always check `backend.properties()` for the latest error rates before choosing qubits.
- **Use "Sessions"** - Wrap multiple related jobs in a `RuntimeSession` to minimize queue wait times.
- **Set optimization_level** - Use level 3 for hardware to enable advanced routing and gate fusion.
- **Apply Readout Mitigation** - Readout (measuring 0 as 1) is the largest error source. Use `resilience_level=1` in Primitives.
- **Use Dynamical Decoupling (DD)** - Add pulses to "idling" qubits to prevent them from losing their state while waiting for other gates.

### ❌ DON'T

- **Don't use execute()** - The old `qiskit.execute` is deprecated for hardware. Use `Sampler` and `Estimator`.
- **Don't run deep circuits** - NISQ devices have limited coherence. If your circuit depth > 50-100, the result will likely be pure noise.
- **Don't ignore the Coupling Map** - If you force a CNOT between two qubits that aren't physically connected, the transpiler will add many "SWAP" gates, increasing error.
- **Don't use qasm_simulator for hardware prep** - Use `FakeBackend` objects (e.g., `FakeManilaV2`) which mimic real hardware noise for local debugging.

## Hardware-Aware Transpilation

### Mapping to physical qubits

```python
from qiskit import transpile

# Basis gates for a specific backend
basis_gates = backend.operation_names
coupling_map = backend.coupling_map

# Optimized transpilation
optimized_circ = transpile(my_circuit, 
                           backend=backend,
                           optimization_level=3,
                           initial_layout=[0, 2, 4]) # Manual qubit selection
```

## Advanced Error Mitigation

### Resilience Levels in Estimator

```python
from qiskit_ibm_runtime import EstimatorV2 as Estimator, EstimatorOptions

options = EstimatorOptions()
# resilience_level 0: No mitigation
# resilience_level 1: Readout mitigation (TREX)
# resilience_level 2: ZNE (Zero Noise Extrapolation) - expensive but accurate
options.resilience_level = 1 

estimator = Estimator(backend=backend, options=options)
```

## Low-Level: Qiskit Pulse (OpenPulse)

### Defining custom microwave signals

```python
from qiskit import pulse
from qiskit.circuit import Parameter

# Define a Gaussian pulse
amp = Parameter('amp')
with pulse.build(backend=backend, name='custom_pulse') as schedule:
    pulse.play(pulse.Gaussian(duration=160, amp=amp, sigma=40), pulse.drive_channel(0))

# Attach pulse to a gate
my_circuit.add_calibration('my_gate', [0], schedule, params=[amp])
```

## Practical Workflows

### 1. Finding the "Best" Qubits on a Device

```python
def get_best_qubits(backend, n_qubits):
    """Finds a linear chain of qubits with lowest error rates."""
    props = backend.properties()
    # Logic to parse gate_error and readout_error from props
    # and find a connected subgraph with minimal noise.
    pass
```

### 2. VQE on Hardware with Runtime

```python
from qiskit_ibm_runtime import Session, EstimatorV2 as Estimator

def run_hardware_vqe(ansatz, hamiltonian, backend):
    with Session(backend=backend) as session:
        estimator = Estimator(session=session)
        # Standard optimization loop (using SciPy)
        # Each 'step' runs a job within the same session
        pass
```

### 3. Measuring T1 Time (Relaxation)

```python
def t1_experiment(qubit, delay_times):
    circuits = []
    for t in delay_times:
        c = QuantumCircuit(qubit + 1)
        c.x(qubit) # Flip to |1>
        c.delay(t, qubit, unit='us') # Wait
        c.measure_all()
        circuits.append(c)
    # Execute on hardware and fit decay curve
```

## Performance Optimization

### 1. Job Batching

Submit multiple circuits in a single `run()` call to bypass repeated initialization overhead.

### 2. Transpiler Pass Manager

Create custom stages for transpilation to control exactly how your circuit is modified.

```python
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import Unroller, BasicSwap
# custom_pm = PassManager([Unroller(['u3', 'cx']), BasicSwap(coupling_map)])
```

## Common Pitfalls and Solutions

### Queue Wait Times

Real hardware has high demand.

```python
# ✅ Solution: 
# 1. Use the 'least_busy' helper.
# 2. Check your IBM Quantum dashboard for reservation windows.
# 3. Use Runtime Sessions to group your jobs.
```

### "Depolarizing" Result

Your histogram looks like a flat line (random noise).

```python
# ✅ Solution:
# 1. Reduce circuit depth.
# 2. Use 'optimization_level=3'.
# 3. Apply Error Mitigation (resilience_level=1+).
# 4. Check if the backend is currently undergoing maintenance/calibration.
```

### Frequency Collisions

Two neighboring qubits have similar frequencies, leading to "Crosstalk".

```python
# ✅ Solution:
# Select qubits that are physically separated or have 
# significantly different frequencies in backend.properties().
```

Qiskit Hardware is where quantum theory meets the harsh reality of physics. Mastering these tools allows you to push the boundaries of what is possible on today's noisy devices, paving the way for the fault-tolerant era.

Related Skills

qiskit

9
from tondevrel/scientific-agent-skills

Comprehensive guide for Qiskit - IBM's quantum computing framework. Use for quantum circuit design, quantum algorithms (VQE, QAOA, Grover, Shor), quantum simulation, noise modeling, quantum machine learning, and quantum chemistry calculations. Essential for quantum computing research and applications.

xgboost-lightgbm

9
from tondevrel/scientific-agent-skills

Industry-standard gradient boosting libraries for tabular data and structured datasets. XGBoost and LightGBM excel at classification and regression tasks on tables, CSVs, and databases. Use when working with tabular machine learning, gradient boosting trees, Kaggle competitions, feature importance analysis, hyperparameter tuning, or when you need state-of-the-art performance on structured data.

xarray

9
from tondevrel/scientific-agent-skills

N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF/GRIB/Zarr files, climate/weather/oceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.

transformers

9
from tondevrel/scientific-agent-skills

State-of-the-art Machine Learning for PyTorch, TensorFlow, and JAX. Provides thousands of pretrained models to perform tasks on different modalities such as text, vision, and audio. The industry standard for Large Language Models (LLMs) and foundation models in science.

tqdm

9
from tondevrel/scientific-agent-skills

A fast, extensible progress bar for Python and CLI. Instantly makes your loops show a smart progress meter with ETA, iterations per second, and customizable statistics. Minimal overhead. Use for monitoring long-running loops, simulations, data processing, ML training, file downloads, I/O operations, command-line tools, pandas operations, parallel tasks, and nested progress bars.

tensorflow

9
from tondevrel/scientific-agent-skills

Comprehensive deep learning framework for building, training, and deploying neural networks. TensorFlow provides tf.keras high-level API for model construction, tf.data for efficient data pipelines, and tf.function for graph-mode optimization. Use when working with: neural network training and inference, image classification/detection/segmentation, NLP/text processing with embeddings or transformers, time series forecasting, generative models (VAE, GAN), transfer learning with pretrained models, custom training loops with GradientTape, GPU/TPU accelerated computation, or any deep learning task.

sympy

9
from tondevrel/scientific-agent-skills

Comprehensive guide for SymPy - Python library for symbolic mathematics. Use for symbolic expressions, calculus (derivatives, integrals, limits, series), equation solving (algebraic, differential, systems), linear algebra, simplification, matrix operations, special functions, code generation, and mathematical proofs. Essential for analytical mathematics and computer algebra.

sunpy

9
from tondevrel/scientific-agent-skills

The community-developed free and open-source software package for solar physics. Provides tools for data search and download, coordinate transformations specific to solar physics, and powerful image processing through the Map object. Use when working with solar data, solar images (EUV, magnetograms, white light), solar coordinates (Helioprojective, Heliographic), Fido data search, solar time series, differential rotation, limb fitting, or multi-instrument solar analysis (AIA, HMI, GOES).

statsmodels

9
from tondevrel/scientific-agent-skills

Advanced statistical modeling and hypothesis testing. Complementary to SciPy's stats module, it provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests and statistical data exploration. Use for linear regression, GLM, time series analysis, ANOVA, survival analysis, causal inference, and statistical hypothesis testing. Load when working with OLS, WLS, logistic regression, Poisson regression, ARIMA, SARIMAX, statistical diagnostics, p-values, confidence intervals, or R-style statistical analysis.

spacy-nltk

9
from tondevrel/scientific-agent-skills

Natural Language Processing for text analysis, corpus linguistics, and production NLP pipelines. spaCy provides fast production-grade tokenization, POS tagging, NER, dependency parsing, and custom model training. NLTK provides classical corpus linguistics, linguistic analysis, VADER sentiment, collocation analysis, and access to standard linguistic corpora. Use when: processing and analyzing text data, extracting named entities (people, orgs, locations, dates), dependency parsing and syntactic analysis, building text classification pipelines, performing corpus-level linguistic analysis (frequency, collocations, readability), sentiment analysis, lemmatization and stemming, working with multilingual text, training custom NER or text classifiers, or any task requiring structured understanding of natural language beyond simple string operations.

sktime-tsfresh

9
from tondevrel/scientific-agent-skills

Time series machine learning layer (Tier 1): integration of **sktime** and **tsfresh** for building production-grade pipelines that transform raw time series into tabular feature representations suitable for classical machine-learning models. *sktime* provides a unified, sklearn-compatible interface for time-series data types, transformations, and pipelines, while *tsfresh* enables large-scale automated extraction of statistical, spectral, and autocorrelation features, with optional statistically grounded feature relevance selection (FRESH).

sklearn-explainability

9
from tondevrel/scientific-agent-skills

Advanced sub-skill for scikit-learn focused on model interpretability, feature importance, and diagnostic tools. Covers global and local explanations using built-in inspection tools and SHAP/LIME integrations.