Skip to content

Commit

Permalink
Provide a workaround to #422, Sampler failing when no measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Sep 29, 2023
1 parent 54ca9c6 commit 9443b8a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions circuit_knitting/cutting/cutting_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,21 @@ def _append_measurement_circuit(
if not inplace:
qc = qc.copy()

# If the circuit has no measurements, the Sampler will fail. So, we
# measure one qubit as a temporary workaround to
# https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/issues/422
pauli_indices = cog.pauli_indices
if not pauli_indices:
pauli_indices = [0]

# Append the appropriate measurements to qc
obs_creg = ClassicalRegister(len(cog.pauli_indices), name="observable_measurements")
obs_creg = ClassicalRegister(len(pauli_indices), name="observable_measurements")
qc.add_register(obs_creg)
# Implement the necessary basis rotations and measurements, as
# in BackendEstimator._measurement_circuit().
genobs_x = cog.general_observable.x
genobs_z = cog.general_observable.z
for clbit, subqubit in enumerate(cog.pauli_indices):
for clbit, subqubit in enumerate(pauli_indices):
# subqubit is the index of the qubit in the subsystem.
# actual_qubit is its index in the system of interest (if different).
actual_qubit = qubit_locations[subqubit]
Expand Down

0 comments on commit 9443b8a

Please sign in to comment.