@@ -52,12 +52,10 @@ common::Error::Error(const stim::DemInstruction& error) {
5252}
5353
5454std::string common::Error::str () {
55- return " Error{cost=" + std::to_string (likelihood_cost) +
56- " , symptom=" + symptom.str () + " }" ;
55+ return " Error{cost=" + std::to_string (likelihood_cost) + " , symptom=" + symptom.str () + " }" ;
5756}
5857
59- std::vector<stim::DemTarget> common::Symptom::as_dem_instruction_targets ()
60- const {
58+ std::vector<stim::DemTarget> common::Symptom::as_dem_instruction_targets () const {
6159 std::vector<stim::DemTarget> targets;
6260 for (int d : detectors) {
6361 targets.push_back (stim::DemTarget::relative_detector_id (d));
@@ -72,8 +70,7 @@ std::vector<stim::DemTarget> common::Symptom::as_dem_instruction_targets()
7270 return targets;
7371}
7472
75- stim::DetectorErrorModel common::merge_identical_errors (
76- const stim::DetectorErrorModel& dem) {
73+ stim::DetectorErrorModel common::merge_identical_errors (const stim::DetectorErrorModel& dem) {
7774 stim::DetectorErrorModel out_dem;
7875
7976 // Map to track the distinct symptoms
@@ -89,11 +86,9 @@ stim::DetectorErrorModel common::merge_identical_errors(
8986 // Merge with existing error with the same symptom (if applicable)
9087 if (errors_by_symptom.find (error.symptom ) != errors_by_symptom.end ()) {
9188 double p0 = errors_by_symptom[error.symptom ].probability ;
92- error.probability =
93- p0 * (1 - error.probability ) + (1 - p0) * error.probability ;
89+ error.probability = p0 * (1 - error.probability ) + (1 - p0) * error.probability ;
9490 }
95- error.likelihood_cost =
96- -1 * std::log (error.probability / (1 - error.probability ));
91+ error.likelihood_cost = -1 * std::log (error.probability / (1 - error.probability ));
9792 errors_by_symptom[error.symptom ] = error;
9893 break ;
9994 }
@@ -106,9 +101,9 @@ stim::DetectorErrorModel common::merge_identical_errors(
106101 }
107102 }
108103 for (const auto & it : errors_by_symptom) {
109- out_dem.append_error_instruction (
110- it. second . probability , it.second .symptom .as_dem_instruction_targets (),
111- /* tag=*/ " " );
104+ out_dem.append_error_instruction (it. second . probability ,
105+ it.second .symptom .as_dem_instruction_targets (),
106+ /* tag=*/ " " );
112107 }
113108 return out_dem;
114109}
@@ -136,19 +131,17 @@ stim::DetectorErrorModel common::remove_zero_probability_errors(
136131 return out_dem;
137132}
138133
139- stim::DetectorErrorModel common::dem_from_counts (
140- stim::DetectorErrorModel& orig_dem, const std::vector<size_t >& error_counts,
141- size_t num_shots) {
134+ stim::DetectorErrorModel common::dem_from_counts (stim::DetectorErrorModel& orig_dem,
135+ const std::vector<size_t >& error_counts,
136+ size_t num_shots) {
142137 if (orig_dem.count_errors () != error_counts.size ()) {
143138 throw std::invalid_argument (
144139 " Error hits array must be the same size as the number of errors in the "
145140 " original DEM." );
146141 }
147142
148- for (const stim::DemInstruction& instruction :
149- orig_dem.flattened ().instructions ) {
150- if (instruction.type == stim::DemInstructionType::DEM_ERROR &&
151- instruction.arg_data [0 ] == 0 ) {
143+ for (const stim::DemInstruction& instruction : orig_dem.flattened ().instructions ) {
144+ if (instruction.type == stim::DemInstructionType::DEM_ERROR && instruction.arg_data [0 ] == 0 ) {
152145 throw std::invalid_argument (
153146 " dem_from_counts requires DEMs without zero-probability errors. Use"
154147 " remove_zero_probability_errors first." );
@@ -157,17 +150,14 @@ stim::DetectorErrorModel common::dem_from_counts(
157150
158151 stim::DetectorErrorModel out_dem;
159152 size_t ei = 0 ;
160- for (const stim::DemInstruction& instruction :
161- orig_dem.flattened ().instructions ) {
153+ for (const stim::DemInstruction& instruction : orig_dem.flattened ().instructions ) {
162154 switch (instruction.type ) {
163155 case stim::DemInstructionType::DEM_SHIFT_DETECTORS:
164156 assert (false && " unreachable" );
165157 break ;
166158 case stim::DemInstructionType::DEM_ERROR: {
167- double est_probability =
168- double (error_counts.at (ei)) / double (num_shots);
169- out_dem.append_error_instruction (est_probability,
170- instruction.target_data , /* tag=*/ " " );
159+ double est_probability = double (error_counts.at (ei)) / double (num_shots);
160+ out_dem.append_error_instruction (est_probability, instruction.target_data , /* tag=*/ " " );
171161 ++ei;
172162 break ;
173163 }
0 commit comments