Skip to main content

Surface-sim

example workflow Code style: black Documentation Status PyPI

This package is a wrapper around Stim to simplify the construction of QEC circuits. Given a circuit, it can implement the logical equivalent under different types of noise, including circuit-level noise. It uses a code layout that helps with qubit labeling, indexing and connectivity. It also defines the detectors automatically for any sequence of logical gates.

For more information see the documentation.

Installation

This package is available in PyPI, thus it can be installed using

pip install surface-sim

or alternatively, it can be installed from source using

git clone git@github.com:MarcSerraPeralta/surface-sim.git
pip install surface-sim/

Example

Pre-built experiment: memory experiment

from surface_sim.layouts import rot_surface_code
from surface_sim.models import CircuitNoiseModel
from surface_sim import Detectors
from surface_sim.experiments.rot_surface_code_css import memory_experiment

# prepare the layout, model, and detectors objects
layout = rot_surface_code(distance=3)
model = CircuitNoiseModel(layout.qubit_inds)
detectors = Detectors.from_layouts(layout)

# create a memory experiment
NUM_ROUNDS = 10
DATA_INIT = {q: 0 for q in layout.data_qubits}
ROT_BASIS = True  # X basis
MEAS_RESET = True  # reset after ancilla measurements
PROB = 1e-5

model.setup.set_var_param("prob", PROB)
stim_circuit = memory_experiment(
    model,
    layout,
    detectors,
    num_rounds=NUM_ROUNDS,
    data_init=DATA_INIT,
    rot_basis=ROT_BASIS,
    anc_reset=MEAS_RESET,
)

Arbitrary logical circuit from a given circuit

import stim

from surface_sim.models import CircuitNoiseModel
from surface_sim import Detectors
from surface_sim.experiments import experiment_from_circuit
from surface_sim.circuit_blocks.unrot_surface_code_css import gate_to_iterator
from surface_sim.layouts import unrot_surface_codes

circuit = stim.Circuit(
    """
    R 0 1
    TICK
    CNOT 0 1
    TICK
    S 0
    I 1
    TICK
    S 0
    H 1
    TICK
    M 0
    MX 1
    OBSERVABLE_INCLUDE(0) rec[-1] rec[-2]
    """
)

layouts = unrot_surface_codes(circuit.num_qubits, distance=3)
model = CircuitNoiseModel.from_layouts(*layouts)
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")

model.setup.set_var_param("prob", 1e-3)

experiment = experiment_from_circuit(
    circuit, layouts, model, detectors, gate_to_iterator, anc_reset=True
)

Tags can be used to specify noiseless/ideal operations. For example, in the circuit below, the logical reset and measurement are noiseless:

R[noiseless] 0
TICK
TICK
TICK
M[noiseless] 0

For more fine tunning in the presence of multiple code patches, see surface_sim.experiments.experiment_from_schedule.

Observables can be defined from Paulis, not just measurement records. For example:

RX 0
R 1
TICK
CNOT 0 1
TICK
TICK
TICK
TICK[noiseless]
OBSERVABLE_INCLUDE(0) Z0 Z1
OBSERVABLE_INCLUDE(1) X0 X1

Noise models with random physical error probabilities

import stim

from surface_sim.models import SI1000NoiseModel
from surface_sim import Detectors
from surface_sim.experiments import experiment_from_circuit
from surface_sim.circuit_blocks.unrot_surface_code_css import gate_to_iterator
from surface_sim.layouts import unrot_surface_codes
from surface_sim.setups.random import lognormal

circuit = stim.Circuit(
    """
    R 0
    TICK
    M 0
    OBSERVABLE_INCLUDE(0) rec[-1]
    """
)

layouts = unrot_surface_codes(circuit.num_qubits, distance=11)
model = SI1000NoiseModel.from_layouts(*layouts)
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")

model.setup.convert_to_random(prob=lognormal(-3, 0.1, seed=123))

experiment = experiment_from_circuit(
    circuit, layouts, model, detectors, gate_to_iterator, anc_reset=True
)

For more information and examples about surface-sim, please read the documentation.

Metadata

Release files for surface-sim 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for surface-sim 0.11.0
File Size Uploaded
surface_sim-0.11.0.tar.gz 99.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for surface-sim 0.11.0
File Interpreter ABI Platform
surface_sim-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 223.0 kB

Release files / surface_sim-0.11.0.tar.gz

Download URL surface_sim-0.11.0.tar.gz
Size 99.2 kB
Tags Source
SHA-256 checksum
How to use checksums
047b5d93a1d9f4ba24ca23edceb2e25bca3dbc4d7b2237ee18277569bceb4a37
BLAKE2b-256 checksum
How to use checksums
c2c3cefd682b74afd27cba289410b6ae87860402a18f5d74ac65e76bf44cb558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release files / surface_sim-0.11.0-py3-none-any.whl

Download URL surface_sim-0.11.0-py3-none-any.whl
Size 123.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a43303b10613a158e61bb95e3a907af8db9d13a75530f2c0466bc075250da5da
BLAKE2b-256 checksum
How to use checksums
52f3a43ba939ed44040c0485adc7a457302ca80f061bd21c0ad06f143d55fff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page