Skip to content

Commit

Permalink
Merge branch 'main' into wcnf
Browse files Browse the repository at this point in the history
  • Loading branch information
noajshu authored Mar 16, 2024
2 parents aca2f25 + 2161fc9 commit 379ef48
Show file tree
Hide file tree
Showing 39 changed files with 2,628 additions and 382 deletions.
6 changes: 6 additions & 0 deletions doc/gates.md
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,12 @@ This can be useful for ensuring measurements are aligned to word boundaries, or
number of measurement bits produced per circuit layer is always the same even if the number
of measured qubits varies.

Parens Arguments:

If no parens argument is given, the padding bits are recorded perfectly.
If one parens argument is given, the padding bits are recorded noisily.
The argument is the probability of recording the wrong result.

Targets:

Each target is a measurement result to add.
Expand Down
254 changes: 254 additions & 0 deletions doc/python_api_reference_vDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ API references for stable versions are kept on the [stim github wiki](https://gi
- [`stim.Circuit.compile_sampler`](#stim.Circuit.compile_sampler)
- [`stim.Circuit.copy`](#stim.Circuit.copy)
- [`stim.Circuit.count_determined_measurements`](#stim.Circuit.count_determined_measurements)
- [`stim.Circuit.decomposed`](#stim.Circuit.decomposed)
- [`stim.Circuit.detecting_regions`](#stim.Circuit.detecting_regions)
- [`stim.Circuit.detector_error_model`](#stim.Circuit.detector_error_model)
- [`stim.Circuit.diagram`](#stim.Circuit.diagram)
- [`stim.Circuit.explain_detector_error_model_errors`](#stim.Circuit.explain_detector_error_model_errors)
Expand Down Expand Up @@ -266,6 +268,7 @@ API references for stable versions are kept on the [stim github wiki](https://gi
- [`stim.PauliString.from_numpy`](#stim.PauliString.from_numpy)
- [`stim.PauliString.from_unitary_matrix`](#stim.PauliString.from_unitary_matrix)
- [`stim.PauliString.iter_all`](#stim.PauliString.iter_all)
- [`stim.PauliString.pauli_indices`](#stim.PauliString.pauli_indices)
- [`stim.PauliString.random`](#stim.PauliString.random)
- [`stim.PauliString.sign`](#stim.PauliString.sign)
- [`stim.PauliString.to_numpy`](#stim.PauliString.to_numpy)
Expand Down Expand Up @@ -1273,6 +1276,213 @@ def count_determined_measurements(
"""
```

<a name="stim.Circuit.decomposed"></a>
```python
# stim.Circuit.decomposed

# (in class stim.Circuit)
def decomposed(
self,
) -> stim.Circuit:
"""Recreates the circuit using (mostly) the {H,S,CX,M,R} gate set.
The intent of this method is to simplify the circuit to use fewer gate types,
so it's easier for other tools to consume. Currently, this method performs the
following simplifications:
- Single qubit cliffords are decomposed into {H,S}.
- Multi-qubit cliffords are decomposed into {H,S,CX}.
- Single qubit dissipative gates are decomposed into {H,S,M,R}.
- Multi-qubit dissipative gates are decomposed into {H,S,CX,M,R}.
Currently, the following types of gate *aren't* simplified, but they may be
in the future:
- Noise instructions (like X_ERROR, DEPOLARIZE2, and E).
- Annotations (like TICK, DETECTOR, and SHIFT_COORDS).
- The MPAD instruction.
- Repeat blocks are not flattened.
Returns:
A `stim.Circuit` whose function is equivalent to the original circuit,
but with most gates decomposed into the {H,S,CX,M,R} gate set.
Examples:
>>> import stim
>>> stim.Circuit('''
... SWAP 0 1
... ''').decomposed()
stim.Circuit('''
CX 0 1 1 0 0 1
''')
>>> stim.Circuit('''
... ISWAP 0 1 2 1
... TICK
... MPP !X1*Y2*Z3
... ''').decomposed()
stim.Circuit('''
H 0
CX 0 1 1 0
H 1
S 1 0
H 2
CX 2 1 1 2
H 1
S 1 2
TICK
H 1 2
S 2
H 2
S 2 2
CX 2 1 3 1
M !1
CX 2 1 3 1
H 2
S 2
H 2
S 2 2
H 1
''')
"""
```

<a name="stim.Circuit.detecting_regions"></a>
```python
# stim.Circuit.detecting_regions

# (in class stim.Circuit)
def detecting_regions(
self,
*,
targets: Optional[Iterable[stim.DemTarget | str | Iterable[float]]] = None,
ticks: Optional[Iterable[int]] = None,
) -> Dict[stim.DemTarget, Dict[int, stim.PauliString]]:
"""Records where detectors and observables are sensitive to errors over time.
The result of this method is a nested dictionary, mapping detectors/observables
and ticks to Pauli sensitivities for that detector/observable at that time.
For example, if observable 2 has Z-type sensitivity on qubits 5 and 6 during
tick 3, then `result[stim.target_logical_observable_id(2)][3]` will be equal to
`stim.PauliString("Z5*Z6")`.
If you want sensitivities from more places in the circuit, besides just at the
TICK instructions, you can work around this by making a version of the circuit
with more TICKs.
Args:
targets: Defaults to everything (None).
When specified, this should be an iterable of filters where items
matching any one filter are included.
A variety of filters are supported:
stim.DemTarget: Includes the targeted detector or observable.
Iterable[float]: Coordinate prefix match. Includes detectors whose
coordinate data begins with the same floats.
"D": Includes all detectors.
"L": Includes all observables.
"D#" (e.g. "D5"): Includes the detector with the specified index.
"L#" (e.g. "L5"): Includes the observable with the specified index.
ticks: Defaults to everything (None).
When specified, this should be a list of integers corresponding to
the tick indices to report sensitivities for.
ignore_anticommutation_errors: Defaults to False.
When set to False, invalid detecting regions that anticommute with a
reset will cause the method to raise an exception. When set to True,
the offending component will simply be silently dropped. This can
result in broken detectors having apparently enormous detecting
regions.
Returns:
Nested dictionaries keyed first by a `stim.DemTarget` identifying the
detector or observable, then by the index of the tick, leading to a
PauliString with that target's error sensitivity at that tick.
Note you can use `stim.PauliString.pauli_indices` to quickly get to the
non-identity terms in the sensitivity.
Examples:
>>> 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)
target D0
tick 0 = +Z_
tick 1 = +X_
tick 2 = +XX
>>> circuit = stim.Circuit.generated(
... "surface_code:rotated_memory_x",
... rounds=5,
... distance=4,
... )
>>> detecting_regions = circuit.detecting_regions(
... targets=["L0", (2, 4), stim.DemTarget.relative_detector_id(5)],
... ticks=range(5, 15),
... )
>>> for target, tick_regions in detecting_regions.items():
... print("target", target)
... for tick, sensitivity in tick_regions.items():
... print(" tick", tick, "=", sensitivity)
target D1
tick 5 = +____________________X______________________
tick 6 = +____________________Z______________________
target D5
tick 5 = +______X____________________________________
tick 6 = +______Z____________________________________
target D14
tick 5 = +__________X_X______XXX_____________________
tick 6 = +__________X_X______XZX_____________________
tick 7 = +__________X_X______XZX_____________________
tick 8 = +__________X_X______XXX_____________________
tick 9 = +__________XXX_____XXX______________________
tick 10 = +__________XXX_______X______________________
tick 11 = +__________X_________X______________________
tick 12 = +____________________X______________________
tick 13 = +____________________Z______________________
target D29
tick 7 = +____________________Z______________________
tick 8 = +____________________X______________________
tick 9 = +____________________XX_____________________
tick 10 = +___________________XXX_______X_____________
tick 11 = +____________X______XXXX______X_____________
tick 12 = +__________X_X______XXX_____________________
tick 13 = +__________X_X______XZX_____________________
tick 14 = +__________X_X______XZX_____________________
target D44
tick 14 = +____________________Z______________________
target L0
tick 5 = +_X________X________X________X______________
tick 6 = +_X________X________X________X______________
tick 7 = +_X________X________X________X______________
tick 8 = +_X________X________X________X______________
tick 9 = +_X________X_______XX________X______________
tick 10 = +_X________X________X________X______________
tick 11 = +_X________XX_______X________XX_____________
tick 12 = +_X________X________X________X______________
tick 13 = +_X________X________X________X______________
tick 14 = +_X________X________X________X______________
"""
```

<a name="stim.Circuit.detector_error_model"></a>
```python
# stim.Circuit.detector_error_model
Expand Down Expand Up @@ -9233,6 +9443,50 @@ def iter_all(
"""
```

<a name="stim.PauliString.pauli_indices"></a>
```python
# stim.PauliString.pauli_indices

# (in class stim.PauliString)
def pauli_indices(
self,
included_paulis: str = "XYZ",
) -> List[int]:
"""Returns the indices of non-identity Paulis, or of specified Paulis.
Args:
include: A string containing the Pauli types to include.
X type Pauli indices are included if "X" or "x" is in the string.
Y type Pauli indices are included if "Y" or "y" is in the string.
Z type Pauli indices are included if "Z" or "z" is in the string.
I type Pauli indices are included if "I" or "_" is in the string.
An exception is thrown if other characters are in the string.
Returns:
A list containing the ascending indices of matching Pauli terms.
Examples:
>>> import stim
>>> stim.PauliString("_____X___Y____Z___").pauli_indices()
[5, 9, 14]
>>> stim.PauliString("_____X___Y____Z___").pauli_indices("XZ")
[5, 14]
>>> stim.PauliString("_____X___Y____Z___").pauli_indices("X")
[5]
>>> stim.PauliString("_____X___Y____Z___").pauli_indices("Y")
[9]
>>> stim.PauliString("_____X___Y____Z___").pauli_indices("IY")
[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17]
>>> stim.PauliString("-X103*Y100").pauli_indices()
[100, 103]
"""
```

<a name="stim.PauliString.random"></a>
```python
# stim.PauliString.random
Expand Down
Loading

0 comments on commit 379ef48

Please sign in to comment.