Sampling¶
A SamplingProblem asks for samples from a circuit’s
output distribution: |bitstring> -> probability.
Usage¶
from microquantum import QuantumCircuit, SamplingProblem
qc = QuantumCircuit(2).h(0).cx(0, 1) # Bell state
problem = SamplingProblem(qc, num_samples=1024, name="bell")
print(problem.circuit)
print(problem.validate()) # []
data = problem.to_dict()
restored = SamplingProblem.from_dict(data) # JSON-safe round trip
print(restored.num_samples) # 1024
What it maps to¶
Solvers usually come from the runtime helpers —
execute()/run_parameter_sweep()/ExecutionRuntime— which bind the circuit, dispatch it to a backend and return aBackendResultwith counts.Analysis —
SamplingAnalysisturns those counts into outcome probabilities, entropy and marginals (see Sampling).
Example through the runtime¶
from microquantum import ExecutionRuntime, StatevectorBackend
runtime = ExecutionRuntime(backend=StatevectorBackend())
result = runtime.execute(
problem.circuit,
shots=problem.num_samples,
seed=1,
)
print(result.counts)