### Install Stimflow Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/getting_started.ipynb Install Stimflow using pip. This is the first step to using the library. ```bash pip install stimflow ``` -------------------------------- ### Install Stim ZX from Source Source: https://github.com/quantumlib/stim/blob/main/glue/zx/README.md Instructions for installing Stim ZX from its source code using pip. ```bash git clone git@github.com:quantumlib/stim.git cd stim pip install -e glue/zx ``` -------------------------------- ### Creating a Python Development Environment Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Steps to set up a Python development environment, including creating a virtual environment, building and installing a Stim wheel, and installing development references for glue packages. ```base # from the repository root in a python virtual environment bazel build :stim_dev_wheel pip uninstall stim --yes pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl ``` ```bash # install test dependencies pip install pytest pymatching # install stimcirq dev reference: pip install -e glue/cirq # install sinter dev reference: pip install -e glue/sample # install stimzx dev reference: pip install -e glue/zx ``` -------------------------------- ### Circuit Instruction Examples Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Demonstrates how to create a Stim Circuit and access its instructions. Shows examples of different instruction types like H, M, and X_ERROR. ```python import stim circuit = stim.Circuit(''' H 0 M 0 1 X_ERROR(0.125) 5 ''') circuit[0] circuit[1] circuit[2] ``` -------------------------------- ### Install Stimcirq with Pip Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Install Stimcirq as a development package using pip install -e. This installs the package in the current virtual environment as a development reference. ```bash # from repo root pip install -e glue/cirq # stimcirq is now installed in current virtualenv as dev reference ``` -------------------------------- ### Installing Stim Development Wheel Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Install a Stim development wheel after building it. This command assumes the wheel file is located in 'bazel-bin/'. ```bash pip uninstall stim --yes pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl ``` -------------------------------- ### Install Stimzx with Pip Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Install Stimzx as a development package using pip install -e. This installs the package in the current virtual environment as a development reference. ```bash # from repo root pip install -e glue/zx # stimzx is now installed in current virtualenv as dev reference ``` -------------------------------- ### Install Sinter with Pip Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Install Sinter as a development package using pip install -e. This installs the package in the current virtual environment as a development reference. ```bash # from repo root pip install -e glue/sample # sinter is now installed in current virtualenv as dev reference ``` -------------------------------- ### Install Sinter Library Source: https://github.com/quantumlib/stim/blob/main/doc/getting_started.ipynb Installs the sinter library, a tool to streamline Monte Carlo sampling for error-correcting codes. Use this for automated sampling and analysis. ```bash !pip install sinter~=1.14 ``` -------------------------------- ### Import Stim and Print Version Source: https://github.com/quantumlib/stim/blob/main/doc/getting_started.ipynb Imports the Stim library and prints its installed version. This confirms a successful installation. ```python import stim print(stim.__version__) ``` -------------------------------- ### Install Stim as Development Wheel with Pip Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Install Stim directly as a development Python wheel using pip install -e. This installs the package in the current virtual environment as a development reference. ```bash # from the repository root pip install -e . # stim is now installed in current virtualenv as dev reference ``` -------------------------------- ### Install Stim using pip Source: https://github.com/quantumlib/stim/blob/main/README.md Install Stim as a Python package using pip. This is the most common way to use Stim. ```bash pip install stim ``` -------------------------------- ### Install PyMatching Source: https://github.com/quantumlib/stim/blob/main/doc/getting_started.ipynb Install the PyMatching package using pip. Ensure you are using a compatible version. ```shell !pip install pymatching~=2.0 ``` -------------------------------- ### Install Sinter using pip Source: https://github.com/quantumlib/stim/blob/main/glue/sample/README.md Install the Sinter library using pip. This command can be run in any Python environment. ```bash pip install sinter ``` -------------------------------- ### Stimflow ChunkBuilder Example: Full Circuit Compilation Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md This example demonstrates the complete process of creating, compiling, and verifying multiple chunks using Stimflow's ChunkBuilder and ChunkCompiler. It includes setting up initial, idle, and end chunks with various operations and flows. ```python import stimflow as sf xx = sf.PauliMap.from_xs([0, 1]) zz = sf.PauliMap.from_zs([0, 1]) # Initial Chunk init_builder = sf.ChunkBuilder() init_builder.append("R", [0, 1]) init_builder.add_flow(end=zz) init_builder.add_discarded_flow_output(sf.PauliMap.from_xs([0, 1])) init_chunk = init_builder.finish_chunk() init_chunk.verify() # Idle Chunk idle_builder = sf.ChunkBuilder() idle_builder.append("MXX", [(0, 1)], measure_key_func=lambda e: ('X', e)) idle_builder.append("TICK") idle_builder.append("MZZ", [(0, 1)], measure_key_func=lambda e: ('Z', e)) idle_builder.add_flow(start=xx, measurements=[('X', (0, 1))]) idle_builder.add_flow(start=zz, measurements=[('Z', (0, 1))]) idle_builder.add_flow(end=xx, measurements=[('X', (0, 1))]) idle_builder.add_flow(end=zz, measurements=[('Z', (0, 1))]) idle_chunk = idle_builder.finish_chunk() idle_chunk.verify() # End Chunk end_builder = sf.ChunkBuilder() end_builder.append("M", [0, 1]) end_builder.add_flow(start=zz, measurements=[0, 1]) end_builder.add_discarded_flow_input(sf.PauliMap.from_xs([0, 1])) end_chunk = end_builder.finish_chunk() end_chunk.verify() # Compiler compiler = sf.ChunkCompiler() compiler.append(init_chunk) compiler.append(idle_chunk) compiler.append(end_chunk) print(compiler.finish_circuit()) ``` ```stim QUBIT_COORDS(0, 0) 0 QUBIT_COORDS(1, 0) 1 R 0 1 TICK MXX 0 1 TICK MZZ 0 1 DETECTOR(0.5, 0, 0) rec[-1] SHIFT_COORDS(0, 0, 1) TICK M 0 1 DETECTOR(0.5, 0, 0) rec[-3] rec[-2] rec[-1] ``` -------------------------------- ### Basic Detecting Regions Example Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Demonstrates how to use the `detecting_regions` method on a simple circuit to see error sensitivities at different ticks. This example shows sensitivities for detectors at ticks 0, 1, and 2. ```python import stim detecting_regions = stim.Circuit(''' R 0 TICK H 0 TICK CX 0 1 TICK MX 0 1 DETECTOR rec[-1] rec[-2] ''').detecting_regions() for target, tick_regions in detecting_regions.items(): print("target", target) for tick, sensitivity in tick_regions.items(): print(" tick", tick, "=", sensitivity) ``` -------------------------------- ### Install Stim and Dependencies Source: https://github.com/quantumlib/stim/blob/main/doc/getting_started.ipynb Installs the Stim package and its dependencies using pip. Ensure you are using compatible versions for libraries like numpy. ```python !pip install stim~=1.14 !pip install numpy~=1.0 # 1.0 instead of 2.0 for pymatching compatibility later !pip install scipy ``` -------------------------------- ### Get Start Patch of Stimflow Chunk Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Retrieves the Patch associated with the start of the chunk. ```python # stimflow.Chunk.start_patch # (in class stimflow.Chunk) def start_patch( self, ) -> Patch: ``` -------------------------------- ### Get Start Code of Stimflow Chunk Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Retrieves the StabilizerCode associated with the start of the chunk. ```python # stimflow.Chunk.start_code # (in class stimflow.Chunk) def start_code( self, ) -> StabilizerCode: ``` -------------------------------- ### Get Start Patch of ChunkLoop Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Retrieves the start patch of the first chunk within a ChunkLoop. This method is part of the ChunkLoop API. ```python # stimflow.ChunkLoop.start_patch # (in class stimflow.ChunkLoop) def start_patch( self, ) -> Patch: ``` -------------------------------- ### Create a Stim Circuit Source: https://github.com/quantumlib/stim/blob/main/doc/getting_started.ipynb Demonstrates how to initialize an empty Stim circuit. This is the starting point for building quantum circuits. ```python import stim circuit = stim.Circuit() print(circuit) ``` -------------------------------- ### Get Start Interface of ChunkLoop Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Retrieves the start interface of the first chunk within a ChunkLoop. This is useful for understanding the input interface of the repeated sequence. ```python # stimflow.ChunkLoop.start_interface # (in class stimflow.ChunkLoop) def start_interface( self, ) -> ChunkInterface: """Returns the start interface of the first chunk in the loop. """ ``` -------------------------------- ### stimflow.ChunkLoop.start_patch Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Returns the start patch of the first chunk in the loop. This can be used for initial circuit setup or analysis. ```APIDOC ## stimflow.ChunkLoop.start_patch ### Description Returns the start patch of the first chunk in the loop. ### Method GET ### Endpoint /stimflow/ChunkLoop/start_patch ### Parameters None ### Response #### Success Response (200) - **return_value** (Patch) - The start patch of the first chunk. ``` -------------------------------- ### Stim Diagram with Input and Output Files Source: https://github.com/quantumlib/stim/blob/main/doc/usage_command_line.md This example shows how to specify input and output files for the 'stim diagram' command. The input is read from 'circuit.stim' and the output is written to 'diagram.txt'. ```bash stim diagram --in circuit.stim --out diagram.txt --type timeline-text ``` -------------------------------- ### Verify Surface Code Initialization Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/getting_started.ipynb Demonstrates how to create and verify surface codes with different initializations. Use this to ensure code integrity. ```python make_surface_code_init_chunk(make_surface_code(4), init_basis="X").verify() make_surface_code_init_chunk(make_surface_code(4), init_basis="Z").verify() make_surface_code_init_chunk(make_surface_code(5), init_basis="Z").verify() ``` -------------------------------- ### Get Start Interface of Stimflow Chunk Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Returns a description of the flows that should enter into the chunk. Allows skipping passthroughs. ```python # stimflow.Chunk.start_interface # (in class stimflow.Chunk) def start_interface( self, *, skip_passthroughs: bool = False, ) -> ChunkInterface: """Returns a description of the flows that should enter into the chunk. """ ``` -------------------------------- ### Initialize stim.CircuitTargetsInsideInstruction Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Demonstrates how to create an instance of stim.CircuitTargetsInsideInstruction with specified gate, arguments, and target information. ```python import stim val = stim.CircuitTargetsInsideInstruction( gate='X_ERROR', tag='', args=[0.25], target_range_start=0, target_range_end=1, targets_in_range=[stim.GateTargetWithCoords(0, [])], ) ``` -------------------------------- ### Initialize LatticeSurgerySynthesizer with Kissat Solver Source: https://github.com/quantumlib/stim/blob/main/glue/lattice_surgery/docs/demo.ipynb Demonstrates how to initialize the LatticeSurgerySynthesizer to use the Kissat SAT solver instead of the default Z3 solver. Requires specifying the directory where Kissat is installed. ```python las_synth = LatticeSurgerySynthesizer(solver="kissat", kissat_dir="") ``` -------------------------------- ### Interactive Simulation with TableauSimulator Source: https://github.com/quantumlib/stim/blob/main/glue/python/README.md Use stim.TableauSimulator for step-by-step simulation of quantum operations and inspection of the simulator's state. This example demonstrates creating a GHZ state and measuring it. ```python import stim s = stim.TableauSimulator() # Create a GHZ state. s.h(0) s.cnot(0, 1) s.cnot(0, 2) # Look at the simulator state re-inverted to be forwards: t = s.current_inverse_tableau() print(t**-1) # prints: # +-xz-xz-xz- # | ++ ++ ++ # | ZX _Z _Z # | _X XZ __ # | _X __ XZ # Measure the GHZ state. print(s.measure_many(0, 1, 2)) # prints one of: # [True, True, True] # or: # [False, False, False] ``` -------------------------------- ### Create and Sample a Simple Stim Circuit Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Demonstrates the creation of a basic Stim circuit with an X gate and a measurement, followed by sampling. ```python import stim c = stim.Circuit() c.append("X", 0) c.append("M", 0) c.compile_sampler().sample(shots=1) ``` -------------------------------- ### Initialize ChunkBuilder with Allowed Qubits Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md This example shows how to create a ChunkBuilder instance, specifying the set of allowed qubit positions for the circuit. This is useful for constraining the builder to a specific set of qubits. ```python import stimflow as sf data_qubits = range(5) measure_qubits = [q + 0.5 for q in data_qubits[::-1]] builder = sf.ChunkBuilder(allowed_qubits=[*data_qubits, *measure_qubits]) ``` -------------------------------- ### YCY Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the YCY gate to different qubit pairs. ```stim YCY 5 6 YCY 42 43 YCY 5 6 42 43 ``` -------------------------------- ### Stim Sample Command Line Interface Source: https://github.com/quantumlib/stim/blob/main/doc/usage_command_line.md This snippet shows the basic structure and available options for the 'stim sample' command. Use it to understand how to specify input circuits, output formats, and control sampling parameters. ```bash stim sample \ [--in filepath] \ [--out filepath] \ [--out_format 01|b8|r8|ptb64|hits|dets] \ [--seed int] \ [--shots int] \ [--skip_loop_folding] \ [--skip_reference_sample] ``` -------------------------------- ### H_NXY Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the H_NXY gate to single or multiple qubits. ```stim H_NXY 5 H_NXY 42 H_NXY 5 42 ``` -------------------------------- ### C_ZYX Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the C_ZYX gate to single or multiple qubits. ```stim C_ZYX 5 C_ZYX 42 C_ZYX 5 42 ``` -------------------------------- ### Write Circuit Samples to 01 Format File Source: https://github.com/quantumlib/stim/blob/main/doc/result_formats.md Demonstrates how to use Stim's Python API to sample a circuit and write the results to a file in the '01' format. This format is human-readable and dense. ```python import pathlib import stim import tempfile with tempfile.TemporaryDirectory() as d: path = str(pathlib.Path(d) / "tmp.dat") stim.Circuit(""" X 1 M 0 0 0 0 1 1 1 1 0 0 1 1 0 1 """).compile_sampler().sample_write(shots=10, filepath=path, format="01") with open(path) as f: print(f.read().strip()) ``` -------------------------------- ### stim.FlipSimulator.__init__ Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Initializes the FlipSimulator. ```python # stim.FlipSimulator.__init__ ``` -------------------------------- ### C_ZYNX Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the C_ZYNX gate to single or multiple qubits. ```stim C_ZYNX 5 C_ZYNX 42 C_ZYNX 5 42 ``` -------------------------------- ### Example CSV Content Source: https://github.com/quantumlib/stim/blob/main/doc/sinter_command_line.md Displays the content of a sample 'stats.csv' file, showing aggregated statistics for circuits. This file is typically generated by 'sinter collect'. ```bash cat stats.csv shots, errors, discards, seconds,decoder,strong_id,json_metadata 100, 0, 0, 0.174,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 100, 0, 0, 0.000,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 400, 0, 0, 0.000,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 1200, 0, 0, 0.000,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 100, 0, 0, 0.178,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 3600, 0, 0, 0.001,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 3600, 0, 0, 0.001,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 10800, 0, 0, 0.002,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 18000, 0, 0, 0.003,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 39600, 0, 0, 0.007,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 75600, 0, 0, 0.012,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 154800, 2, 0, 0.028,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 306000, 5, 0, 0.051,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 200, 0, 0, 0.000,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 600, 0, 0, 0.001,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 1800, 0, 0, 0.001,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 5400, 0, 0, 0.002,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 16200, 0, 0, 0.004,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 48600, 1, 0, 0.010,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 385800, 5, 0, 0.071,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" 145800, 0, 0, 0.030,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 145800, 0, 0, 0.032,pymatching,639d47a421d2a7661bb5b19255295767fc7cf0be7592fe4bcbc2639068e21349,"{""d"":7,""p"":0.01,""r"":5}" 200, 0, 0, 0.178,pymatching,41fe89ff6c51e598d51846cb7a2b626fbfcaa76adcd1be9e0f1e2dff1fe87f1c,"{""d"":5,""p"":0.01,""r"":5}" ``` -------------------------------- ### C_NZYX Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the C_NZYX gate to single or multiple qubits. ```stim C_NZYX 5 C_NZYX 42 C_NZYX 5 42 ``` -------------------------------- ### C_NXYZ Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the C_NXYZ gate to single or multiple qubits. ```stim C_NXYZ 5 C_NXYZ 42 C_NXYZ 5 42 ``` -------------------------------- ### PauliMap Initialization Examples Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/api.md Demonstrates various ways to initialize a PauliMap, including empty, from dictionaries, from other Stimflow/Stim objects, and with observation names. ```python # stimflow.PauliMap.__init__ # (in class stimflow.PauliMap) def __init__( self, mapping: "dict[complex, Literal['X, 'Y, 'Z'] | str] | dict[Literal['X, 'Y, 'Z'] | str, complex | Iterable[complex]] | PauliMap | Tile | stim.PauliString | None" = None, *, obs_name: Any = None, ): """Initializes a PauliMap using maps of Paulis to/from qubits. Args: mapping: The association between qubits and paulis, specifiable in a variety of ways. obs_name: Defaults to None (no name). Can be set to an arbitrary hashable equatable value, in order to identify the Pauli map. A common convention used in the library is that named Pauli maps correspond to logical operators. Examples: >>> import stimflow as sf >>> import stim >>> print(sf.PauliMap()) I >>> print(sf.PauliMap({0: "X", 1: "Y", 2: "Z"})) X0*Y1*Z2 >>> print(sf.PauliMap({"X": [1, 2], "Y": 1+1j})) X1*Y(1+1j)*X2 >>> print(sf.PauliMap(stim.PauliString("XYZ_X"))) X0*Y1*Z2*X4 >>> print(sf.PauliMap(sf.Tile(data_qubits=[1, 2, 3], bases="X"))) X1*X2*X3 >>> print(sf.PauliMap({0: "X", "Y": [0, 1]})) Z0*Y1 >>> print(sf.PauliMap({0: "X", 1: "Y", 2: "Z"}, obs_name="test")) (obs_name='test') X0*Y1*Z2 """ ``` -------------------------------- ### Pauli Y Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the Pauli Y gate to single or multiple qubits. ```stim Y 5 Y 42 Y 5 42 ``` -------------------------------- ### Building Stim Wheels with Cibuildwheels Locally Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Use cibuildwheels locally to build Stim wheels for a specific platform. This requires Docker to be installed. ```bash CIBW_BUILD=cp39-manylinux_x86_64 cibuildwheel --platform linux ``` -------------------------------- ### H_YZ Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the H_YZ gate to single qubits or multiple qubits. ```stim H_YZ 5 H_YZ 42 H_YZ 5 42 ``` -------------------------------- ### Build Sinter Python Source Distribution Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Create a source distribution for the Sinter Python package. Navigate to the glue/sample directory and run setup.py sdist. The output is located in glue/sample/dist/*. ```bash # from repo root cd glue/sample python setup.py sdist cd - # output in glue/sample/dist/* ``` -------------------------------- ### H_XY Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the H_XY gate to single qubits or multiple qubits. ```stim H_XY 5 H_XY 42 H_XY 5 42 ``` -------------------------------- ### H_NYZ Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the H_NYZ gate to single qubits or multiple qubits. ```stim H_NYZ 5 H_NYZ 42 H_NYZ 5 42 ``` -------------------------------- ### Run performance benchmarks with Bazel Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Execute Stim's performance benchmarks using Bazel. Ensure you are in the repository root. ```bash bazel run stim_perf ``` -------------------------------- ### H_NXZ Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the H_NXZ gate to single qubits or multiple qubits. ```stim H_NXZ 5 H_NXZ 42 H_NXZ 5 42 ``` -------------------------------- ### Build Stim Python Binary Distribution Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Create a development version of the Stim Python wheel using setup.py's bdist command. Requires a Python virtual environment with pybind11 installed. Output is in the dist/ directory. ```bash # from the repository root in a python venv with pybind11 installed: python setup.py bdist # output is at dist/* ``` -------------------------------- ### Hadamard Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the Hadamard gate (H) to single or multiple qubits. ```stim H 5 H 42 H 5 42 ``` -------------------------------- ### Building Stim Development Wheel with Bazel Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Build a development wheel for the Stim library using Bazel. This command should be executed from the repository root. ```bash bazel build :stim_dev_wheel ``` -------------------------------- ### Pauli Z Gate Example Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the Pauli Z gate to single or multiple qubits. ```stim Z 5 Z 42 Z 5 42 ``` -------------------------------- ### Build Stim Python Source Distribution Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Create a source distribution of the Stim Python package using setup.py's sdist command. Requires a Python virtual environment with pybind11 installed. Output is in the dist/ directory. ```bash # from the repository root in a python venv with pybind11 installed: python setup.py sdist # output is at dist/* ``` -------------------------------- ### stim.ExplainedError.__init__ Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Creates a stim.ExplainedError. ```APIDOC ## stim.ExplainedError.__init__ ### Description Creates a stim.ExplainedError. ### Method `__init__` ### Parameters #### Keyword Arguments - **dem_error_terms** (List[stim.DemTargetWithCoords]) - Required - The DEM error terms. - **circuit_error_locations** (List[stim.CircuitErrorLocation]) - Required - The circuit error locations. ### Request Example ```python import stim err = stim.Circuit(''' R 0 TICK Y_ERROR(0.125) 0 M 0 OBSERVABLE_INCLUDE(0) rec[-1] ''').shortest_graphlike_error() print(err[0]) ``` ### Response #### Success Response (None) This method does not return a value. ``` -------------------------------- ### Interactive Stim REPL Session Source: https://github.com/quantumlib/stim/blob/main/doc/usage_command_line.md Demonstrates an interactive session using the 'stim repl' command. Shows how to apply operations like measurement (M), Pauli-X (X), and Pauli-R (R), and how to use control flow structures like REPEAT. ```bash stim repl ... M 0 0 ... X 0 ... M 0 1 ... X 2 3 9 ... M 0 1 2 3 4 5 6 7 8 9 1 0 1 1 0 0 0 0 0 1 ... REPEAT 5 { ... R 0 1 ... H 0 ... CNOT 0 1 ... M 0 1 ... } 00 11 11 00 11 ``` -------------------------------- ### Print Stimflow and Stim Versions Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/getting_started.ipynb Prints the installed versions of the stimflow and stim libraries. This is useful for verifying the installation. ```python print(f"{stimflow.__version__=}") print(f"{stim.__version__=}") ``` -------------------------------- ### Build Stimzx Python Source Distribution Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Create a source distribution for the Stimzx Python package. Navigate to the glue/zx directory and run setup.py sdist. The output is located in glue/zx/dist/*. ```bash # from repo root cd glue/zx python setup.py sdist cd - # output in glue/zx/dist/* ``` -------------------------------- ### Example Bacon-Shor Circuit Source: https://github.com/quantumlib/stim/blob/main/glue/crumble/crumble.html This is an example of a 5x5x3 Bacon-Shor circuit using interleaved XZXZ gates and memory qubits. ```stim Q(0,0)0;Q(0,1)1;Q(0,2)2;Q(0,3)3;Q(0,4)4;Q(1,0)5;Q(1,1)6;Q(1,2)7;Q(1,3)8;Q(1,4)9;Q(2,0)10;Q(2,1)11;Q(2,2)12;Q(2,3)13;Q(2,4)14;Q(3,0)15;Q(3,1)16;Q(3,2)17;Q(3,3)18;Q(3,4)19;Q(4,0)20;Q(4,1)21;Q(4,2)22;Q(4,3)23;Q(4,4)24;POLYGON(0,0,1,0.25)23_24;POLYGON(0,0,1,0.25)18_19;POLYGON(0,0,1,0.25)13_14;POLYGON(0,0,1,0.25)8_9;POLYGON(0,0,1,0.25)3_4;POLYGON(0,0,1,0.25)22_23;POLYGON(0,0,1,0.25)17_18;POLYGON(0,0,1,0.25)12_13;POLYGON(0,0,1,0.25)7_8;POLYGON(0,0,1,0.25)2_3;POLYGON(0,0,1,0.25)21_22;POLYGON(0,0,1,0.25)16_17;POLYGON(0,0,1,0.25)11_12;POLYGON(0,0,1,0.25)6_7;POLYGON(0,0,1,0.25)1_2;POLYGON(0,0,1,0.25)20_21;POLYGON(0,0,1,0.25)15_16;POLYGON(0,0,1,0.25)10_11;POLYGON(0,0,1,0.25)5_6;POLYGON(0,0,1,0.25)0_1;POLYGON(1,0,0,0.25)24_19;POLYGON(1,0,0,0.25)19_14;POLYGON(1,0,0,0.25)14_9;POLYGON(1,0,0,0.25)9_4;POLYGON(1,0,0,0.25)23_18;POLYGON(1,0,0,0.25)18_13;POLYGON(1,0,0,0.25)13_8;POLYGON(1,0,0,0.25)8_3;POLYGON(1,0,0,0.25)22_17;POLYGON(1,0,0,0.25)17_12;POLYGON(1,0,0,0.25)12_7;POLYGON(1,0,0,0.25)7_2;POLYGON(1,0,0,0.25)21_16;POLYGON(1,0,0,0.25)16_11;POLYGON(1,0,0,0.25)11_6;POLYGON(1,0,0,0.25)6_1;POLYGON(1,0,0,0.25)20_15;POLYGON(1,0,0,0.25)15_10;POLYGON(1,0,0,0.25)10_5;POLYGON(1,0,0,0.25)5_0;TICK;R_0_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24;MARKZ(0)1_2_6_7_11_12_16_17_21_22;TICK;TICK;MZZ_0_1_5_6_10_11_15_16_20_21_2_3_7_8_12_13_17_18_22_23;DT(0,0,0)rec[-10];DT(1,0,0)rec[-9];DT(2,0,0)rec[-8];DT(3,0,0)rec[-7];DT(4,0,0)rec[-6];DT(0,2,0)rec[-5];DT(1,2,0)rec[-4];DT(2,2,0)rec[-3];DT(3,2,0)rec[-2];DT(4,2,0)rec[-1];TICK;MXX_0_5_1_6_2_7_3_8_4_9_10_15_11_16_12_17_13_18_14_19;MARKX(1)10_11_12_13_14_15_16_17_18_19;TICK;MZZ_1_2_6_7_11_12_16_17_21_22_3_4_8_9_13_14_18_19_23_24;MARKZ(0)1_2_6_7_11_12_16_17_21_22;DT(4,1,1)rec[-6]_rec[-7]_rec[-8]_rec[-9]_rec[-10];DT(4,3,1)rec[-1]_rec[-2]_rec[-3]_rec[-4]_rec[-5];TICK;MXX_5_10_6_11_7_12_8_13_9_14_15_20_16_21_17_22_18_23_19_24;TICK;TICK;MZZ_0_1_5_6_10_11_15_16_20_21_2_3_7_8_12_13_17_18_22_23;DT(4,0,2)rec[-6]_rec[-7]_rec[-8]_rec[-9]_rec[-10]_rec[-46]_rec[-47]_rec[-48]_rec[-49]_rec[-50];DT(4,2,2)rec[-1]_rec[-2]_rec[-3]_rec[-4]_rec[-5]_rec[-41]_rec[-42]_rec[-43]_rec[-44]_rec[-45];TICK;MXX_0_5_1_6_2_7_3_8_4_9_10_15_11_16_12_17_13_18_14_19;MARKX(1)10_11_12_13_14_15_16_17_18_19;DT(0,4,3)rec[-6]_rec[-7]_rec[-8]_rec[-9]_rec[-10]_rec[-46]_rec[-47]_rec[-48]_rec[-49]_rec[-50];DT(2,4,3)rec[-1]_rec[-2]_rec[-3]_rec[-4]_rec[-5]_rec[-41]_rec[-42]_rec[-43]_rec[-44]_rec[-45];TICK;MZZ_1_2_6_7_11_12_16_17_21_22_3_4_8_9_13_14_18_19_23_24;DT(4,1,4)rec[-6]_rec[-7]_rec[-8]_rec[-9]_rec[-10]_rec[-46]_rec[-47]_rec[-48]_rec[-49]_rec[-50];DT(4,3,4)rec[-1]_rec[-2]_rec[-3]_rec[-4]_rec[-5]_rec[-41]_rec[-42]_rec[-43]_rec[-44]_rec[-45];TICK;MXX_5_10_6_11_7_12_8_13_9_14_15_20_16_21_17_22_18_23_19_24;DT(1,4,5)rec[-6]_rec[-7]_rec[-8]_rec[-9]_rec[-10]_rec[-46]_rec[-47]_rec[-48]_rec[-49]_rec[-50];DT(3,4,5)rec[-1]_rec[-2]_rec[-3]_rec[-4]_rec[-5]_rec[-41]_rec[-42]_rec[-43]_rec[-44]_rec[-45];TICK;TICK;MZZ_0_1_5_6_10_11_15_16_20_21_2_3_7_8_12_13_17_18_22_23;DT(4,0,6)rec[-6]_rec[-7] ``` -------------------------------- ### Basic Stim Diagram Command Source: https://github.com/quantumlib/stim/blob/main/doc/usage_command_line.md This is a basic example of how to use the 'stim diagram' command. It requires specifying the type of diagram to generate. ```bash stim diagram --type timeline-text ``` -------------------------------- ### Build Stimcirq Python Source Distribution Source: https://github.com/quantumlib/stim/blob/main/doc/developer_documentation.md Create a source distribution for the Stimcirq Python package. Navigate to the glue/cirq directory and run setup.py sdist. The output is located in glue/cirq/dist/*. ```bash # from repo root cd glue/cirq python setup.py sdist cd - # output in glue/cirq/dist/* ``` -------------------------------- ### stim.FlipSimulator.__init__ Source: https://github.com/quantumlib/stim/blob/main/doc/python_api_reference_vDev.md Initializes a stim.FlipSimulator. This simulator is designed to efficiently simulate many quantum circuit instances in parallel, tracking measurement flips. It offers options for controlling the batch size, enabling/disabling stabilizer randomization for debugging, setting the initial number of qubits, and seeding the random number generator for reproducible results. ```APIDOC ## stim.FlipSimulator.__init__ ### Description Initializes a stim.FlipSimulator. This simulator is designed to efficiently simulate many quantum circuit instances in parallel, tracking measurement flips. It offers options for controlling the batch size, enabling/disabling stabilizer randomization for debugging, setting the initial number of qubits, and seeding the random number generator for reproducible results. ### Method __init__ ### Parameters #### Keyword Arguments - **batch_size** (int) - Required - For speed, the flip simulator simulates many instances in parallel. This argument determines the number of parallel instances. It's recommended to use a multiple of 256 for optimal performance due to internal SIMD optimizations. - **disable_stabilizer_randomization** (bool) - Optional - Defaults to False. Determines whether or not the flip simulator uses stabilizer randomization. Set to True to disable. Stabilizer randomization is a safety feature that adds Z errors with 50% probability when stabilizers are introduced, enforcing the uncertainty principle and catching mistakes in circuit design. It can be a hindrance in use cases focused on error propagation analysis. - **num_qubits** (int) - Optional - Defaults to 0. Sets the initial number of qubits tracked by the simulation. The simulator will automatically resize as needed. This parameter hints at the desired state size for performance and ensures methods peeking at the size have the expected value from the start. - **seed** (Optional[int]) - Optional - Defaults to None. Partially determines simulation results by deterministically seeding the random number generator. Must be None or an integer in range(2**64). When None, the PRNG is seeded from system entropy. Setting an integer allows for reproducible results under specific conditions, but results may not be consistent across different Stim versions, machines with different SIMD instruction sets, or variations in circuit execution order. ### Returns An initialized stim.FlipSimulator. ### Examples ```python import stim sim = stim.FlipSimulator(batch_size=256) ``` ``` -------------------------------- ### YCZ Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the YCZ gate for various control and target configurations, including classical control and sweep data. ```stim # Apply Y to qubit 5 controlled by qubit 2. YCZ 5 2 # Perform CY 2 5 then CY 4 2. YCZ 5 2 2 4 # Apply Y to qubit 6 if the most recent measurement result was TRUE. YCZ 6 rec[-1] # Apply Y to qubits 7 and 8 conditioned on sweep configuration data. YCZ 7 sweep[5] 8 sweep[5] ``` -------------------------------- ### Create a Stim Circuit Source: https://github.com/quantumlib/stim/blob/main/glue/stimflow/doc/getting_started.ipynb Create a simple Stim circuit. This example demonstrates how to define a circuit with basic gates. ```python import stim circuit = stim.Circuit() circuit.append(stim.H(0)) circuit.append(stim.CNOT(0, 1)) circuit.append(stim.measure(0, 0)) circuit.append(stim.measure(1, 1)) ``` -------------------------------- ### SQRT_ZZ Gate Examples Source: https://github.com/quantumlib/stim/blob/main/doc/gates.md Examples of applying the SQRT_ZZ gate to qubit pairs. This gate phases the -1 eigenspace of the ZZ observable by i. ```stim SQRT_ZZ 5 6 SQRT_ZZ 42 43 SQRT_ZZ 5 6 42 43 ```