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

Qiskit / qiskit / 15925372786

27 Jun 2025 11:38AM UTC coverage: 87.69% (-0.3%) from 88.02%
15925372786

push

github

web-flow
Bump indexmap from 2.9.0 to 2.10.0 (#14675)

Bumps [indexmap](https://github.com/indexmap-rs/indexmap) from 2.9.0 to 2.10.0.
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/main/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.9.0...2.10.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-version: 2.10.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

80997 of 92367 relevant lines covered (87.69%)

505937.52 hits per line

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

98.68
/crates/circuit/src/classical/expr/binary.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::{Expr, ExprKind, PyExpr};
14
use crate::classical::types::Type;
15
use crate::imports;
16
use pyo3::prelude::*;
17
use pyo3::types::PyTuple;
18
use pyo3::{intern, IntoPyObjectExt};
19

20
/// A binary expression.
21
#[derive(Clone, Debug, PartialEq)]
22
pub struct Binary {
23
    pub op: BinaryOp,
24
    pub left: Expr,
25
    pub right: Expr,
26
    pub ty: Type,
27
    pub constant: bool,
28
}
29

30
/// The Rust-side enum indicating a [Binary] expression's kind.
31
///
32
/// The values are part of the public Qiskit Python interface, since
33
/// they are public in the sister Python enum `_BinaryOp` in `expr.py`
34
/// and used in our QPY serialization format.
35
///
36
/// WARNING: If you add more, **be sure to update expr.py** as well
37
/// as the implementation of [::bytemuck::CheckedBitPattern]
38
/// below.
39
#[repr(u8)]
40
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
41
pub enum BinaryOp {
42
    BitAnd = 1,
43
    BitOr = 2,
44
    BitXor = 3,
45
    LogicAnd = 4,
46
    LogicOr = 5,
47
    Equal = 6,
48
    NotEqual = 7,
49
    Less = 8,
50
    LessEqual = 9,
51
    Greater = 10,
52
    GreaterEqual = 11,
53
    ShiftLeft = 12,
54
    ShiftRight = 13,
55
    Add = 14,
56
    Sub = 15,
57
    Mul = 16,
58
    Div = 17,
59
}
60

61
unsafe impl ::bytemuck::CheckedBitPattern for BinaryOp {
62
    type Bits = u8;
63

64
    fn is_valid_bit_pattern(bits: &Self::Bits) -> bool {
2,162✔
65
        *bits > 0 && *bits < 18
2,162✔
66
    }
2,162✔
67
}
68

69
impl<'py> IntoPyObject<'py> for Binary {
70
    type Target = PyAny;
71
    type Output = Bound<'py, PyAny>;
72
    type Error = PyErr;
73

74
    fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
1,046✔
75
        Ok(Bound::new(py, (PyBinary(self), PyExpr(ExprKind::Binary)))?.into_any())
1,046✔
76
    }
1,046✔
77
}
78

79
impl<'py> FromPyObject<'py> for Binary {
80
    fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
1,664✔
81
        let PyBinary(b) = ob.extract()?;
1,664✔
82
        Ok(b)
1,664✔
83
    }
1,664✔
84
}
85

86
impl<'py> IntoPyObject<'py> for BinaryOp {
87
    type Target = PyAny;
88
    type Output = Bound<'py, Self::Target>;
89
    type Error = PyErr;
90

91
    fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
1,288✔
92
        imports::BINARY_OP.get_bound(py).call1((self as usize,))
1,288✔
93
    }
1,288✔
94
}
95

96
impl<'py> FromPyObject<'py> for BinaryOp {
97
    fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
2,162✔
98
        let value = ob.getattr(intern!(ob.py(), "value"))?;
2,162✔
99
        Ok(bytemuck::checked::cast(value.extract::<u8>()?))
2,162✔
100
    }
2,162✔
101
}
102

103
/// A Python descriptor to prevent PyO3 from attempting to import the Python-side
104
/// enum before we're initialized.
105
#[pyclass(module = "qiskit._accelerate.circuit.classical.expr")]
106
struct PyBinaryOp;
107

108
#[pymethods]
109
impl PyBinaryOp {
110
    fn __get__(&self, obj: &Bound<PyAny>, _obj_type: &Bound<PyAny>) -> Py<PyAny> {
2,772✔
111
        imports::BINARY_OP.get_bound(obj.py()).clone().unbind()
2,772✔
112
    }
2,772✔
113
}
114

115
/// A binary expression.
116
///
117
/// Args:
118
///     op: The opcode describing which operation is being done.
119
///     left: The left-hand operand.
120
///     right: The right-hand operand.
121
///     type: The resolved type of the result.
122
#[pyclass(eq, extends = PyExpr, name = "Binary", module = "qiskit._accelerate.circuit.classical.expr")]
123
#[derive(PartialEq, Clone, Debug)]
124
pub struct PyBinary(Binary);
125

126
#[pymethods]
×
127
impl PyBinary {
128
    // The docstring for 'Op' is defined in Python (expr.py).
129
    #[classattr]
130
    #[allow(non_snake_case)]
131
    fn Op(py: Python) -> PyResult<Py<PyAny>> {
12✔
132
        PyBinaryOp.into_py_any(py)
12✔
133
    }
12✔
134

135
    #[new]
136
    #[pyo3(text_signature = "(op, left, right, type)")]
137
    fn new(py: Python, op: BinaryOp, left: Expr, right: Expr, ty: Type) -> PyResult<Py<Self>> {
2,162✔
138
        let constant = left.is_const() && right.is_const();
2,162✔
139
        Py::new(
2,162✔
140
            py,
2,162✔
141
            (
2,162✔
142
                PyBinary(Binary {
2,162✔
143
                    op,
2,162✔
144
                    left,
2,162✔
145
                    right,
2,162✔
146
                    ty,
2,162✔
147
                    constant,
2,162✔
148
                }),
2,162✔
149
                PyExpr(ExprKind::Binary),
2,162✔
150
            ),
2,162✔
151
        )
152
    }
2,162✔
153

154
    #[getter]
155
    fn get_op(&self, py: Python) -> PyResult<Py<PyAny>> {
1,288✔
156
        self.0.op.into_py_any(py)
1,288✔
157
    }
1,288✔
158

159
    #[getter]
160
    fn get_left(&self, py: Python) -> PyResult<Py<PyAny>> {
2,272✔
161
        self.0.left.clone().into_py_any(py)
2,272✔
162
    }
2,272✔
163

164
    #[getter]
165
    fn get_right(&self, py: Python) -> PyResult<Py<PyAny>> {
2,116✔
166
        self.0.right.clone().into_py_any(py)
2,116✔
167
    }
2,116✔
168

169
    #[getter]
170
    fn get_const(&self) -> bool {
458✔
171
        self.0.constant
458✔
172
    }
458✔
173

174
    #[getter]
175
    fn get_type(&self, py: Python) -> PyResult<Py<PyAny>> {
3,648✔
176
        self.0.ty.into_py_any(py)
3,648✔
177
    }
3,648✔
178

179
    fn accept<'py>(
1,962✔
180
        slf: PyRef<'py, Self>,
1,962✔
181
        visitor: &Bound<'py, PyAny>,
1,962✔
182
    ) -> PyResult<Bound<'py, PyAny>> {
1,962✔
183
        visitor.call_method1(intern!(visitor.py(), "visit_binary"), (slf,))
1,962✔
184
    }
1,962✔
185

186
    fn __reduce__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyTuple>> {
22✔
187
        (
188
            py.get_type::<Self>(),
22✔
189
            (
190
                self.get_op(py)?,
22✔
191
                self.get_left(py)?,
22✔
192
                self.get_right(py)?,
22✔
193
                self.get_type(py)?,
22✔
194
            ),
195
        )
196
            .into_pyobject(py)
22✔
197
    }
22✔
198

199
    fn __repr__(&self, py: Python) -> PyResult<String> {
8✔
200
        Ok(format!(
8✔
201
            "Binary({}, {}, {}, {})",
8✔
202
            self.get_op(py)?.bind(py).repr()?,
8✔
203
            self.get_left(py)?.bind(py).repr()?,
8✔
204
            self.get_right(py)?.bind(py).repr()?,
8✔
205
            self.get_type(py)?.bind(py).repr()?,
8✔
206
        ))
207
    }
8✔
208
}
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