Skip to content

Commit

Permalink
Refactor (#11198)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkoham authored Nov 6, 2023
1 parent 179d9ab commit fd8a7df
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions qiskit/primitives/backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,18 @@ def _transpile(self):
# 1. transpile a common circuit
if self._skip_transpilation:
transpiled_circuit = common_circuit.copy()
perm_pattern = list(range(common_circuit.num_qubits))
final_index_layout = list(range(common_circuit.num_qubits))
else:
transpiled_circuit = transpile(
common_circuit, self.backend, **self.transpile_options.__dict__
)
if transpiled_circuit.layout is not None:
layout = transpiled_circuit.layout
virtual_bit_map = layout.initial_layout.get_virtual_bits()
perm_pattern = [virtual_bit_map[v] for v in common_circuit.qubits]
if layout.final_layout is not None:
final_mapping = dict(
enumerate(layout.final_layout.get_virtual_bits().values())
)
perm_pattern = [final_mapping[i] for i in perm_pattern]
final_index_layout = transpiled_circuit.layout.final_index_layout()
else:
perm_pattern = list(range(transpiled_circuit.num_qubits))
final_index_layout = list(range(transpiled_circuit.num_qubits))

# 2. transpile diff circuits
passmanager = _passmanager_for_measurement_circuits(perm_pattern, self.backend)
passmanager = _passmanager_for_measurement_circuits(final_index_layout, self.backend)
diff_circuits = passmanager.run(diff_circuits)
# 3. combine
transpiled_circuits = []
Expand Down

0 comments on commit fd8a7df

Please sign in to comment.