Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "raise from" in except blocks #415

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions circuit_knitting/cutting/cutting_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def _get_mapping_ids_by_partition(
if isinstance(inst.operation, SingleQubitQPDGate):
try:
decomp_id = int(inst.operation.label.split("_")[-1])
except (AttributeError, ValueError):
except (AttributeError, ValueError) as ex:
raise ValueError(
"SingleQubitQPDGate instances in input circuit(s) must have their "
'labels suffixed with "_<id>", where <id> is the index of the cut '
"relative to the other cuts in the circuit. For example, all "
"SingleQubitQPDGates belonging to the same cut, N, should have labels "
' formatted as "<your_label>_N". This allows SingleQubitQPDGates '
"belonging to the same cut to be sampled jointly."
)
) from ex
decomp_ids.add(decomp_id)
subcirc_qpd_gate_ids[label].append([i])
subcirc_map_ids[label].append(decomp_id)
Expand Down
8 changes: 4 additions & 4 deletions circuit_knitting/cutting/cutting_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def reconstruct_expectation_values(
num_qpd_bits = results_dict[label].metadata[
i * len(so.groups) + k
]["num_qpd_bits"]
except KeyError:
except KeyError as ex:
raise ValueError(
"The num_qpd_bits field must be set in each subexperiment "
"result metadata dictionary."
)
) from ex
else:
subsystem_expvals[k] += quasi_prob * _process_outcome(
num_qpd_bits,
Expand Down Expand Up @@ -159,10 +159,10 @@ def _process_outcome(
outcome = _outcome_to_int(outcome)
try:
qpd_outcomes = outcome & ((1 << num_qpd_bits) - 1)
except TypeError:
except TypeError as ex:
raise TypeError(
f"num_qpd_bits must be an integer, but a {type(num_qpd_bits)} was passed."
)
) from ex

meas_outcomes = outcome >> num_qpd_bits

Expand Down