From 2c5e6eeb16256363d2e18b0cfc2a64a39d775579 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Sun, 20 Aug 2023 01:43:09 -0700 Subject: [PATCH] Fix gcc13 build failures (#613) Fixes https://github.com/quantumlib/Stim/issues/580 --- src/stim/circuit/circuit.cc | 10 +- src/stim/circuit/circuit.h | 2 +- src/stim/circuit/circuit_instruction.h | 2 + src/stim/circuit/gate_data.h | 1 + src/stim/diagram/ascii_diagram.h | 1 + src/stim/diagram/base64.h | 1 + src/stim/diagram/gate_data_svg.h | 1 + src/stim/mem/simd_word.h | 1 + src/stim/search/hyper/algo.cc | 4 +- src/stim/search/hyper/algo.h | 2 + src/stim/simulators/frame_simulator.h | 8 +- src/stim/simulators/frame_simulator.pybind.cc | 121 +++++++----------- 12 files changed, 65 insertions(+), 89 deletions(-) diff --git a/src/stim/circuit/circuit.cc b/src/stim/circuit/circuit.cc index d88454eee..bba80044f 100644 --- a/src/stim/circuit/circuit.cc +++ b/src/stim/circuit/circuit.cc @@ -304,8 +304,8 @@ template inline void read_result_targets64_into(int &c, SOURCE read_char, Circuit &circuit) { while (read_until_next_line_arg(c, read_char)) { uint64_t q = read_uint63_t(c, read_char); - circuit.target_buf.append_tail({(uint32_t)(q & 0xFFFFFFFFULL)}); - circuit.target_buf.append_tail({(uint32_t)(q >> 32)}); + circuit.target_buf.append_tail(GateTarget{(uint32_t)(q & 0xFFFFFFFFULL)}); + circuit.target_buf.append_tail(GateTarget{(uint32_t)(q >> 32)}); } } @@ -382,9 +382,9 @@ void circuit_read_operations(Circuit &circuit, SOURCE read_char, READ_CONDITION // Rewrite target data to reference the parsed block. circuit.target_buf.ensure_available(3); - circuit.target_buf.append_tail({block_id}); - circuit.target_buf.append_tail({rep_count_low}); - circuit.target_buf.append_tail({rep_count_high}); + circuit.target_buf.append_tail(GateTarget{block_id}); + circuit.target_buf.append_tail(GateTarget{rep_count_low}); + circuit.target_buf.append_tail(GateTarget{rep_count_high}); new_op.targets = circuit.target_buf.commit_tail(); } diff --git a/src/stim/circuit/circuit.h b/src/stim/circuit/circuit.h index 9f14f7b39..a69202b9f 100644 --- a/src/stim/circuit/circuit.h +++ b/src/stim/circuit/circuit.h @@ -18,8 +18,8 @@ #define _STIM_CIRCUIT_CIRCUIT_H #include +#include #include -#include #include #include #include diff --git a/src/stim/circuit/circuit_instruction.h b/src/stim/circuit/circuit_instruction.h index c231de5c8..9cc510ed3 100644 --- a/src/stim/circuit/circuit_instruction.h +++ b/src/stim/circuit/circuit_instruction.h @@ -17,6 +17,8 @@ #ifndef _STIM_CIRCUIT_INSTRUCTION_H #define _STIM_CIRCUIT_INSTRUCTION_H +#include + #include "stim/circuit/gate_target.h" #include "stim/mem/span_ref.h" diff --git a/src/stim/circuit/gate_data.h b/src/stim/circuit/gate_data.h index df66f11bd..a525bf05c 100644 --- a/src/stim/circuit/gate_data.h +++ b/src/stim/circuit/gate_data.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/src/stim/diagram/ascii_diagram.h b/src/stim/diagram/ascii_diagram.h index 7a6cb3d4f..e30dbd1bc 100644 --- a/src/stim/diagram/ascii_diagram.h +++ b/src/stim/diagram/ascii_diagram.h @@ -17,6 +17,7 @@ #ifndef _STIM_DIAGRAM_TIMELINE_ASCII_DIAGRAM_ASCII_DIAGRAM_H #define _STIM_DIAGRAM_TIMELINE_ASCII_DIAGRAM_ASCII_DIAGRAM_H +#include #include #include #include diff --git a/src/stim/diagram/base64.h b/src/stim/diagram/base64.h index d1eee9e14..24d1d96a8 100644 --- a/src/stim/diagram/base64.h +++ b/src/stim/diagram/base64.h @@ -17,6 +17,7 @@ #ifndef _STIM_DIAGRAM_BASE64_H #define _STIM_DIAGRAM_BASE64_H +#include #include namespace stim_draw_internal { diff --git a/src/stim/diagram/gate_data_svg.h b/src/stim/diagram/gate_data_svg.h index 1399e7f7e..dbe6f8338 100644 --- a/src/stim/diagram/gate_data_svg.h +++ b/src/stim/diagram/gate_data_svg.h @@ -17,6 +17,7 @@ #ifndef _STIM_DIAGRAM_GATE_DATA_SVG_H #define _STIM_DIAGRAM_GATE_DATA_SVG_H +#include #include #include diff --git a/src/stim/mem/simd_word.h b/src/stim/mem/simd_word.h index 10b095187..3d2e59476 100644 --- a/src/stim/mem/simd_word.h +++ b/src/stim/mem/simd_word.h @@ -15,6 +15,7 @@ */ #include +#include #ifndef _STIM_MEM_SIMD_WORD_H #define _STIM_MEM_SIMD_WORD_H diff --git a/src/stim/search/hyper/algo.cc b/src/stim/search/hyper/algo.cc index da1c00b27..0c216e918 100644 --- a/src/stim/search/hyper/algo.cc +++ b/src/stim/search/hyper/algo.cc @@ -27,7 +27,7 @@ using namespace stim; using namespace stim::impl_search_hyper; -DetectorErrorModel backtrack_path(const std::map &back_map, SearchState final_state) { +DetectorErrorModel backtrack_path(const std::map &back_map, SearchState &&final_state) { DetectorErrorModel out; SearchState cur_state = std::move(final_state); while (true) { @@ -98,7 +98,7 @@ DetectorErrorModel stim::find_undetectable_logical_error( } if (next.dets.empty()) { assert(next.obs_mask.not_zero()); // Otherwise, it would have already been in back_map. - return backtrack_path(back_map, next); + return backtrack_path(back_map, std::move(next)); } queue.push(std::move(next)); } diff --git a/src/stim/search/hyper/algo.h b/src/stim/search/hyper/algo.h index b96baeba8..29b6a45c1 100644 --- a/src/stim/search/hyper/algo.h +++ b/src/stim/search/hyper/algo.h @@ -17,6 +17,8 @@ #ifndef _STIM_SEARCH_HYPER_ALGO_H #define _STIM_SEARCH_HYPER_ALGO_H +#include + #include "stim/dem/detector_error_model.h" namespace stim { diff --git a/src/stim/simulators/frame_simulator.h b/src/stim/simulators/frame_simulator.h index 5b60396e0..f975bc198 100644 --- a/src/stim/simulators/frame_simulator.h +++ b/src/stim/simulators/frame_simulator.h @@ -28,10 +28,10 @@ namespace stim { enum FrameSimulatorMode { STORE_MEASUREMENTS_TO_MEMORY, // all measurements stored, detections not stored - STREAM_MEASUREMENTS_TO_DISK, // measurements stored up to lookback, detections not stored - STORE_DETECTIONS_TO_MEMORY, // measurements stored up to lookback, all detections stored - STREAM_DETECTIONS_TO_DISK, // measurements stored up to lookback, detections stored until write - STORE_EVERYTHING_TO_MEMORY, // all measurements stored and all detections stored + STREAM_MEASUREMENTS_TO_DISK, // measurements stored up to lookback, detections not stored + STORE_DETECTIONS_TO_MEMORY, // measurements stored up to lookback, all detections stored + STREAM_DETECTIONS_TO_DISK, // measurements stored up to lookback, detections stored until write + STORE_EVERYTHING_TO_MEMORY, // all measurements stored and all detections stored }; /// A Pauli Frame simulator that computes many samples simultaneously. diff --git a/src/stim/simulators/frame_simulator.pybind.cc b/src/stim/simulators/frame_simulator.pybind.cc index d2717986f..f4c18e70c 100644 --- a/src/stim/simulators/frame_simulator.pybind.cc +++ b/src/stim/simulators/frame_simulator.pybind.cc @@ -10,7 +10,8 @@ using namespace stim; using namespace stim_pybind; -std::optional py_index_to_optional_size_t(const pybind11::object &index, size_t length, const char *val_name, const char *len_name) { +std::optional py_index_to_optional_size_t( + const pybind11::object &index, size_t length, const char *val_name, const char *len_name) { if (index.is_none()) { return {}; } @@ -54,11 +55,8 @@ pybind11::class_> stim_pybind::pybind_frame_si template pybind11::object peek_pauli_flips(const FrameSimulator &self, const pybind11::object &py_instance_index) { - std::optional instance_index = py_index_to_optional_size_t( - py_instance_index, - self.batch_size, - "instance_index", - "batch_size"); + std::optional instance_index = + py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size"); if (instance_index.has_value()) { return pybind11::cast(PyPauliString(self.get_frame(*instance_index))); @@ -72,16 +70,17 @@ pybind11::object peek_pauli_flips(const FrameSimulator &self, const pybind11: } template -FrameSimulator create_frame_simulator(size_t batch_size, bool disable_heisenberg_uncertainty, uint32_t num_qubits, const pybind11::object &seed) { +FrameSimulator create_frame_simulator( + size_t batch_size, bool disable_heisenberg_uncertainty, uint32_t num_qubits, const pybind11::object &seed) { FrameSimulator result( CircuitStats{ - 0, // num_detectors - 0, // num_observables - 0, // num_measurements + 0, // num_detectors + 0, // num_observables + 0, // num_measurements num_qubits, - 0, // num_ticks - (uint32_t)(1 << 24), // max_lookback - 0, // num_sweep_bits + 0, // num_ticks + (uint32_t)(1 << 24), // max_lookback + 0, // num_sweep_bits }, FrameSimulatorMode::STORE_EVERYTHING_TO_MEMORY, batch_size, @@ -124,28 +123,16 @@ pybind11::object get_measurement_flips( const pybind11::object &py_record_index, const pybind11::object &py_instance_index, bool bit_packed) { - size_t num_measurements = self.m_record.stored; - std::optional instance_index = py_index_to_optional_size_t( - py_instance_index, - self.batch_size, - "instance_index", - "batch_size"); + std::optional instance_index = + py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size"); - std::optional record_index = py_index_to_optional_size_t( - py_record_index, - num_measurements, - "record_index", - "num_measurements"); + std::optional record_index = + py_index_to_optional_size_t(py_record_index, num_measurements, "record_index", "num_measurements"); return sliced_table_to_numpy( - self.m_record.storage, - num_measurements, - self.batch_size, - record_index, - instance_index, - bit_packed); + self.m_record.storage, num_measurements, self.batch_size, record_index, instance_index, bit_packed); } template @@ -154,28 +141,16 @@ pybind11::object get_detector_flips( const pybind11::object &py_detector_index, const pybind11::object &py_instance_index, bool bit_packed) { - size_t num_detectors = self.det_record.stored; - std::optional instance_index = py_index_to_optional_size_t( - py_instance_index, - self.batch_size, - "instance_index", - "batch_size"); + std::optional instance_index = + py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size"); - std::optional detector_index = py_index_to_optional_size_t( - py_detector_index, - num_detectors, - "detector_index", - "num_detectors"); + std::optional detector_index = + py_index_to_optional_size_t(py_detector_index, num_detectors, "detector_index", "num_detectors"); return sliced_table_to_numpy( - self.det_record.storage, - num_detectors, - self.batch_size, - detector_index, - instance_index, - bit_packed); + self.det_record.storage, num_detectors, self.batch_size, detector_index, instance_index, bit_packed); } template @@ -184,26 +159,14 @@ pybind11::object get_obs_flips( const pybind11::object &py_observable_index, const pybind11::object &py_instance_index, bool bit_packed) { + std::optional instance_index = + py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size"); - std::optional instance_index = py_index_to_optional_size_t( - py_instance_index, - self.batch_size, - "instance_index", - "batch_size"); - - std::optional observable_index = py_index_to_optional_size_t( - py_observable_index, - self.num_observables, - "observable_index", - "num_observables"); + std::optional observable_index = + py_index_to_optional_size_t(py_observable_index, self.num_observables, "observable_index", "num_observables"); return sliced_table_to_numpy( - self.obs_record, - self.num_observables, - self.batch_size, - observable_index, - instance_index, - bit_packed); + self.obs_record, self.num_observables, self.batch_size, observable_index, instance_index, bit_packed); } void stim_pybind::pybind_frame_simulator_methods( @@ -302,8 +265,8 @@ void stim_pybind::pybind_frame_simulator_methods( .data()); c.def_property_readonly( - "batch_size", - [](FrameSimulator &self) -> size_t { + "batch_size", + [](FrameSimulator &self) -> size_t { return self.batch_size; }, clean_doc_string(R"DOC( @@ -321,8 +284,8 @@ void stim_pybind::pybind_frame_simulator_methods( .data()); c.def_property_readonly( - "num_qubits", - [](FrameSimulator &self) -> size_t { + "num_qubits", + [](FrameSimulator &self) -> size_t { return self.num_qubits; }, clean_doc_string(R"DOC( @@ -343,8 +306,8 @@ void stim_pybind::pybind_frame_simulator_methods( .data()); c.def_property_readonly( - "num_observables", - [](FrameSimulator &self) -> size_t { + "num_observables", + [](FrameSimulator &self) -> size_t { return self.num_observables; }, clean_doc_string(R"DOC( @@ -365,8 +328,8 @@ void stim_pybind::pybind_frame_simulator_methods( .data()); c.def_property_readonly( - "num_measurements", - [](FrameSimulator &self) -> size_t { + "num_measurements", + [](FrameSimulator &self) -> size_t { return self.m_record.stored; }, clean_doc_string(R"DOC( @@ -384,8 +347,8 @@ void stim_pybind::pybind_frame_simulator_methods( .data()); c.def_property_readonly( - "num_detectors", - [](FrameSimulator &self) -> size_t { + "num_detectors", + [](FrameSimulator &self) -> size_t { return self.det_record.stored; }, clean_doc_string(R"DOC( @@ -406,8 +369,11 @@ void stim_pybind::pybind_frame_simulator_methods( .data()); c.def( - "set_pauli_flip", - [](FrameSimulator &self, const pybind11::object &pauli, int64_t qubit_index, int64_t instance_index) { + "set_pauli_flip", + [](FrameSimulator &self, + const pybind11::object &pauli, + int64_t qubit_index, + int64_t instance_index) { uint8_t p = 255; try { p = pybind11::cast(pauli); @@ -763,7 +729,8 @@ void stim_pybind::pybind_frame_simulator_methods( const CircuitRepeatBlock &block = pybind11::cast(obj); self.safe_do_circuit(block.body, block.repeat_count); } else { - throw std::invalid_argument("Don't know how to do a '" + pybind11::cast(pybind11::repr(obj)) + "'."); + throw std::invalid_argument( + "Don't know how to do a '" + pybind11::cast(pybind11::repr(obj)) + "'."); } }, pybind11::arg("obj"),