Random Circuit Generation
API reference for random circuit generation and quantum benchmarking utilities.
random_qcircuit
Generates a random quantum circuit with the specified qubits, depth, and gate types.
Signature
random_qcircuit(qubits: list[int], depth: int, gate_type: list[str]) -> QCircuitParameters
| Parameter | Type | Description |
|---|---|---|
| qubits | list[int] | List of qubit indices to include in the circuit |
| depth | int | Depth (number of gate layers) of the circuit |
| gate_type | list[str] | List of gate type strings to use, e.g. ["H", "CNOT"] |
Returns
QCircuit — A randomly generated quantum circuit.
Examples
from pyqpanda3.core import random_qcircuit
# Generate a random circuit on qubits [0, 1, 2] with depth 5 using H and CNOT gates
circ = random_qcircuit([0, 1, 2], 5, ["H", "CNOT"])
print(f"Circuit depth: {circ.depth()}")
print(f"Gate count: {circ.count_ops()}")QV — Quantum Volume Benchmark
Generates a Quantum Volume (QV) benchmark circuit for the given configuration.
Signature
QV(num_qubit: int, depth: int, seed: int) -> QCircuitParameters
| Parameter | Type | Description |
|---|---|---|
| num_qubit | int | Number of qubits for the QV test |
| depth | int | Depth (number of layers) of the circuit |
| seed | int | Random seed for reproducibility |
Returns
QCircuit — The quantum volume benchmark circuit.
Examples
from pyqpanda3.core import QV
# Compute quantum volume for a 4-qubit, depth-4 circuit
qv = QV(num_qubit=4, depth=4, seed=42)
print(f"Quantum Volume: {qv}")Mathematical Background
Quantum Volume is a single-number metric that captures the overall capability of a quantum processor. It accounts for qubit count, gate fidelity, connectivity, and software performance. The QV protocol runs random circuits of width
where
direct_twirl
Performs direct twirling (randomized compiling) on a quantum program, decomposing it into a sequence of random Pauli frames.
Signature
direct_twirl(
input_circ: QProg,
twirled_gate: str = "CNOT",
seed: int = 0
) -> QProgParameters
| Parameter | Type | Description |
|---|---|---|
| input_circ | QProg | Input quantum program to twirl |
| twirled_gate | str | Gate type to use for twirling (default "CNOT"). Supported: "CNOT", "CZ" |
| seed | int | Random seed (default 0) |
Returns
QProg — The twirled quantum program.
Examples
from pyqpanda3.core import H, CNOT, direct_twirl, QProg
# Build a simple program
prog = QProg()
prog << H(0) << CNOT(0, 1)
# Apply direct twirling
twirled = direct_twirl(prog, "CNOT", 42)
print(f"Original gates: {prog.count_ops()}")
print(f"Twirled gates: {twirled.count_ops()}")Mathematical Background
Twirling converts a general quantum channel into a Pauli channel by conjugating with random Pauli operators. For a channel
This simplifies error characterization and enables error mitigation techniques.