|
| 1 | +// This code is part of Qiskit. |
| 2 | +// |
| 3 | +// (C) Copyright IBM 2024 |
| 4 | +// |
| 5 | +// This code is licensed under the Apache License, Version 2.0. You may |
| 6 | +// obtain a copy of this license in the LICENSE.txt file in the root directory |
| 7 | +// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. |
| 8 | +// |
| 9 | +// Any modifications or derivative works of this code must retain this |
| 10 | +// copyright notice, and modified files need to carry a notice indicating |
| 11 | +// that they have been altered from the originals. |
| 12 | + |
| 13 | +use pyo3::{prelude::*, pyclass}; |
| 14 | + |
| 15 | +/** |
| 16 | + A representation of an ``InstructionProperties`` object. |
| 17 | +*/ |
| 18 | +#[pyclass( |
| 19 | + subclass, |
| 20 | + name = "BaseInstructionProperties", |
| 21 | + module = "qiskit._accelerate.target" |
| 22 | +)] |
| 23 | +#[derive(Clone, Debug)] |
| 24 | +pub struct InstructionProperties { |
| 25 | + #[pyo3(get, set)] |
| 26 | + pub duration: Option<f64>, |
| 27 | + #[pyo3(get, set)] |
| 28 | + pub error: Option<f64>, |
| 29 | +} |
| 30 | + |
| 31 | +#[pymethods] |
| 32 | +impl InstructionProperties { |
| 33 | + /// Create a new ``BaseInstructionProperties`` object |
| 34 | + /// |
| 35 | + /// Args: |
| 36 | + /// duration (Option<f64>): The duration, in seconds, of the instruction on the |
| 37 | + /// specified set of qubits |
| 38 | + /// error (Option<f64>): The average error rate for the instruction on the specified |
| 39 | + /// set of qubits. |
| 40 | + /// calibration (Option<PyObject>): The pulse representation of the instruction. |
| 41 | + #[new] |
| 42 | + #[pyo3(signature = (duration=None, error=None))] |
| 43 | + pub fn new(_py: Python<'_>, duration: Option<f64>, error: Option<f64>) -> Self { |
| 44 | + Self { error, duration } |
| 45 | + } |
| 46 | + |
| 47 | + fn __getstate__(&self) -> PyResult<(Option<f64>, Option<f64>)> { |
| 48 | + Ok((self.duration, self.error)) |
| 49 | + } |
| 50 | + |
| 51 | + fn __setstate__(&mut self, _py: Python<'_>, state: (Option<f64>, Option<f64>)) -> PyResult<()> { |
| 52 | + self.duration = state.0; |
| 53 | + self.error = state.1; |
| 54 | + Ok(()) |
| 55 | + } |
| 56 | + |
| 57 | + fn __repr__(&self, _py: Python<'_>) -> String { |
| 58 | + format!( |
| 59 | + "InstructionProperties(duration={}, error={})", |
| 60 | + if let Some(duration) = self.duration { |
| 61 | + duration.to_string() |
| 62 | + } else { |
| 63 | + "None".to_string() |
| 64 | + }, |
| 65 | + if let Some(error) = self.error { |
| 66 | + error.to_string() |
| 67 | + } else { |
| 68 | + "None".to_string() |
| 69 | + } |
| 70 | + ) |
| 71 | + } |
| 72 | +} |
0 commit comments