• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Qiskit / qiskit / 19082828935

04 Nov 2025 09:06PM UTC coverage: 88.178% (-0.009%) from 88.187%
19082828935

Pull #15208

github

web-flow
Merge 2824c324c into 56db921d1
Pull Request #15208: Add ways to iterate over the `Target` in C.

102 of 126 new or added lines in 2 files covered. (80.95%)

989 existing lines in 42 files now uncovered.

93963 of 106561 relevant lines covered (88.18%)

1143131.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.87
/crates/circuit/src/classical/expr/value.rs
1
// This code is part of Qiskit.
2
//
3
// (C) Copyright IBM 2025
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 crate::classical::expr::{ExprKind, PyExpr};
14
use crate::classical::types::Type;
15
use crate::duration::Duration;
16
use num_bigint::BigUint;
17
use pyo3::prelude::*;
18
use pyo3::types::PyTuple;
19
use pyo3::{IntoPyObjectExt, intern};
20

21
/// A single scalar value expression.
22
#[derive(Clone, Debug, PartialEq)]
23
pub enum Value {
24
    Duration(Duration),
25
    Float { raw: f64, ty: Type },
26
    Uint { raw: BigUint, ty: Type },
27
}
28

29
impl<'py> IntoPyObject<'py> for Value {
30
    type Target = PyAny;
31
    type Output = Bound<'py, PyAny>;
32
    type Error = PyErr;
33

34
    fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
3,634✔
35
        Ok(Bound::new(py, (PyValue(self), PyExpr(ExprKind::Value)))?.into_any())
3,634✔
36
    }
3,634✔
37
}
38

39
impl<'a, 'py> FromPyObject<'a, 'py> for Value {
40
    type Error = <PyValue as FromPyObject<'a, 'py>>::Error;
41

42
    fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error> {
5,030✔
43
        let PyValue(v) = ob.extract()?;
5,030✔
44
        Ok(v)
5,030✔
45
    }
5,030✔
46
}
47

48
/// A single scalar value.
49
#[pyclass(eq, extends = PyExpr, name = "Value", module = "qiskit._accelerate.circuit.classical.expr")]
50
#[derive(PartialEq, Clone, Debug)]
51
pub struct PyValue(Value);
52

UNCOV
53
#[pymethods]
×
54
impl PyValue {
55
    #[new]
56
    #[pyo3(text_signature = "(value, type)")]
57
    fn new(py: Python, value: Bound<PyAny>, ty: Type) -> PyResult<Py<Self>> {
6,474✔
58
        let value = if let Ok(raw) = value.extract::<BigUint>() {
6,474✔
59
            Value::Uint { raw, ty }
4,662✔
60
        } else if let Ok(raw) = value.extract::<f64>() {
1,812✔
61
            Value::Float { raw, ty }
832✔
62
        } else {
63
            Value::Duration(value.extract()?)
980✔
64
        };
65
        Py::new(py, (PyValue(value), PyExpr(ExprKind::Value)))
6,474✔
66
    }
6,474✔
67

68
    #[getter]
69
    fn get_value(&self, py: Python) -> PyResult<Py<PyAny>> {
6,262✔
70
        match &self.0 {
6,262✔
71
            Value::Duration(d) => d.into_py_any(py),
1,628✔
72
            Value::Float { raw, .. } => raw.into_py_any(py),
816✔
73
            Value::Uint { raw, .. } => raw.into_py_any(py),
3,818✔
74
        }
75
    }
6,262✔
76

77
    #[getter]
78
    fn get_const(&self) -> bool {
164✔
79
        true
164✔
80
    }
164✔
81

82
    #[getter]
83
    fn get_type(&self, py: Python) -> PyResult<Py<PyAny>> {
13,342✔
84
        match self.0 {
13,342✔
85
            Value::Duration(_) => Type::Duration.into_py_any(py),
3,170✔
86
            Value::Float { ty, .. } | Value::Uint { ty, .. } => ty.into_py_any(py),
10,172✔
87
        }
88
    }
13,342✔
89

90
    fn accept<'py>(
3,630✔
91
        slf: PyRef<'py, Self>,
3,630✔
92
        visitor: &Bound<'py, PyAny>,
3,630✔
93
    ) -> PyResult<Bound<'py, PyAny>> {
3,630✔
94
        visitor.call_method1(intern!(visitor.py(), "visit_value"), (slf,))
3,630✔
95
    }
3,630✔
96

97
    fn __reduce__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyTuple>> {
2,582✔
98
        (
99
            py.get_type::<Self>(),
2,582✔
100
            (self.get_value(py)?, self.get_type(py)?),
2,582✔
101
        )
102
            .into_pyobject(py)
2,582✔
103
    }
2,582✔
104

105
    fn __repr__(&self, py: Python) -> PyResult<String> {
8✔
106
        Ok(format!(
8✔
107
            "Value({}, {})",
8✔
108
            self.get_value(py)?.bind(py).repr()?,
8✔
109
            self.get_type(py)?.bind(py).repr()?,
8✔
110
        ))
111
    }
8✔
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc