mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-05-14 20:58:00 +00:00
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
|
|
from qiskit.providers.basic_provider import BasicSimulator
|
||
|
|
|
||
|
|
from quantum_learning.experiments import (
|
||
|
|
bell_circuit,
|
||
|
|
build_demo_noise_model,
|
||
|
|
line_coupling_map,
|
||
|
|
simulate_counts,
|
||
|
|
transpile_summary,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_simulate_counts_respects_requested_shots():
|
||
|
|
counts = simulate_counts(bell_circuit(), shots=64, seed=13)
|
||
|
|
assert sum(counts.values()) == 64
|
||
|
|
|
||
|
|
|
||
|
|
def test_transpile_summary_returns_compiled_circuit():
|
||
|
|
circuit = bell_circuit(measure=False)
|
||
|
|
backend = BasicSimulator()
|
||
|
|
summary = transpile_summary(
|
||
|
|
circuit,
|
||
|
|
backend,
|
||
|
|
basis_gates=["rz", "sx", "x", "cx"],
|
||
|
|
coupling_map=line_coupling_map(2),
|
||
|
|
)
|
||
|
|
|
||
|
|
assert summary["depth_before"] >= 1
|
||
|
|
assert summary["compiled_circuit"].num_qubits == 2
|
||
|
|
assert summary["ops_after"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_build_demo_noise_model_declares_cx_basis_gate():
|
||
|
|
noise_model = build_demo_noise_model()
|
||
|
|
assert "cx" in noise_model.basis_gates
|
||
|
|
|
||
|
|
|
||
|
|
def test_simulate_counts_with_noise_still_returns_requested_shots():
|
||
|
|
counts = simulate_counts(
|
||
|
|
bell_circuit(),
|
||
|
|
shots=64,
|
||
|
|
seed=11,
|
||
|
|
noise_model=build_demo_noise_model(readout_error=0.1),
|
||
|
|
)
|
||
|
|
assert sum(counts.values()) == 64
|