协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
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).
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
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.
QiskitRuntimeService, Sampler, Estimator, transpile, InstructionScheduleMapThe modern way to interact with hardware. Instead of sending raw circuits, you use Primitives:
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.
Unlike Error Correction (which requires thousands of qubits), Mitigation uses statistical tricks (like TREX or ZNE) to "clean" the results after execution.
pip install qiskit-ibm-runtime
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()
backend.properties() for the latest error rates before choosing qubits.RuntimeSession to minimize queue wait times.resilience_level=1 in Primitives.qiskit.execute is deprecated for hardware. Use Sampler and Estimator.FakeBackend objects (e.g., FakeManilaV2) which mimic real hardware noise for local debugging.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
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)
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])
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
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
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
Submit multiple circuits in a single run() call to bypass repeated initialization overhead.
Create custom stages for transpilation to control exactly how your circuit is modified.
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import Unroller, BasicSwap
# custom_pm = PassManager([Unroller(['u3', 'cx']), BasicSwap(coupling_map)])
Real hardware has high demand.
# ✅ Solution:
# 1. Use the 'least_busy' helper.
# 2. Check your IBM Quantum dashboard for reservation windows.
# 3. Use Runtime Sessions to group your jobs.
Your histogram looks like a flat line (random noise).
# ✅ 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.
Two neighboring qubits have similar frequencies, leading to "Crosstalk".
# ✅ 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.