Error Model¶
An error model in Selene is a plugin component that injects and tracks noise behavior during simulation. Error models are optional in Selene workflows. Users can run ideal or near-ideal simulations by selecting a no-noise plugin implementation, and later switch to a noise-aware plugin without changing the rest of the program structure.
This plugin-based optionality is useful for the following scenarios:
validate algorithm logic first in a simplified environment;
compare ideal and noisy outcomes under the same runtime and simulator setup;
progressively adopt hardware-informed noise models as they become available.
Code Samples¶
Selene provides three error model plugins locally. Through the Selene-based cloud emulator capabilities in Quantinuum Nexus, users can select error models corresponding to specific machine instance. By default, all local Selene simulations do not incorporate any error model mechanisms. This is enabled by the default choice of IdealErrorModel.
The code samples provided here demonstrate usage of opensource error models, available with a local instance of Selene.
Depolarizing Error Model¶
A plugin for simulating depolarizing error models in quantum systems. This plugin incorporates depolarizing error into the user’s simulation. It is also possible to configure error probabilities for 1-qubit gates (p_1q), 2-qubit gates (p_2q), measurements (p_meas), and initializations (p_init). Error probabilities must be defined within the valid range of \([0, 1]\).
from guppylang import guppy
from guppylang.std.builtins import array, result
from guppylang.std.quantum import qubit, measure, h, cx, measure
@guppy
def main() -> None:
qubit_top = qubit()
h(qubit_top)
qubits = array(qubit() for _ in range(3))
for q in qubits:
cx(qubit_top, q)
m = measure(q)
result("result", m)
m_top = measure(qubit_top)
result("result", m_top)
hugr = main.compile()
from selene_sim import build, Quest, DepolarizingErrorModel
from hugr.qsystem.result import QsysResult
runner = build(hugr)
error_model = DepolarizingErrorModel(
random_seed=123141,
p_1q=1e-5,
p_2q=1.4e-4,
p_meas=1e-3,
p_init=1e-5
)
simulator = Quest()
qsys_result = QsysResult(runner.run_shots(
simulator,
error_model=error_model,
n_qubits=4,
n_shots=100,
))
print(qsys_result.collated_counts())
Counter({(('result', '0000'),): 52, (('result', '1111'),): 47, (('result', '0100'),): 1})
Leakage Error Model¶
A plugin for simulating a simple leakage model. On any 1-qubit gate, a qubit may leak to an auxiliary state with a probability of p_leak. On any 2-qubit gate, each qubit may leak to an auxiliary state with a probability of p_leak. If either qubit in a 2-qubit gate leaks, the other qubit is then leaked.
from selene_sim import build, Quest, SimpleLeakageErrorModel
from hugr.qsystem.result import QsysResult
runner = build(hugr)
error_model = SimpleLeakageErrorModel(
random_seed=123141,
p_leak=0.1,
leak_measurement_bias=0.6
)
simulator = Quest()
qsys_result = QsysResult(runner.run_shots(
simulator,
error_model=error_model,
n_qubits=4,
n_shots=100,
))
print(qsys_result.collated_counts())
Counter({(('result', '1111'),): 20, (('result', '0000'),): 12, (('result', '1101'),): 8, (('result', '1001'),): 8, (('result', '0111'),): 8, (('result', '1011'),): 7, (('result', '0011'),): 5, (('result', '1100'),): 5, (('result', '0001'),): 5, (('result', '0100'),): 5, (('result', '1110'),): 4, (('result', '1010'),): 4, (('result', '0010'),): 3, (('result', '1000'),): 3, (('result', '0101'),): 2, (('result', '0110'),): 1})
Extending Selene Capabilities¶
For plugin API details, see the Extensibility API pages: