Core API Reference
The core modules provide the fundamental building blocks: circuits, gates, parameters, kernels, the execution runner, and the unified result type.
Circuits
The Circuit class (aliased as QuantumCircuit) is the backend-agnostic intermediate representation.
It supports single- and multi-qubit gates, parameterised rotations, measurements, composition, and parameter binding.
from hlquantum.circuit import Circuit, Parameter
# Build a parameterised circuit
qc = Circuit(2)
qc.rx(0, "theta").cx(0, 1).measure_all()
# Inspect
print(qc.depth) # critical-path length
print(qc.gate_count) # total gates
print(qc.parameters) # [Parameter('theta')]
# Bind parameters
bound = qc.bind_parameters({"theta": 1.57})
# Compose circuits with |
c_total = qc | Circuit(2).h(1)
Backend-agnostic quantum circuit representation.
Circuit
High-level quantum circuit.
Source code in hlquantum/circuit.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
depth
property
Circuit depth (longest critical path).
gate_count
property
Total number of gates.
parameters
property
Unique parameters in the circuit.
bind_parameters(value_dict)
Replace parameters with values and return a new circuit.
Source code in hlquantum/circuit.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
from_cirq(circuit)
classmethod
Import circuit from Cirq.
Source code in hlquantum/circuit.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
from_qiskit(qc)
classmethod
Import circuit from Qiskit.
Source code in hlquantum/circuit.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
Gate
dataclass
A single quantum gate operation.
Source code in hlquantum/circuit.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
Parameter
dataclass
A symbolic parameter for a quantum gate.
Source code in hlquantum/circuit.py
9 10 11 12 13 14 15 | |
Kernels
The @kernel decorator lets you write quantum logic as plain Python functions.
from hlquantum import kernel
@kernel(num_qubits=2)
def bell(qc):
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
print(bell.circuit) # QuantumCircuit(num_qubits=2, gates=4)
Quantum kernel decorator and wrapper.
Kernel
Wraps a function into a reusable quantum kernel.
Source code in hlquantum/kernel.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
kernel(num_qubits)
Decorator to transform a function into a Kernel.
Source code in hlquantum/kernel.py
36 37 38 39 40 | |
Runner
The run() function is the high-level entry point. It accepts a circuit or kernel, optionally transpiles it, executes on a backend, and applies error mitigation.
import hlquantum as hlq
from hlquantum.mitigation import ThresholdMitigation
result = hlq.run(
bell,
shots=1000,
transpile=True,
mitigation=ThresholdMitigation(threshold=0.01),
)
Convenience helpers for executing quantum circuits.
run(circuit_or_kernel, *, shots=1000, include_statevector=False, transpile=False, mitigation=None, backend=None, **kwargs)
Execute a circuit or kernel and return the result.
Source code in hlquantum/runner.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
Results
Every backend returns an ExecutionResult dataclass with counts, probabilities, expectation values, and optional state-vector access.
result.counts # {'00': 512, '11': 488}
result.probabilities # {'00': 0.512, '11': 0.488}
result.most_probable # '00'
result.expectation_value() # 1.0 (parity-based)
result.get_state_vector() # numpy array (simulators only)
Unified result container for circuit executions.
ExecutionResult
dataclass
Result of a quantum circuit execution.
Source code in hlquantum/result.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
get_state_vector()
Return the state vector as a numpy array.
Source code in hlquantum/result.py
20 21 22 23 24 25 | |
Exceptions
All HLQuantum-specific errors inherit from HLQuantumError.
| Exception | Purpose |
|---|---|
HLQuantumError |
Base class |
BackendError |
Backend execution failure |
CircuitValidationError |
Invalid circuit structure |
BackendNotAvailableError |
Required SDK not installed |
Custom exception hierarchy.
BackendError
Bases: HLQuantumError
Raised on backend execution error.
Source code in hlquantum/exceptions.py
8 9 | |
BackendNotAvailableError
Bases: HLQuantumError
Raised when backend is unavailable.
Source code in hlquantum/exceptions.py
16 17 | |
CircuitValidationError
Bases: HLQuantumError
Raised on circuit validation failure.
Source code in hlquantum/exceptions.py
12 13 | |
HLQuantumError
Bases: Exception
Base exception for all HLQuantum errors.
Source code in hlquantum/exceptions.py
4 5 | |