Skip to content

Commit

Permalink
Fix gcc13 build failures (#613)
Browse files Browse the repository at this point in the history
Fixes #580
  • Loading branch information
Strilanc authored Aug 20, 2023
1 parent 836a564 commit 2c5e6ee
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 89 deletions.
10 changes: 5 additions & 5 deletions src/stim/circuit/circuit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ template <typename SOURCE>
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)});
}
}

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/stim/circuit/circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#define _STIM_CIRCUIT_CIRCUIT_H

#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
Expand Down
2 changes: 2 additions & 0 deletions src/stim/circuit/circuit_instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef _STIM_CIRCUIT_INSTRUCTION_H
#define _STIM_CIRCUIT_INSTRUCTION_H

#include <cstdint>

#include "stim/circuit/gate_target.h"
#include "stim/mem/span_ref.h"

Expand Down
1 change: 1 addition & 0 deletions src/stim/circuit/gate_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <array>
#include <cassert>
#include <complex>
#include <cstdint>
#include <cstring>
#include <functional>
#include <initializer_list>
Expand Down
1 change: 1 addition & 0 deletions src/stim/diagram/ascii_diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef _STIM_DIAGRAM_TIMELINE_ASCII_DIAGRAM_ASCII_DIAGRAM_H
#define _STIM_DIAGRAM_TIMELINE_ASCII_DIAGRAM_ASCII_DIAGRAM_H

#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
Expand Down
1 change: 1 addition & 0 deletions src/stim/diagram/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef _STIM_DIAGRAM_BASE64_H
#define _STIM_DIAGRAM_BASE64_H

#include <cstdint>
#include <iostream>

namespace stim_draw_internal {
Expand Down
1 change: 1 addition & 0 deletions src/stim/diagram/gate_data_svg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef _STIM_DIAGRAM_GATE_DATA_SVG_H
#define _STIM_DIAGRAM_GATE_DATA_SVG_H

#include <cstdint>
#include <map>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions src/stim/mem/simd_word.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include <cstddef>
#include <cstdint>

#ifndef _STIM_MEM_SIMD_WORD_H
#define _STIM_MEM_SIMD_WORD_H
Expand Down
4 changes: 2 additions & 2 deletions src/stim/search/hyper/algo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using namespace stim;
using namespace stim::impl_search_hyper;

DetectorErrorModel backtrack_path(const std::map<SearchState, SearchState> &back_map, SearchState final_state) {
DetectorErrorModel backtrack_path(const std::map<SearchState, SearchState> &back_map, SearchState &&final_state) {
DetectorErrorModel out;
SearchState cur_state = std::move(final_state);
while (true) {
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions src/stim/search/hyper/algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef _STIM_SEARCH_HYPER_ALGO_H
#define _STIM_SEARCH_HYPER_ALGO_H

#include <cstdint>

#include "stim/dem/detector_error_model.h"

namespace stim {
Expand Down
8 changes: 4 additions & 4 deletions src/stim/simulators/frame_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
121 changes: 44 additions & 77 deletions src/stim/simulators/frame_simulator.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
using namespace stim;
using namespace stim_pybind;

std::optional<size_t> py_index_to_optional_size_t(const pybind11::object &index, size_t length, const char *val_name, const char *len_name) {
std::optional<size_t> 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 {};
}
Expand Down Expand Up @@ -54,11 +55,8 @@ pybind11::class_<FrameSimulator<MAX_BITWORD_WIDTH>> stim_pybind::pybind_frame_si

template <size_t W>
pybind11::object peek_pauli_flips(const FrameSimulator<W> &self, const pybind11::object &py_instance_index) {
std::optional<size_t> instance_index = py_index_to_optional_size_t(
py_instance_index,
self.batch_size,
"instance_index",
"batch_size");
std::optional<size_t> 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)));
Expand All @@ -72,16 +70,17 @@ pybind11::object peek_pauli_flips(const FrameSimulator<W> &self, const pybind11:
}

template <size_t W>
FrameSimulator<W> create_frame_simulator(size_t batch_size, bool disable_heisenberg_uncertainty, uint32_t num_qubits, const pybind11::object &seed) {
FrameSimulator<W> create_frame_simulator(
size_t batch_size, bool disable_heisenberg_uncertainty, uint32_t num_qubits, const pybind11::object &seed) {
FrameSimulator<W> 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,
Expand Down Expand Up @@ -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<size_t> instance_index = py_index_to_optional_size_t(
py_instance_index,
self.batch_size,
"instance_index",
"batch_size");
std::optional<size_t> instance_index =
py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size");

std::optional<size_t> record_index = py_index_to_optional_size_t(
py_record_index,
num_measurements,
"record_index",
"num_measurements");
std::optional<size_t> 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 <size_t W>
Expand All @@ -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<size_t> instance_index = py_index_to_optional_size_t(
py_instance_index,
self.batch_size,
"instance_index",
"batch_size");
std::optional<size_t> instance_index =
py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size");

std::optional<size_t> detector_index = py_index_to_optional_size_t(
py_detector_index,
num_detectors,
"detector_index",
"num_detectors");
std::optional<size_t> 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 <size_t W>
Expand All @@ -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<size_t> instance_index =
py_index_to_optional_size_t(py_instance_index, self.batch_size, "instance_index", "batch_size");

std::optional<size_t> instance_index = py_index_to_optional_size_t(
py_instance_index,
self.batch_size,
"instance_index",
"batch_size");

std::optional<size_t> observable_index = py_index_to_optional_size_t(
py_observable_index,
self.num_observables,
"observable_index",
"num_observables");
std::optional<size_t> 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(
Expand Down Expand Up @@ -302,8 +265,8 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def_property_readonly(
"batch_size",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
"batch_size",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
return self.batch_size;
},
clean_doc_string(R"DOC(
Expand All @@ -321,8 +284,8 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def_property_readonly(
"num_qubits",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
"num_qubits",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
return self.num_qubits;
},
clean_doc_string(R"DOC(
Expand All @@ -343,8 +306,8 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def_property_readonly(
"num_observables",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
"num_observables",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
return self.num_observables;
},
clean_doc_string(R"DOC(
Expand All @@ -365,8 +328,8 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def_property_readonly(
"num_measurements",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
"num_measurements",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
return self.m_record.stored;
},
clean_doc_string(R"DOC(
Expand All @@ -384,8 +347,8 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def_property_readonly(
"num_detectors",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
"num_detectors",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) -> size_t {
return self.det_record.stored;
},
clean_doc_string(R"DOC(
Expand All @@ -406,8 +369,11 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def(
"set_pauli_flip",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self, const pybind11::object &pauli, int64_t qubit_index, int64_t instance_index) {
"set_pauli_flip",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self,
const pybind11::object &pauli,
int64_t qubit_index,
int64_t instance_index) {
uint8_t p = 255;
try {
p = pybind11::cast<uint8_t>(pauli);
Expand Down Expand Up @@ -763,7 +729,8 @@ void stim_pybind::pybind_frame_simulator_methods(
const CircuitRepeatBlock &block = pybind11::cast<const CircuitRepeatBlock &>(obj);
self.safe_do_circuit(block.body, block.repeat_count);
} else {
throw std::invalid_argument("Don't know how to do a '" + pybind11::cast<std::string>(pybind11::repr(obj)) + "'.");
throw std::invalid_argument(
"Don't know how to do a '" + pybind11::cast<std::string>(pybind11::repr(obj)) + "'.");
}
},
pybind11::arg("obj"),
Expand Down

0 comments on commit 2c5e6ee

Please sign in to comment.