@@ -193,10 +193,6 @@ def __init__(
193193 self .state : QuantumCircuit = QuantumCircuit ()
194194
195195 self .error_occurred = False
196- self ._gates_in_basis_check = GatesInBasis (basis_gates = self .device .operation_names )
197- self ._check_map = CheckMap (coupling_map = self .device .build_coupling_map ())
198- self ._last_qc_id : int | None = None
199- self ._last_native_mapped : tuple [bool , bool ] | None = None
200196
201197 def _apply_and_update (self , action : int ) -> QuantumCircuit | None :
202198 """Apply an action, normalize the circuit, and update internal state."""
@@ -319,7 +315,15 @@ def calculate_reward(self, qc: QuantumCircuit | None = None, mode: str = "auto")
319315 elif mode == "approx" :
320316 kind = "approx"
321317 else : # "auto"
322- kind = "exact" if self ._is_native_and_mapped (qc ) else "approx"
318+ check_nat_gates = GatesInBasis (basis_gates = self .device .operation_names )
319+ check_nat_gates (qc )
320+ only_native = bool (check_nat_gates .property_set ["all_gates_in_basis" ])
321+
322+ check_mapping = CheckMap (coupling_map = self .device .build_coupling_map ())
323+ check_mapping (qc )
324+ mapped = bool (check_mapping .property_set ["is_swap_mapped" ])
325+
326+ kind = "exact" if (only_native and mapped ) else "approx"
323327
324328 if kind == "exact" :
325329 if self .reward_function == "expected_fidelity" :
@@ -701,21 +705,3 @@ def _get_props(name: str, qargs: tuple[int, ...]) -> InstructionProperties | Non
701705
702706 self ._tbar = float (np .median (tmins )) if tmins else None
703707 self ._dev_avgs_cached = True
704-
705- def _native_and_mapped (self , qc : QuantumCircuit ) -> tuple [bool , bool ]:
706- qc_id = id (qc )
707- if qc_id == self ._last_qc_id and self ._last_native_mapped is not None :
708- return self ._last_native_mapped
709-
710- self ._gates_in_basis_check (qc )
711- only_native = bool (self ._gates_in_basis_check .property_set ["all_gates_in_basis" ])
712- self ._check_map (qc )
713- mapped = bool (self ._check_map .property_set ["is_swap_mapped" ])
714-
715- self ._last_qc_id = qc_id
716- self ._last_native_mapped = (only_native , mapped )
717- return only_native , mapped
718-
719- def _is_native_and_mapped (self , qc : QuantumCircuit ) -> bool :
720- only_native , mapped = self ._native_and_mapped (qc )
721- return only_native and mapped
0 commit comments