Skip to content

Commit

Permalink
autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Mar 20, 2024
1 parent 3ddb521 commit a68d19e
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/stim/circuit/circuit.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include "stim/simulators/tableau_simulator.h"
#include "stim/simulators/transform_without_feedback.h"
#include "stim/stabilizers/flow.h"
#include "stim/util_top/circuit_vs_tableau.h"
#include "stim/util_top/circuit_to_detecting_regions.h"
#include "stim/util_top/circuit_vs_tableau.h"

using namespace stim;
using namespace stim_pybind;
Expand Down
29 changes: 9 additions & 20 deletions src/stim/simulators/frame_simulator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -685,34 +685,23 @@ void FrameSimulator<W>::do_Z_ERROR(const CircuitInstruction &target_data) {

template <size_t W>
void FrameSimulator<W>::do_MPP(const CircuitInstruction &target_data) {
decompose_mpp_operation(
target_data,
num_qubits,
[&](const CircuitInstruction &inst) {
safe_do_instruction(inst);
});
decompose_mpp_operation(target_data, num_qubits, [&](const CircuitInstruction &inst) {
safe_do_instruction(inst);
});
}

template <size_t W>
void FrameSimulator<W>::do_SPP(const CircuitInstruction &target_data) {
decompose_spp_or_spp_dag_operation(
target_data,
num_qubits,
false,
[&](const CircuitInstruction &inst) {
safe_do_instruction(inst);
});
decompose_spp_or_spp_dag_operation(target_data, num_qubits, false, [&](const CircuitInstruction &inst) {
safe_do_instruction(inst);
});
}

template <size_t W>
void FrameSimulator<W>::do_SPP_DAG(const CircuitInstruction &target_data) {
decompose_spp_or_spp_dag_operation(
target_data,
num_qubits,
false,
[&](const CircuitInstruction &inst) {
safe_do_instruction(inst);
});
decompose_spp_or_spp_dag_operation(target_data, num_qubits, false, [&](const CircuitInstruction &inst) {
safe_do_instruction(inst);
});
}

template <size_t W>
Expand Down
29 changes: 9 additions & 20 deletions src/stim/simulators/tableau_simulator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,23 @@ bool TableauSimulator<W>::is_deterministic_z(size_t target) const {

template <size_t W>
void TableauSimulator<W>::do_MPP(const CircuitInstruction &target_data) {
decompose_mpp_operation(
target_data,
inv_state.num_qubits,
[&](const CircuitInstruction &inst) {
do_gate(inst);
});
decompose_mpp_operation(target_data, inv_state.num_qubits, [&](const CircuitInstruction &inst) {
do_gate(inst);
});
}

template <size_t W>
void TableauSimulator<W>::do_SPP(const CircuitInstruction &target_data) {
decompose_spp_or_spp_dag_operation(
target_data,
inv_state.num_qubits,
false,
[&](const CircuitInstruction &inst) {
do_gate(inst);
});
decompose_spp_or_spp_dag_operation(target_data, inv_state.num_qubits, false, [&](const CircuitInstruction &inst) {
do_gate(inst);
});
}

template <size_t W>
void TableauSimulator<W>::do_SPP_DAG(const CircuitInstruction &target_data) {
decompose_spp_or_spp_dag_operation(
target_data,
inv_state.num_qubits,
false,
[&](const CircuitInstruction &inst) {
do_gate(inst);
});
decompose_spp_or_spp_dag_operation(target_data, inv_state.num_qubits, false, [&](const CircuitInstruction &inst) {
do_gate(inst);
});
}

template <size_t W>
Expand Down
7 changes: 3 additions & 4 deletions src/stim/simulators/tableau_simulator.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2071,10 +2071,9 @@ void stim_pybind::pybind_tableau_simulator_methods(
v.push_back(pybind11::cast<std::complex<float>>(obj));
}

self.inv_state =
circuit_to_tableau<MAX_BITWORD_WIDTH>(
stabilizer_state_vector_to_circuit(v, little_endian), false, false, false)
.inverse();
self.inv_state = circuit_to_tableau<MAX_BITWORD_WIDTH>(
stabilizer_state_vector_to_circuit(v, little_endian), false, false, false)
.inverse();
},
pybind11::arg("state_vector"),
pybind11::kw_only(),
Expand Down
4 changes: 2 additions & 2 deletions src/stim/stabilizers/tableau.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "stim/stabilizers/pauli_string.h"
#include "stim/stabilizers/tableau.h"
#include "stim/stabilizers/tableau_iter.h"
#include "stim/util_top/stabilizers_vs_amplitudes.h"
#include "stim/util_top/stabilizers_to_tableau.h"
#include "stim/util_top/circuit_vs_amplitudes.h"
#include "stim/util_top/stabilizers_to_tableau.h"
#include "stim/util_top/stabilizers_vs_amplitudes.h"

using namespace stim;
using namespace stim_pybind;
Expand Down
2 changes: 1 addition & 1 deletion src/stim/util_bot/error_decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ double depolarize2_probability_to_independent_per_channel_probability(double p);
double independent_per_channel_probability_to_depolarize1_probability(double p);
double independent_per_channel_probability_to_depolarize2_probability(double p);

}
} // namespace stim

#endif
2 changes: 1 addition & 1 deletion src/stim/util_bot/twiddle.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ inline uint8_t is_power_of_2(size_t value) {
inline size_t first_set_bit(size_t value, size_t min_result) {
size_t t = min_result;
value >>= min_result;
// assert(value);
// assert(value);
while (!(value & 1)) {
value >>= 1;
t += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/stim/util_top/circuit_inverse_unitary.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace stim {
/// Inverts the given circuit, as long as it only contains unitary operations.
Circuit circuit_inverse_unitary(const Circuit &unitary_circuit);

}
} // namespace stim

#endif
9 changes: 5 additions & 4 deletions src/stim/util_top/circuit_to_detecting_regions.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ TEST(circuit_to_detecting_regions, simple) {
)CIRCUIT");
auto actual = circuit_to_detecting_regions(circuit, {DemTarget::relative_detector_id(0)}, {0, 1}, false);
std::map<DemTarget, std::map<uint64_t, FlexPauliString>> expected{
{DemTarget::relative_detector_id(0), {
{0, FlexPauliString::from_text("X_")},
{1, FlexPauliString::from_text("XX")},
}},
{DemTarget::relative_detector_id(0),
{
{0, FlexPauliString::from_text("X_")},
{1, FlexPauliString::from_text("XX")},
}},
};
}
3 changes: 2 additions & 1 deletion src/stim/util_top/circuit_vs_amplitudes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ inline static size_t compute_occupation(const std::vector<std::complex<float>> &
return c;
}

Circuit stim::stabilizer_state_vector_to_circuit(const std::vector<std::complex<float>> &state_vector, bool little_endian) {
Circuit stim::stabilizer_state_vector_to_circuit(
const std::vector<std::complex<float>> &state_vector, bool little_endian) {
if (!is_power_of_2(state_vector.size())) {
std::stringstream ss;
ss << "Expected number of amplitudes to be a power of 2.";
Expand Down
3 changes: 1 addition & 2 deletions src/stim/util_top/circuit_vs_amplitudes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ Circuit stabilizer_state_vector_to_circuit(
///
/// Returns:
/// The state vector, using the requested endianness.
std::vector<std::complex<float>> circuit_to_output_state_vector(
const Circuit &circuit, bool little_endian);
std::vector<std::complex<float>> circuit_to_output_state_vector(const Circuit &circuit, bool little_endian);

} // namespace stim

Expand Down
6 changes: 2 additions & 4 deletions src/stim/util_top/circuit_vs_amplitudes.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ TEST(conversions, circuit_to_output_state_vector) {
circuit_to_output_state_vector(Circuit("H 0 1"), false),
(std::vector<std::complex<float>>{{0.5}, {0.5}, {0.5}, {0.5}}));
ASSERT_EQ(
circuit_to_output_state_vector(Circuit("X 1"), false),
(std::vector<std::complex<float>>{{0}, {1}, {0}, {0}}));
circuit_to_output_state_vector(Circuit("X 1"), false), (std::vector<std::complex<float>>{{0}, {1}, {0}, {0}}));
ASSERT_EQ(
circuit_to_output_state_vector(Circuit("X 1"), true),
(std::vector<std::complex<float>>{{0}, {0}, {1}, {0}}));
circuit_to_output_state_vector(Circuit("X 1"), true), (std::vector<std::complex<float>>{{0}, {0}, {1}, {0}}));
}
5 changes: 3 additions & 2 deletions src/stim/util_top/circuit_vs_tableau.inl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace stim {

template <size_t W>
Tableau<W> circuit_to_tableau(const Circuit &circuit, bool ignore_noise, bool ignore_measurement, bool ignore_reset, bool inverse) {
Tableau<W> circuit_to_tableau(
const Circuit &circuit, bool ignore_noise, bool ignore_measurement, bool ignore_reset, bool inverse) {
Tableau<W> result(circuit.count_qubits());
TableauSimulator<W> sim(std::mt19937_64(0), circuit.count_qubits());

Expand Down Expand Up @@ -111,7 +112,7 @@ Circuit tableau_to_circuit_mpp_method(const Tableau<W> &tableau, bool skip_sign)
for (size_t q = 0; q < n; q++) {
bool x = destabilizer.xs[q];
bool z = destabilizer.zs[q];
auto *out = targets_ptrs[x + z*2];
auto *out = targets_ptrs[x + z * 2];
if (out != nullptr) {
out->push_back(GateTarget::rec(-(int32_t)(n - k)));
out->push_back(GateTarget::qubit(q));
Expand Down
6 changes: 4 additions & 2 deletions src/stim/util_top/stabilizers_to_tableau.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stim/util_top/stabilizers_to_tableau.h"
#include "stim/util_top/circuit_vs_tableau.h"
#include "stim/util_top/stabilizers_to_tableau.h"

namespace stim {

Expand Down Expand Up @@ -156,7 +156,9 @@ Tableau<W> stabilizers_to_tableau(
}
}
}
throw std::invalid_argument("The given stabilizers commute but the solver failed in a way that suggests they anticommute. Please report this as a bug.");
throw std::invalid_argument(
"The given stabilizers commute but the solver failed in a way that suggests they anticommute. Please "
"report this as a bug.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stim/util_top/stabilizers_vs_amplitudes.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stim/util_top/circuit_inverse_unitary.h"
#include "stim/util_bot/twiddle.h"
#include "stim/util_top/circuit_inverse_unitary.h"
#include "stim/util_top/circuit_vs_amplitudes.h"
#include "stim/util_top/circuit_vs_tableau.h"

Expand Down

0 comments on commit a68d19e

Please sign in to comment.