Skip to content

Commit

Permalink
Add stim.Tableau.to_circuit("graph_state")
Browse files Browse the repository at this point in the history
- Add `stim::GraphSimulator` with support for unitary operations

Fixes #647
  • Loading branch information
Strilanc committed Nov 25, 2023
1 parent 50d4db5 commit f02462e
Show file tree
Hide file tree
Showing 13 changed files with 1,166 additions and 85 deletions.
71 changes: 51 additions & 20 deletions doc/python_api_reference_vDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -10107,6 +10107,20 @@ def to_circuit(
Circuit qubit count: n
Circuit operation count: O(n^2)
Circuit depth: O(n^2)
"graph_state": Prepares the tableau's state using a graph state circuit.
Gate set: RX, CZ, H, S, X, Y, Z
Circuit qubit count: n
Circuit operation count: O(n^2)
The circuit will be made up of three layers:
1. An RX layer initializing all qubits.
2. A CZ layer coupling the qubits.
(Each CZ is an edge in the graph state.)
3. A single qubit rotation layer.
Note: "graph_state" treats the tableau as a state instead of as a
Clifford operation. It will preserve the set of stabilizers, but
not the exact choice of generators.
Returns:
The synthesized circuit.
Expand All @@ -10115,35 +10129,52 @@ def to_circuit(
>>> import stim
>>> tableau = stim.Tableau.from_conjugated_generators(
... xs=[
... stim.PauliString("-_YZ"),
... stim.PauliString("-YY_"),
... stim.PauliString("-XZX"),
... stim.PauliString("+YZ__"),
... stim.PauliString("-Y_XY"),
... stim.PauliString("+___Y"),
... stim.PauliString("+YZX_"),
... ],
... zs=[
... stim.PauliString("+Y_Y"),
... stim.PauliString("-_XY"),
... stim.PauliString("-Y__"),
... stim.PauliString("+XZYY"),
... stim.PauliString("-XYX_"),
... stim.PauliString("-ZXXZ"),
... stim.PauliString("+XXZ_"),
... ],
... )
>>> tableau.to_circuit(method="elimination")
>>> tableau.to_circuit()
stim.Circuit('''
CX 2 0 0 2 2 0
S 0
H 0
S 0
H 0 1 3
CX 0 1 0 2 0 3
S 1 3
H 1 3
CX 1 0 3 0 3 1 1 3 3 1
H 1
CX 0 1 0 2
H 1 2
CX 1 0 2 0 2 1 1 2 2 1
H 1
S 1 2
H 2
CX 2 1
S 2
H 0 1 2
S 1
CX 1 3
H 2 3
CX 2 1 3 1 3 2 2 3 3 2
H 3
CX 2 3
S 3
H 3 0 1 2
S 0 0 1 1 2 2
H 0 1 2
S 1 1 2 2
S 3 3
''')
>>> tableau.to_circuit("graph_state")
stim.Circuit('''
RX 0 1 2 3
TICK
CZ 0 3 1 2 1 3
TICK
X 0 1
Z 2
S 2 3
H 3
S 3
''')
"""
```
Expand Down
71 changes: 51 additions & 20 deletions doc/stim.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7843,6 +7843,20 @@ class Tableau:
Circuit qubit count: n
Circuit operation count: O(n^2)
Circuit depth: O(n^2)
"graph_state": Prepares the tableau's state using a graph state circuit.
Gate set: RX, CZ, H, S, X, Y, Z
Circuit qubit count: n
Circuit operation count: O(n^2)
The circuit will be made up of three layers:
1. An RX layer initializing all qubits.
2. A CZ layer coupling the qubits.
(Each CZ is an edge in the graph state.)
3. A single qubit rotation layer.
Note: "graph_state" treats the tableau as a state instead of as a
Clifford operation. It will preserve the set of stabilizers, but
not the exact choice of generators.
Returns:
The synthesized circuit.
Expand All @@ -7851,35 +7865,52 @@ class Tableau:
>>> import stim
>>> tableau = stim.Tableau.from_conjugated_generators(
... xs=[
... stim.PauliString("-_YZ"),
... stim.PauliString("-YY_"),
... stim.PauliString("-XZX"),
... stim.PauliString("+YZ__"),
... stim.PauliString("-Y_XY"),
... stim.PauliString("+___Y"),
... stim.PauliString("+YZX_"),
... ],
... zs=[
... stim.PauliString("+Y_Y"),
... stim.PauliString("-_XY"),
... stim.PauliString("-Y__"),
... stim.PauliString("+XZYY"),
... stim.PauliString("-XYX_"),
... stim.PauliString("-ZXXZ"),
... stim.PauliString("+XXZ_"),
... ],
... )
>>> tableau.to_circuit(method="elimination")
>>> tableau.to_circuit()
stim.Circuit('''
CX 2 0 0 2 2 0
S 0
H 0
S 0
H 0 1 3
CX 0 1 0 2 0 3
S 1 3
H 1 3
CX 1 0 3 0 3 1 1 3 3 1
H 1
CX 0 1 0 2
H 1 2
CX 1 0 2 0 2 1 1 2 2 1
H 1
S 1 2
H 2
CX 2 1
S 2
H 0 1 2
S 1
CX 1 3
H 2 3
CX 2 1 3 1 3 2 2 3 3 2
H 3
CX 2 3
S 3
H 3 0 1 2
S 0 0 1 1 2 2
H 0 1 2
S 1 1 2 2
S 3 3
''')
>>> tableau.to_circuit("graph_state")
stim.Circuit('''
RX 0 1 2 3
TICK
CZ 0 3 1 2 1 3
TICK
X 0 1
Z 2
S 2 3
H 3
S 3
''')
"""
def to_numpy(
Expand Down
1 change: 1 addition & 0 deletions file_lists/source_files_no_main
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ src/stim/search/hyper/search_state.cc
src/stim/simulators/error_analyzer.cc
src/stim/simulators/error_matcher.cc
src/stim/simulators/force_streaming.cc
src/stim/simulators/graph_simulator.cc
src/stim/simulators/matched_error.cc
src/stim/simulators/sparse_rev_frame_tracker.cc
src/stim/simulators/transform_without_feedback.cc
Expand Down
1 change: 1 addition & 0 deletions file_lists/test_files
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ src/stim/simulators/error_analyzer.test.cc
src/stim/simulators/error_matcher.test.cc
src/stim/simulators/frame_simulator.test.cc
src/stim/simulators/frame_simulator_util.test.cc
src/stim/simulators/graph_simulator.test.cc
src/stim/simulators/matched_error.test.cc
src/stim/simulators/measurements_to_detection_events.test.cc
src/stim/simulators/sparse_rev_frame_tracker.test.cc
Expand Down
71 changes: 51 additions & 20 deletions glue/python/src/stim/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7843,6 +7843,20 @@ class Tableau:
Circuit qubit count: n
Circuit operation count: O(n^2)
Circuit depth: O(n^2)
"graph_state": Prepares the tableau's state using a graph state circuit.
Gate set: RX, CZ, H, S, X, Y, Z
Circuit qubit count: n
Circuit operation count: O(n^2)
The circuit will be made up of three layers:
1. An RX layer initializing all qubits.
2. A CZ layer coupling the qubits.
(Each CZ is an edge in the graph state.)
3. A single qubit rotation layer.
Note: "graph_state" treats the tableau as a state instead of as a
Clifford operation. It will preserve the set of stabilizers, but
not the exact choice of generators.
Returns:
The synthesized circuit.
Expand All @@ -7851,35 +7865,52 @@ class Tableau:
>>> import stim
>>> tableau = stim.Tableau.from_conjugated_generators(
... xs=[
... stim.PauliString("-_YZ"),
... stim.PauliString("-YY_"),
... stim.PauliString("-XZX"),
... stim.PauliString("+YZ__"),
... stim.PauliString("-Y_XY"),
... stim.PauliString("+___Y"),
... stim.PauliString("+YZX_"),
... ],
... zs=[
... stim.PauliString("+Y_Y"),
... stim.PauliString("-_XY"),
... stim.PauliString("-Y__"),
... stim.PauliString("+XZYY"),
... stim.PauliString("-XYX_"),
... stim.PauliString("-ZXXZ"),
... stim.PauliString("+XXZ_"),
... ],
... )
>>> tableau.to_circuit(method="elimination")
>>> tableau.to_circuit()
stim.Circuit('''
CX 2 0 0 2 2 0
S 0
H 0
S 0
H 0 1 3
CX 0 1 0 2 0 3
S 1 3
H 1 3
CX 1 0 3 0 3 1 1 3 3 1
H 1
CX 0 1 0 2
H 1 2
CX 1 0 2 0 2 1 1 2 2 1
H 1
S 1 2
H 2
CX 2 1
S 2
H 0 1 2
S 1
CX 1 3
H 2 3
CX 2 1 3 1 3 2 2 3 3 2
H 3
CX 2 3
S 3
H 3 0 1 2
S 0 0 1 1 2 2
H 0 1 2
S 1 1 2 2
S 3 3
''')
>>> tableau.to_circuit("graph_state")
stim.Circuit('''
RX 0 1 2 3
TICK
CZ 0 3 1 2 1 3
TICK
X 0 1
Z 2
S 2 3
H 3
S 3
''')
"""
def to_numpy(
Expand Down
1 change: 1 addition & 0 deletions src/stim.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include "stim/simulators/force_streaming.h"
#include "stim/simulators/frame_simulator.h"
#include "stim/simulators/frame_simulator_util.h"
#include "stim/simulators/graph_simulator.h"
#include "stim/simulators/matched_error.h"
#include "stim/simulators/measurements_to_detection_events.h"
#include "stim/simulators/sparse_rev_frame_tracker.h"
Expand Down
Loading

0 comments on commit f02462e

Please sign in to comment.