diff --git a/doc/gates.md b/doc/gates.md
index 05b314b59..de61175c3 100644
--- a/doc/gates.md
+++ b/doc/gates.md
@@ -26,6 +26,7 @@
- [CXSWAP](#CXSWAP)
- [CY](#CY)
- [CZ](#CZ)
+ - [CZSWAP](#CZSWAP)
- [ISWAP](#ISWAP)
- [ISWAP_DAG](#ISWAP_DAG)
- [SQRT_XX](#SQRT_XX)
@@ -36,6 +37,7 @@
- [SQRT_ZZ_DAG](#SQRT_ZZ_DAG)
- [SWAP](#SWAP)
- [SWAPCX](#SWAPCX)
+ - [SWAPCZ](#SWAPCZ)
- [XCX](#XCX)
- [XCY](#XCY)
- [XCZ](#XCZ)
@@ -1103,6 +1105,51 @@ Decomposition (into H, S, CX, M, R):
H 1
+
+### The 'CZSWAP' Gate
+
+Alternate name: `SWAPCZ`
+
+A combination CZ-and-SWAP gate.
+This gate is kak-equivalent to the iswap gate.
+
+Parens Arguments:
+
+ This instruction takes no parens arguments.
+
+Targets:
+
+ Qubit pairs to operate on.
+
+Example:
+
+ CZSWAP 5 6
+ CZSWAP 42 43
+ CZSWAP 5 6 42 43
+
+Stabilizer Generators:
+
+ X_ -> ZX
+ Z_ -> _Z
+ _X -> XZ
+ _Z -> Z_
+
+Unitary Matrix (little endian):
+
+ [+1 , , , ]
+ [ , , +1 , ]
+ [ , +1 , , ]
+ [ , , , -1 ]
+
+Decomposition (into H, S, CX, M, R):
+
+ # The following circuit is equivalent (up to global phase) to `CZSWAP 0 1`
+ H 0
+ CX 0 1
+ CX 1 0
+ H 1
+
+
### The 'ISWAP' Gate
diff --git a/file_lists/benchmark_files b/file_lists/benchmark_files
index a2b5f1e28..3e16d7f9d 100644
--- a/file_lists/benchmark_files
+++ b/file_lists/benchmark_files
@@ -1,7 +1,7 @@
src/stim/benchmark_main.perf.cc
src/stim/benchmark_util.perf.cc
src/stim/circuit/circuit.perf.cc
-src/stim/circuit/gate_data.perf.cc
+src/stim/gates/gates.perf.cc
src/stim/io/measure_record_reader.perf.cc
src/stim/main_namespaced.perf.cc
src/stim/mem/simd_bit_table.perf.cc
diff --git a/file_lists/python_api_files b/file_lists/python_api_files
index 50bc6ecac..25a80a28d 100644
--- a/file_lists/python_api_files
+++ b/file_lists/python_api_files
@@ -1,13 +1,13 @@
src/stim/circuit/circuit.pybind.cc
src/stim/circuit/circuit_instruction.pybind.cc
src/stim/circuit/circuit_repeat_block.pybind.cc
-src/stim/circuit/gate_data.pybind.cc
src/stim/circuit/gate_target.pybind.cc
src/stim/cmd/command_diagram.pybind.cc
src/stim/dem/detector_error_model.pybind.cc
src/stim/dem/detector_error_model_instruction.pybind.cc
src/stim/dem/detector_error_model_repeat_block.pybind.cc
src/stim/dem/detector_error_model_target.pybind.cc
+src/stim/gates/gates.pybind.cc
src/stim/io/read_write.pybind.cc
src/stim/py/base.pybind.cc
src/stim/py/compiled_detector_sampler.pybind.cc
diff --git a/file_lists/source_files_no_main b/file_lists/source_files_no_main
index 27511b6ea..b9694b6e5 100644
--- a/file_lists/source_files_no_main
+++ b/file_lists/source_files_no_main
@@ -3,20 +3,6 @@ src/stim/arg_parse.cc
src/stim/circuit/circuit.cc
src/stim/circuit/circuit_instruction.cc
src/stim/circuit/export_qasm.cc
-src/stim/circuit/gate_data.cc
-src/stim/circuit/gate_data_annotations.cc
-src/stim/circuit/gate_data_blocks.cc
-src/stim/circuit/gate_data_collapsing.cc
-src/stim/circuit/gate_data_controlled.cc
-src/stim/circuit/gate_data_hada.cc
-src/stim/circuit/gate_data_heralded.cc
-src/stim/circuit/gate_data_noisy.cc
-src/stim/circuit/gate_data_pair_measure.cc
-src/stim/circuit/gate_data_pauli.cc
-src/stim/circuit/gate_data_period_3.cc
-src/stim/circuit/gate_data_period_4.cc
-src/stim/circuit/gate_data_pp.cc
-src/stim/circuit/gate_data_swaps.cc
src/stim/circuit/gate_decomposition.cc
src/stim/circuit/gate_target.cc
src/stim/cmd/command_analyze_errors.cc
@@ -51,6 +37,20 @@ src/stim/diagram/lattice_map.cc
src/stim/diagram/timeline/timeline_3d_drawer.cc
src/stim/diagram/timeline/timeline_ascii_drawer.cc
src/stim/diagram/timeline/timeline_svg_drawer.cc
+src/stim/gates/gate_data_annotations.cc
+src/stim/gates/gate_data_blocks.cc
+src/stim/gates/gate_data_collapsing.cc
+src/stim/gates/gate_data_controlled.cc
+src/stim/gates/gate_data_hada.cc
+src/stim/gates/gate_data_heralded.cc
+src/stim/gates/gate_data_noisy.cc
+src/stim/gates/gate_data_pair_measure.cc
+src/stim/gates/gate_data_pauli.cc
+src/stim/gates/gate_data_period_3.cc
+src/stim/gates/gate_data_period_4.cc
+src/stim/gates/gate_data_pp.cc
+src/stim/gates/gate_data_swaps.cc
+src/stim/gates/gates.cc
src/stim/gen/circuit_gen_params.cc
src/stim/gen/gen_color_code.cc
src/stim/gen/gen_rep_code.cc
diff --git a/file_lists/test_files b/file_lists/test_files
index 51d1ffdef..6506e3f6a 100644
--- a/file_lists/test_files
+++ b/file_lists/test_files
@@ -2,7 +2,6 @@ src/stim.test.cc
src/stim/arg_parse.test.cc
src/stim/circuit/circuit.test.cc
src/stim/circuit/export_qasm.test.cc
-src/stim/circuit/gate_data.test.cc
src/stim/circuit/gate_decomposition.test.cc
src/stim/circuit/gate_target.test.cc
src/stim/circuit/stabilizer_flow.test.cc
@@ -26,6 +25,7 @@ src/stim/diagram/json_obj.test.cc
src/stim/diagram/timeline/timeline_3d_drawer.test.cc
src/stim/diagram/timeline/timeline_ascii_drawer.test.cc
src/stim/diagram/timeline/timeline_svg_drawer.test.cc
+src/stim/gates/gates.test.cc
src/stim/gen/circuit_gen_params.test.cc
src/stim/gen/gen_color_code.test.cc
src/stim/gen/gen_rep_code.test.cc
@@ -74,6 +74,7 @@ src/stim/stabilizers/conversions.test.cc
src/stim/stabilizers/flex_pauli_string.test.cc
src/stim/stabilizers/pauli_string.test.cc
src/stim/stabilizers/pauli_string_iter.test.cc
+src/stim/stabilizers/pauli_string_ref.test.cc
src/stim/stabilizers/tableau.test.cc
src/stim/stabilizers/tableau_iter.test.cc
src/stim/str_util.test.cc
diff --git a/glue/cirq/stimcirq/__init__.py b/glue/cirq/stimcirq/__init__.py
index 1e5543696..daef84e16 100644
--- a/glue/cirq/stimcirq/__init__.py
+++ b/glue/cirq/stimcirq/__init__.py
@@ -1,6 +1,7 @@
__version__ = '1.13.dev0'
from ._cirq_to_stim import cirq_circuit_to_stim_circuit
from ._cx_swap_gate import CXSwapGate
+from ._cz_swap_gate import CZSwapGate
from ._det_annotation import DetAnnotation
from ._obs_annotation import CumulativeObservableAnnotation
from ._shift_coords_annotation import ShiftCoordsAnnotation
@@ -20,5 +21,6 @@
"SweepPauli": SweepPauli,
"TwoQubitAsymmetricDepolarizingChannel": TwoQubitAsymmetricDepolarizingChannel,
"CXSwapGate": CXSwapGate,
+ "CZSwapGate": CZSwapGate,
}
JSON_RESOLVER = JSON_RESOLVERS_DICT.get
diff --git a/glue/cirq/stimcirq/_cz_swap_gate.py b/glue/cirq/stimcirq/_cz_swap_gate.py
new file mode 100644
index 000000000..6f9ded68c
--- /dev/null
+++ b/glue/cirq/stimcirq/_cz_swap_gate.py
@@ -0,0 +1,46 @@
+from typing import Any, Dict, List
+
+import cirq
+import stim
+
+
+@cirq.value_equality
+class CZSwapGate(cirq.Gate):
+ """Handles explaining stim's CZSWAP gates to cirq."""
+
+ def _num_qubits_(self) -> int:
+ return 2
+
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> List[str]:
+ return ['ZSWAP', 'ZSWAP']
+
+ def _value_equality_values_(self):
+ return ()
+
+ def _decompose_(self, qubits):
+ a, b = qubits
+ yield cirq.SWAP(a, b)
+ yield cirq.CZ(a, b)
+
+ def _stim_conversion_(self, edit_circuit: stim.Circuit, targets: List[int], **kwargs):
+ edit_circuit.append_operation('CZSWAP', targets)
+
+ def __pow__(self, power: int) -> 'CZSwapGate':
+ if power == +1:
+ return self
+ if power == -1:
+ return self
+ return NotImplemented
+
+ def __str__(self) -> str:
+ return 'CZSWAP'
+
+ def __repr__(self):
+ return f'stimcirq.CZSwapGate()'
+
+ @staticmethod
+ def _json_namespace_() -> str:
+ return ''
+
+ def _json_dict_(self) -> Dict[str, Any]:
+ return {}
diff --git a/glue/cirq/stimcirq/_cz_swap_test.py b/glue/cirq/stimcirq/_cz_swap_test.py
new file mode 100644
index 000000000..34c2af445
--- /dev/null
+++ b/glue/cirq/stimcirq/_cz_swap_test.py
@@ -0,0 +1,72 @@
+import cirq
+import stim
+import stimcirq
+
+
+def test_stim_conversion():
+ a, b, c = cirq.LineQubit.range(3)
+
+ cirq_circuit = cirq.Circuit(
+ stimcirq.CZSwapGate().on(a, b),
+ stimcirq.CZSwapGate().on(b, c),
+ )
+ stim_circuit = stim.Circuit(
+ """
+ CZSWAP 0 1
+ TICK
+ CZSWAP 1 2
+ TICK
+ """
+ )
+ assert stimcirq.cirq_circuit_to_stim_circuit(cirq_circuit) == stim_circuit
+ assert stimcirq.stim_circuit_to_cirq_circuit(stim_circuit) == cirq_circuit
+
+
+def test_diagram():
+ a, b = cirq.LineQubit.range(2)
+ cirq.testing.assert_has_diagram(
+ cirq.Circuit(
+ stimcirq.CZSwapGate()(a, b),
+ stimcirq.CZSwapGate()(a, b),
+ ),
+ """
+0: ---ZSWAP---ZSWAP---
+ | |
+1: ---ZSWAP---ZSWAP---
+ """,
+ use_unicode_characters=False,
+ )
+
+
+def test_inverse():
+ a = stimcirq.CZSwapGate()
+ assert a**+1 == a
+ assert a**-1 == a
+
+
+def test_repr():
+ val = stimcirq.CZSwapGate()
+ assert eval(repr(val), {"stimcirq": stimcirq}) == val
+
+
+def test_equality():
+ eq = cirq.testing.EqualsTester()
+ eq.add_equality_group(stimcirq.CZSwapGate(), stimcirq.CZSwapGate())
+
+
+def test_json_serialization():
+ a, b, d = cirq.LineQubit.range(3)
+ c = cirq.Circuit(
+ stimcirq.CZSwapGate()(a, b),
+ stimcirq.CZSwapGate()(b, d),
+ )
+ json = cirq.to_json(c)
+ c2 = cirq.read_json(json_text=json, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER])
+ assert c == c2
+
+
+def test_json_backwards_compat_exact():
+ raw = stimcirq.CZSwapGate()
+ packed = '{\n "cirq_type": "CZSwapGate"\n}'
+ assert cirq.to_json(raw) == packed
+ assert cirq.read_json(json_text=packed, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER]) == raw
diff --git a/glue/cirq/stimcirq/_stim_to_cirq.py b/glue/cirq/stimcirq/_stim_to_cirq.py
index 43bf516d0..af8edeb8f 100644
--- a/glue/cirq/stimcirq/_stim_to_cirq.py
+++ b/glue/cirq/stimcirq/_stim_to_cirq.py
@@ -16,6 +16,7 @@
import stim
from ._cx_swap_gate import CXSwapGate
+from ._cz_swap_gate import CZSwapGate
from ._det_annotation import DetAnnotation
from ._measure_and_or_reset_gate import MeasureAndOrResetGate
from ._obs_annotation import CumulativeObservableAnnotation
@@ -424,6 +425,7 @@ def handler(
measure=False, reset=True, basis='X', invert_measure=False, key=''
)
),
+ "CZSWAP": gate(CZSwapGate()),
"CXSWAP": gate(CXSwapGate(inverted=False)),
"SWAPCX": gate(CXSwapGate(inverted=True)),
"RY": gate(
diff --git a/glue/javascript/tableau.js.cc b/glue/javascript/tableau.js.cc
index e31a2cbb6..920d7079c 100644
--- a/glue/javascript/tableau.js.cc
+++ b/glue/javascript/tableau.js.cc
@@ -3,7 +3,7 @@
#include
#include "common.js.h"
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim.h b/src/stim.h
index bddc097cf..c2777add7 100644
--- a/src/stim.h
+++ b/src/stim.h
@@ -7,8 +7,6 @@
#include "stim/circuit/circuit.h"
#include "stim/circuit/circuit_instruction.h"
#include "stim/circuit/export_qasm.h"
-#include "stim/circuit/gate_data.h"
-#include "stim/circuit/gate_data_table.h"
#include "stim/circuit/gate_decomposition.h"
#include "stim/circuit/gate_target.h"
#include "stim/circuit/stabilizer_flow.h"
@@ -45,6 +43,7 @@
#include "stim/diagram/timeline/timeline_3d_drawer.h"
#include "stim/diagram/timeline/timeline_ascii_drawer.h"
#include "stim/diagram/timeline/timeline_svg_drawer.h"
+#include "stim/gates/gates.h"
#include "stim/gen/circuit_gen_params.h"
#include "stim/gen/gen_color_code.h"
#include "stim/gen/gen_rep_code.h"
diff --git a/src/stim/circuit/circuit.cc b/src/stim/circuit/circuit.cc
index f9cf17763..fd8348ac4 100644
--- a/src/stim/circuit/circuit.cc
+++ b/src/stim/circuit/circuit.cc
@@ -14,11 +14,12 @@
#include "stim/circuit/circuit.h"
+#include
#include
#include
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/gate_target.h"
+#include "stim/gates/gates.h"
#include "stim/str_util.h"
using namespace stim;
diff --git a/src/stim/circuit/circuit.h b/src/stim/circuit/circuit.h
index a69202b9f..bb9fd3c3c 100644
--- a/src/stim/circuit/circuit.h
+++ b/src/stim/circuit/circuit.h
@@ -28,8 +28,8 @@
#include
#include "stim/circuit/circuit_instruction.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/gate_target.h"
+#include "stim/gates/gates.h"
#include "stim/mem/monotonic_buffer.h"
#include "stim/mem/span_ref.h"
diff --git a/src/stim/circuit/circuit.test.cc b/src/stim/circuit/circuit.test.cc
index 6615ae520..0103bf64b 100644
--- a/src/stim/circuit/circuit.test.cc
+++ b/src/stim/circuit/circuit.test.cc
@@ -1619,6 +1619,7 @@ Circuit stim::generate_test_circuit_with_all_operations() {
ISWAP_DAG 4 5
SWAP 6 7
SWAPCX 8 9
+ CZSWAP 10 11
SQRT_XX 0 1
SQRT_XX_DAG 2 3
SQRT_YY 4 5
diff --git a/src/stim/circuit/circuit_instruction.cc b/src/stim/circuit/circuit_instruction.cc
index 8178008ee..d7c327ae7 100644
--- a/src/stim/circuit/circuit_instruction.cc
+++ b/src/stim/circuit/circuit_instruction.cc
@@ -17,8 +17,8 @@
#include
#include "stim/circuit/circuit.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/gate_target.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/circuit_instruction.pybind.cc b/src/stim/circuit/circuit_instruction.pybind.cc
index a554d174d..c29700ed6 100644
--- a/src/stim/circuit/circuit_instruction.pybind.cc
+++ b/src/stim/circuit/circuit_instruction.pybind.cc
@@ -14,8 +14,8 @@
#include "stim/circuit/circuit_instruction.pybind.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/gate_target.pybind.h"
+#include "stim/gates/gates.h"
#include "stim/py/base.pybind.h"
#include "stim/str_util.h"
diff --git a/src/stim/circuit/circuit_instruction.pybind.h b/src/stim/circuit/circuit_instruction.pybind.h
index 59a7e4ea2..48873543b 100644
--- a/src/stim/circuit/circuit_instruction.pybind.h
+++ b/src/stim/circuit/circuit_instruction.pybind.h
@@ -18,8 +18,8 @@
#include
#include "stim/circuit/circuit_instruction.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/gate_target.h"
+#include "stim/gates/gates.h"
namespace stim_pybind {
diff --git a/src/stim/circuit/export_qasm.cc b/src/stim/circuit/export_qasm.cc
index a5a9ec8da..d18a2a19d 100644
--- a/src/stim/circuit/export_qasm.cc
+++ b/src/stim/circuit/export_qasm.cc
@@ -259,7 +259,9 @@ struct QasmExporter {
target = t1;
break;
default:
- throw std::invalid_argument("Not implemented: " + instruction.str());
+ throw std::invalid_argument(
+ "Not implemented in output_two_qubit_unitary_instruction_with_possible_feedback: " +
+ instruction.str());
}
out << "if (";
@@ -279,7 +281,9 @@ struct QasmExporter {
}
out << "sweep[" << control.value() << "]";
} else {
- throw std::invalid_argument("Not implemented: " + instruction.str());
+ throw std::invalid_argument(
+ "Not implemented in output_two_qubit_unitary_instruction_with_possible_feedback: " +
+ instruction.str());
}
out << ") {\n";
out << " " << basis << " q[" << target.qubit_value() << "];\n";
@@ -415,6 +419,7 @@ struct QasmExporter {
define_custom_single_qubit_gate(GateType::SQRT_Y_DAG, "sydg");
define_custom_decomposed_gate(GateType::CXSWAP, "cxswap");
+ define_custom_decomposed_gate(GateType::CZSWAP, "czswap");
define_custom_decomposed_gate(GateType::ISWAP, "iswap");
define_custom_decomposed_gate(GateType::ISWAP_DAG, "iswapdg");
define_custom_decomposed_gate(GateType::SQRT_XX, "sxx");
@@ -557,7 +562,7 @@ struct QasmExporter {
}
}
- throw std::invalid_argument("Not implemented: " + instruction.str());
+ throw std::invalid_argument("Not implemented in QasmExporter::output_instruction: " + instruction.str());
}
};
diff --git a/src/stim/circuit/export_qasm.test.cc b/src/stim/circuit/export_qasm.test.cc
index d8f9d86f4..d0f67e86e 100644
--- a/src/stim/circuit/export_qasm.test.cc
+++ b/src/stim/circuit/export_qasm.test.cc
@@ -261,6 +261,7 @@ gate hyz q0 { U(pi/2, pi/2, pi/2) q0; }
gate sy q0 { U(pi/2, 0, 0) q0; }
gate sydg q0 { U(pi/2, pi/2, pi/2) q0; }
gate cxswap q0, q1 { cx q1, q0; cx q0, q1; }
+gate czswap q0, q1 { h q0; cx q0, q1; cx q1, q0; h q1; }
gate iswap q0, q1 { h q0; cx q0, q1; cx q1, q0; h q1; s q1; s q0; }
gate iswapdg q0, q1 { s q0; s q0; s q0; s q1; s q1; s q1; h q1; cx q1, q0; cx q0, q1; h q0; }
gate sxx q0, q1 { h q0; cx q0, q1; h q1; s q0; s q1; h q0; h q1; }
@@ -317,6 +318,7 @@ iswap q[2], q[3];
iswapdg q[4], q[5];
swap q[6], q[7];
swapcx q[8], q[9];
+czswap q[10], q[11];
sxx q[0], q[1];
sxxdg q[2], q[3];
syy q[4], q[5];
@@ -419,6 +421,7 @@ gate hyz q0 { U(pi/2, pi/2, pi/2) q0; }
gate sy q0 { U(pi/2, 0, 0) q0; }
gate sydg q0 { U(pi/2, pi/2, pi/2) q0; }
gate cxswap q0, q1 { cx q1, q0; cx q0, q1; }
+gate czswap q0, q1 { h q0; cx q0, q1; cx q1, q0; h q1; }
gate iswap q0, q1 { h q0; cx q0, q1; cx q1, q0; h q1; s q1; s q0; }
gate iswapdg q0, q1 { s q0; s q0; s q0; s q1; s q1; s q1; h q1; cx q1, q0; cx q0, q1; h q0; }
gate sxx q0, q1 { h q0; cx q0, q1; h q1; s q0; s q1; h q0; h q1; }
@@ -462,6 +465,7 @@ iswap q[2], q[3];
iswapdg q[4], q[5];
swap q[6], q[7];
swapcx q[8], q[9];
+czswap q[10], q[11];
sxx q[0], q[1];
sxxdg q[2], q[3];
syy q[4], q[5];
diff --git a/src/stim/circuit/gate_data_table.h b/src/stim/circuit/gate_data_table.h
deleted file mode 100644
index e1d9a5a78..000000000
--- a/src/stim/circuit/gate_data_table.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef _STIM_CIRCUIT_GATE_DATA_TABLE_H
-#define _STIM_CIRCUIT_GATE_DATA_TABLE_H
-
-#include
-
-#include "gate_data.h"
-
-namespace stim {
-
-/// A class that maps each gate to a value.
-///
-/// The only real difference between this class and a raw array is that this class makes it
-/// harder to forget to define a value for a gate, and supports key-value style
-/// initialization at compile time.
-///
-/// The value for gate G is stored at: vtable.data[G.id]
-template
-struct GateVTable {
- std::array data;
-
- // Must construct explicitly, but can copy and move.
- GateVTable() = delete;
- GateVTable(const GateVTable &) = default;
- GateVTable(GateVTable &&) = default;
- GateVTable &operator=(const GateVTable &) = default;
- GateVTable &operator=(GateVTable &&) = default;
-
- // Construct from gate-value pairs.
- constexpr GateVTable(const std::array, NUM_DEFINED_GATES> &gate_data_pairs)
- : data({}) {
- for (const auto &[gate_id, value] : gate_data_pairs) {
- data[gate_id] = value;
- }
-#ifndef NDEBUG
- std::array seen{};
- for (const auto &[gate_id, value] : gate_data_pairs) {
- seen[(size_t)gate_id] = true;
- }
- for (const auto &gate : GATE_DATA.items) {
- if (!seen[(size_t)gate.id]) {
- throw std::invalid_argument(
- "Missing gate data! A value was not defined for '" + std::string(gate.name) + "'.");
- }
- }
-#endif
- }
-};
-
-} // namespace stim
-
-#endif
diff --git a/src/stim/circuit/gate_decomposition.h b/src/stim/circuit/gate_decomposition.h
index 5cf89ad20..5cbcd505c 100644
--- a/src/stim/circuit/gate_decomposition.h
+++ b/src/stim/circuit/gate_decomposition.h
@@ -17,9 +17,11 @@
#ifndef _STIM_GATE_DECOMPOSITION_H
#define _STIM_GATE_DECOMPOSITION_H
+#include
+
#include "stim/circuit/circuit_instruction.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/gate_target.h"
+#include "stim/gates/gates.h"
#include "stim/mem/simd_bits.h"
namespace stim {
diff --git a/src/stim/circuit/gate_target.h b/src/stim/circuit/gate_target.h
index c42b22766..fa964a386 100644
--- a/src/stim/circuit/gate_target.h
+++ b/src/stim/circuit/gate_target.h
@@ -19,7 +19,7 @@
#include
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
#include "stim/mem/span_ref.h"
namespace stim {
diff --git a/src/stim/cmd/command_help.cc b/src/stim/cmd/command_help.cc
index b05fbfbaa..909bb6965 100644
--- a/src/stim/cmd/command_help.cc
+++ b/src/stim/cmd/command_help.cc
@@ -31,9 +31,9 @@
#include "command_sample.h"
#include "command_sample_dem.h"
#include "stim/arg_parse.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/stabilizer_flow.h"
#include "stim/cmd/command_analyze_errors.h"
+#include "stim/gates/gates.h"
#include "stim/io/stim_data_formats.h"
#include "stim/stabilizers/tableau.h"
diff --git a/src/stim/diagram/circuit_timeline_helper.h b/src/stim/diagram/circuit_timeline_helper.h
index ae912057d..d23ef4e8c 100644
--- a/src/stim/diagram/circuit_timeline_helper.h
+++ b/src/stim/diagram/circuit_timeline_helper.h
@@ -17,6 +17,7 @@
#ifndef _STIM_DIAGRAM_TIMELINE_ASCII_DIAGRAM_CIRCUIT_WITH_RESOLVED_TIMELINE_INFO_H
#define _STIM_DIAGRAM_TIMELINE_ASCII_DIAGRAM_CIRCUIT_WITH_RESOLVED_TIMELINE_INFO_H
+#include
#include
#include "lattice_map.h"
diff --git a/src/stim/diagram/detector_slice/detector_slice_set.h b/src/stim/diagram/detector_slice/detector_slice_set.h
index 24101644b..41f3a85f0 100644
--- a/src/stim/diagram/detector_slice/detector_slice_set.h
+++ b/src/stim/diagram/detector_slice/detector_slice_set.h
@@ -17,6 +17,7 @@
#ifndef _STIM_DIAGRAM_DETECTOR_SLICE_DETECTOR_SLICE_SET_H
#define _STIM_DIAGRAM_DETECTOR_SLICE_DETECTOR_SLICE_SET_H
+#include
#include
#include "stim/circuit/circuit.h"
diff --git a/src/stim/diagram/diagram_util.cc b/src/stim/diagram/diagram_util.cc
index 8fee5212d..56d34851f 100644
--- a/src/stim/diagram/diagram_util.cc
+++ b/src/stim/diagram/diagram_util.cc
@@ -25,6 +25,8 @@ std::pair stim_draw_internal::two_qubit_gate_pieces(Ga
return {"Y", "Z"};
} else if (gate_type == GateType::CXSWAP) {
return {"ZSWAP", "XSWAP"};
+ } else if (gate_type == GateType::CZSWAP) {
+ return {"ZSWAP", "ZSWAP"};
} else if (gate_type == GateType::SWAPCX) {
return {"XSWAP", "ZSWAP"};
} else {
diff --git a/src/stim/diagram/gltf.h b/src/stim/diagram/gltf.h
index 1644b3bab..ccef9fc03 100644
--- a/src/stim/diagram/gltf.h
+++ b/src/stim/diagram/gltf.h
@@ -1,6 +1,7 @@
#ifndef _STIM_DRAW_3D_GLTF_H
#define _STIM_DRAW_3D_GLTF_H
+#include
#include
#include "base64.h"
diff --git a/src/stim/diagram/timeline/timeline_ascii_drawer.test.cc b/src/stim/diagram/timeline/timeline_ascii_drawer.test.cc
index 54c5b56bc..63dbd63fc 100644
--- a/src/stim/diagram/timeline/timeline_ascii_drawer.test.cc
+++ b/src/stim/diagram/timeline/timeline_ascii_drawer.test.cc
@@ -535,9 +535,9 @@ TEST(circuit_diagram_timeline_text, test_circuit_all_ops) {
| | | | |
q9: ----------------------------------------ZSWAP-----SQRT_ZZ-----Y-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------R----------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------
| |
-q10: --------------------------------------------------SQRT_ZZ_DAG-Y------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------
- | | | |
-q11: --------------------------------------------------SQRT_ZZ_DAG-@------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------
+q10: ----------------------------------------ZSWAP-----SQRT_ZZ_DAG-Y------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------
+ | | | | |
+q11: ----------------------------------------ZSWAP-----SQRT_ZZ_DAG-@------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------
| |
q12: --------------------------------------------------------------@------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------
| | |
diff --git a/src/stim/circuit/gate_data_annotations.cc b/src/stim/gates/gate_data_annotations.cc
similarity index 99%
rename from src/stim/circuit/gate_data_annotations.cc
rename to src/stim/gates/gate_data_annotations.cc
index 0a3e5a485..ec533521e 100644
--- a/src/stim/circuit/gate_data_annotations.cc
+++ b/src/stim/gates/gate_data_annotations.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_blocks.cc b/src/stim/gates/gate_data_blocks.cc
similarity index 98%
rename from src/stim/circuit/gate_data_blocks.cc
rename to src/stim/gates/gate_data_blocks.cc
index 7d47f564d..d48062c8f 100644
--- a/src/stim/circuit/gate_data_blocks.cc
+++ b/src/stim/gates/gate_data_blocks.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_collapsing.cc b/src/stim/gates/gate_data_collapsing.cc
similarity index 99%
rename from src/stim/circuit/gate_data_collapsing.cc
rename to src/stim/gates/gate_data_collapsing.cc
index 2dc2172da..8b5e04f2c 100644
--- a/src/stim/circuit/gate_data_collapsing.cc
+++ b/src/stim/gates/gate_data_collapsing.cc
@@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/circuit.h"
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_controlled.cc b/src/stim/gates/gate_data_controlled.cc
similarity index 99%
rename from src/stim/circuit/gate_data_controlled.cc
rename to src/stim/gates/gate_data_controlled.cc
index 4f5be99c3..49ba28f83 100644
--- a/src/stim/circuit/gate_data_controlled.cc
+++ b/src/stim/gates/gate_data_controlled.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_hada.cc b/src/stim/gates/gate_data_hada.cc
similarity index 98%
rename from src/stim/circuit/gate_data_hada.cc
rename to src/stim/gates/gate_data_hada.cc
index ac00b654f..419cc9b4d 100644
--- a/src/stim/circuit/gate_data_hada.cc
+++ b/src/stim/gates/gate_data_hada.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_heralded.cc b/src/stim/gates/gate_data_heralded.cc
similarity index 99%
rename from src/stim/circuit/gate_data_heralded.cc
rename to src/stim/gates/gate_data_heralded.cc
index a398d5dd2..45515bb58 100644
--- a/src/stim/circuit/gate_data_heralded.cc
+++ b/src/stim/gates/gate_data_heralded.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_noisy.cc b/src/stim/gates/gate_data_noisy.cc
similarity index 99%
rename from src/stim/circuit/gate_data_noisy.cc
rename to src/stim/gates/gate_data_noisy.cc
index 60daf2dc1..e58b370f4 100644
--- a/src/stim/circuit/gate_data_noisy.cc
+++ b/src/stim/gates/gate_data_noisy.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_pair_measure.cc b/src/stim/gates/gate_data_pair_measure.cc
similarity index 99%
rename from src/stim/circuit/gate_data_pair_measure.cc
rename to src/stim/gates/gate_data_pair_measure.cc
index 7ede6538c..55472c2a7 100644
--- a/src/stim/circuit/gate_data_pair_measure.cc
+++ b/src/stim/gates/gate_data_pair_measure.cc
@@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/circuit.h"
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_pauli.cc b/src/stim/gates/gate_data_pauli.cc
similarity index 98%
rename from src/stim/circuit/gate_data_pauli.cc
rename to src/stim/gates/gate_data_pauli.cc
index 73822d04c..a00bdb739 100644
--- a/src/stim/circuit/gate_data_pauli.cc
+++ b/src/stim/gates/gate_data_pauli.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_period_3.cc b/src/stim/gates/gate_data_period_3.cc
similarity index 97%
rename from src/stim/circuit/gate_data_period_3.cc
rename to src/stim/gates/gate_data_period_3.cc
index d212737dc..fc77b4668 100644
--- a/src/stim/circuit/gate_data_period_3.cc
+++ b/src/stim/gates/gate_data_period_3.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_period_4.cc b/src/stim/gates/gate_data_period_4.cc
similarity index 98%
rename from src/stim/circuit/gate_data_period_4.cc
rename to src/stim/gates/gate_data_period_4.cc
index 6f1299362..585246688 100644
--- a/src/stim/circuit/gate_data_period_4.cc
+++ b/src/stim/gates/gate_data_period_4.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_pp.cc b/src/stim/gates/gate_data_pp.cc
similarity index 99%
rename from src/stim/circuit/gate_data_pp.cc
rename to src/stim/gates/gate_data_pp.cc
index f3a60c25c..cab1c9935 100644
--- a/src/stim/circuit/gate_data_pp.cc
+++ b/src/stim/gates/gate_data_pp.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data_swaps.cc b/src/stim/gates/gate_data_swaps.cc
similarity index 84%
rename from src/stim/circuit/gate_data_swaps.cc
rename to src/stim/gates/gate_data_swaps.cc
index 26f03fe8f..5a47a811a 100644
--- a/src/stim/circuit/gate_data_swaps.cc
+++ b/src/stim/gates/gate_data_swaps.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include
-
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
using namespace stim;
@@ -177,4 +175,36 @@ CNOT 0 1
CNOT 1 0
)CIRCUIT",
});
+
+ add_gate(
+ failed,
+ Gate{
+ .name = "CZSWAP",
+ .id = GateType::CZSWAP,
+ .best_candidate_inverse_id = GateType::CZSWAP,
+ .arg_count = 0,
+ .flags = (GateFlags)(GATE_IS_UNITARY | GATE_TARGETS_PAIRS),
+ .category = "C_Two Qubit Clifford Gates",
+ .help = R"MARKDOWN(
+A combination CZ-and-SWAP gate.
+This gate is kak-equivalent to the iswap gate.
+
+Parens Arguments:
+
+ This instruction takes no parens arguments.
+
+Targets:
+
+ Qubit pairs to operate on.
+)MARKDOWN",
+ .unitary_data = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, -1}},
+ .flow_data = {"+ZX", "+IZ", "+XZ", "+ZI"},
+ .h_s_cx_m_r_decomposition = R"CIRCUIT(
+H 0
+CX 0 1
+CX 1 0
+H 1
+)CIRCUIT",
+ });
+ add_gate_alias(failed, "SWAPCZ", "CZSWAP");
}
diff --git a/src/stim/circuit/gate_data.cc b/src/stim/gates/gates.cc
similarity index 99%
rename from src/stim/circuit/gate_data.cc
rename to src/stim/gates/gates.cc
index d10fbcd52..089b753a8 100644
--- a/src/stim/circuit/gate_data.cc
+++ b/src/stim/gates/gates.cc
@@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
-
-#include
+#include "stim/gates/gates.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data.h b/src/stim/gates/gates.h
similarity index 98%
rename from src/stim/circuit/gate_data.h
rename to src/stim/gates/gates.h
index 721ddb32c..f6f9c577f 100644
--- a/src/stim/circuit/gate_data.h
+++ b/src/stim/gates/gates.h
@@ -14,20 +14,14 @@
* limitations under the License.
*/
-#ifndef _STIM_CIRCUIT_GATE_DATA_H
-#define _STIM_CIRCUIT_GATE_DATA_H
+#ifndef _STIM_GATES_GATE_DATA_H
+#define _STIM_GATES_GATE_DATA_H
-#include
#include
#include
#include
#include
-#include
-#include
#include
-#include
-#include
-#include
#include
#include "stim/mem/fixed_cap_vector.h"
@@ -82,7 +76,7 @@ constexpr inline uint16_t gate_name_to_hash(const char *c) {
return gate_name_to_hash(c, std::char_traits::length(c));
}
-constexpr const size_t NUM_DEFINED_GATES = 67;
+constexpr const size_t NUM_DEFINED_GATES = 68;
enum class GateType : uint8_t {
NOT_A_GATE = 0,
@@ -160,6 +154,7 @@ enum class GateType : uint8_t {
ISWAP,
CXSWAP,
SWAPCX,
+ CZSWAP,
ISWAP_DAG,
// Pair measurement gates
MXX,
diff --git a/src/stim/circuit/gate_data.perf.cc b/src/stim/gates/gates.perf.cc
similarity index 96%
rename from src/stim/circuit/gate_data.perf.cc
rename to src/stim/gates/gates.perf.cc
index a51e03566..27e411ec4 100644
--- a/src/stim/circuit/gate_data.perf.cc
+++ b/src/stim/gates/gates.perf.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
#include
diff --git a/src/stim/circuit/gate_data.pybind.cc b/src/stim/gates/gates.pybind.cc
similarity index 99%
rename from src/stim/circuit/gate_data.pybind.cc
rename to src/stim/gates/gates.pybind.cc
index 72e742202..a70b60de7 100644
--- a/src/stim/circuit/gate_data.pybind.cc
+++ b/src/stim/gates/gates.pybind.cc
@@ -12,13 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.pybind.h"
+#include "stim/gates/gates.h"
-#include "stim/circuit/gate_data.h"
#include "stim/circuit/stabilizer_flow.h"
+#include "stim/gates/gates.pybind.h"
#include "stim/py/base.pybind.h"
-#include "stim/stabilizers/pauli_string.pybind.h"
-#include "stim/stabilizers/tableau.pybind.h"
#include "stim/str_util.h"
using namespace stim;
diff --git a/src/stim/circuit/gate_data.pybind.h b/src/stim/gates/gates.pybind.h
similarity index 87%
rename from src/stim/circuit/gate_data.pybind.h
rename to src/stim/gates/gates.pybind.h
index 25fa37b96..021668bab 100644
--- a/src/stim/circuit/gate_data.pybind.h
+++ b/src/stim/gates/gates.pybind.h
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef _STIM_CIRCUIT_GATE_DATA_PYBIND_H
-#define _STIM_CIRCUIT_GATE_DATA_PYBIND_H
+#ifndef _STIM_GATES_GATE_DATA_PYBIND_H
+#define _STIM_GATES_GATE_DATA_PYBIND_H
#include
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
namespace stim_pybind {
diff --git a/src/stim/circuit/gate_data.test.cc b/src/stim/gates/gates.test.cc
similarity index 99%
rename from src/stim/circuit/gate_data.test.cc
rename to src/stim/gates/gates.test.cc
index 93afe26b0..cf5ed6e8a 100644
--- a/src/stim/circuit/gate_data.test.cc
+++ b/src/stim/gates/gates.test.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "stim/circuit/gate_data.h"
+#include "stim/gates/gates.h"
#include "gtest/gtest.h"
diff --git a/src/stim/circuit/gate_data_test.py b/src/stim/gates/gates_test.py
similarity index 100%
rename from src/stim/circuit/gate_data_test.py
rename to src/stim/gates/gates_test.py
diff --git a/src/stim/gen/gen_surface_code.cc b/src/stim/gen/gen_surface_code.cc
index 4ff30577a..91e27fa2d 100644
--- a/src/stim/gen/gen_surface_code.cc
+++ b/src/stim/gen/gen_surface_code.cc
@@ -2,6 +2,7 @@
#include
#include
+#include
#include