diff --git a/crates/accelerate/src/target_transpiler/mod.rs b/crates/accelerate/src/target_transpiler/mod.rs index ffb77514391..46117f3cbbf 100644 --- a/crates/accelerate/src/target_transpiler/mod.rs +++ b/crates/accelerate/src/target_transpiler/mod.rs @@ -907,21 +907,21 @@ impl Target { } /// Performs caching of python side dict objects for better access performance. - fn __getitem__(&mut self, key: &Bound) -> PyResult { + fn __getitem__(mut slf: PyRefMut, key: &Bound) -> PyResult { let py: Python = key.py(); let Ok(key) = key.extract::() else {return Err(PyKeyError::new_err( "Invalid Key Type for Target." ));}; - if let Some(val) = self._py_gate_map_cache.get(key.as_str()) { + if let Some(val) = slf._py_gate_map_cache.get(key.as_str()) { Ok(val.as_any().clone_ref(py)) - } else if let Some(val) = self.gate_map.get(key.as_str()) { + } else if let Some(val) = slf.gate_map.get(key.as_str()) { let new_py: Vec<(Option>, PyObject)> = val .clone() .into_iter() .map(|(key, val)| (key.map(|key| PyTuple::new_bound(py, key)), val.into_py(py))) .collect(); let dict_py = new_py.into_py_dict_bound(py).unbind(); - self._py_gate_map_cache.insert(key, dict_py.clone_ref(py)); + slf._py_gate_map_cache.insert(key, dict_py.clone_ref(py)); Ok(dict_py.into()) } else { Err(PyKeyError::new_err(format!( diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 6374a0b0b60..8e600ca0d36 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -489,7 +489,11 @@ def _add_noisy_instruction_to_target( ) for qubit in qargs: if qubit < self.num_qubits: - self._target[instruction.name][(qubit,)].calibration = calibration_entry + inst_prop = self._target[instruction.name][(qubit,)] + inst_prop.calibration = calibration_entry + self._target.update_instruction_properties( + instruction.name, (qubit,), inst_prop + ) def run(self, run_input, **options): """Run on the backend using a simulator. diff --git a/test/python/transpiler/test_pulse_gate_pass.py b/test/python/transpiler/test_pulse_gate_pass.py index 07d6172264d..a870bdab7a2 100644 --- a/test/python/transpiler/test_pulse_gate_pass.py +++ b/test/python/transpiler/test_pulse_gate_pass.py @@ -143,8 +143,12 @@ def test_transpile_with_custom_basis_gate_in_target(self): seed=42, ).target - target["sx"][(0,)].calibration = self.custom_sx_q0 - target["sx"][(1,)].calibration = self.custom_sx_q1 + inst_prop_0 = target["sx"][(0,)] + inst_prop_0.calibration = self.custom_sx_q0 + target.update_instruction_properties("sx", (0,), inst_prop_0) + inst_prop_1 = target["sx"][(1,)] + inst_prop_1.calibration = self.custom_sx_q1 + target.update_instruction_properties("sx", (1,), inst_prop_1) qc = circuit.QuantumCircuit(2) qc.sx(0)