Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stretch] Add stretch variable support to QuantumCircuit. #13852

Open
wants to merge 79 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
af4ba52
WIP
kevinhartman Feb 7, 2025
e423bf9
Add try_const to lift.
kevinhartman Feb 7, 2025
0a5917b
Try multiple singletons, new one for const.
kevinhartman Feb 7, 2025
a97434d
Revert "Try multiple singletons, new one for const."
kevinhartman Feb 7, 2025
1afc965
Remove Bool singleton test.
kevinhartman Feb 7, 2025
86655f1
Add const handling for stores, fix test bugs.
kevinhartman Feb 7, 2025
aaeae9b
Fix formatting.
kevinhartman Feb 7, 2025
a2a444b
Remove Duration and Stretch for now.
kevinhartman Feb 7, 2025
8ac2dc3
Cleanup, fix const bug in index.
kevinhartman Feb 7, 2025
9f8313c
Fix ordering issue for types with differing const-ness.
kevinhartman Feb 9, 2025
db9d9cb
Fix QPY serialization.
kevinhartman Feb 10, 2025
71b7e7a
Make expr.Lift default to non-const.
kevinhartman Feb 11, 2025
2091557
Revert to old test_expr_constructors.py.
kevinhartman Feb 11, 2025
7307be9
Make binary_logical lift independent again.
kevinhartman Feb 11, 2025
9b30284
Update tests, handle a few edge cases.
kevinhartman Feb 12, 2025
ce1faf1
Fix docstring.
kevinhartman Feb 12, 2025
4fee48f
Remove now redundant arg from tests.
kevinhartman Feb 12, 2025
88ab046
Add const testing for ordering.
kevinhartman Feb 12, 2025
c5a230f
Add const tests for shifts.
kevinhartman Feb 12, 2025
7c88d88
Add release note.
kevinhartman Feb 12, 2025
c58a7b8
Add const store tests.
kevinhartman Feb 12, 2025
d9e9a8c
Address lint, minor cleanup.
kevinhartman Feb 13, 2025
4a56150
Add Float type to classical expressions.
kevinhartman Feb 12, 2025
23b5961
Allow DANGEROUS conversion from Float to Bool.
kevinhartman Feb 12, 2025
8bf2e4f
Test Float ordering.
kevinhartman Feb 12, 2025
111eb32
Improve error messages for using Float with logical operators.
kevinhartman Feb 12, 2025
a839d51
Float tests for constructors.
kevinhartman Feb 12, 2025
a19b39a
Add release note.
kevinhartman Feb 12, 2025
7f02e56
Add Duration and Stretch classical types.
kevinhartman Feb 13, 2025
55af327
Add Duration type to qiskit.circuit.
kevinhartman Feb 13, 2025
86b7af9
Block Stretch from use in binary relations.
kevinhartman Feb 13, 2025
9b3c821
Add type ordering tests for Duration and Stretch.
kevinhartman Feb 13, 2025
69eab91
Test expr constructors for Duration and Stretch.
kevinhartman Feb 13, 2025
971cc26
Fix lint.
kevinhartman Feb 13, 2025
657b666
Implement operators +, -, *, /.
kevinhartman Feb 14, 2025
fc53d47
Add expression tests for arithmetic ops.
kevinhartman Feb 15, 2025
24f5125
Implement stretch support for circuit.
kevinhartman Feb 16, 2025
9e775e1
Initial support for writing QASM3.
kevinhartman Feb 16, 2025
25508bf
Reject const vars in add_var and add_input.
kevinhartman Feb 17, 2025
2c8ce43
Merge branch 'main' of github.com:Qiskit/qiskit into const-expr
kevinhartman Feb 17, 2025
ccf9441
Implement QPY support for const-typed expressions.
kevinhartman Feb 18, 2025
c6eab02
Remove invalid test.
kevinhartman Feb 18, 2025
edd7806
Update QPY version 14 desc.
kevinhartman Feb 18, 2025
8afa92e
Fix lint.
kevinhartman Feb 18, 2025
4e0f2df
Add serialization testing.
kevinhartman Feb 18, 2025
15ba943
Merge branch 'main' of github.com:Qiskit/qiskit into const-expr
kevinhartman Feb 18, 2025
81c5833
Merge branch 'const-expr' into expr-float
kevinhartman Feb 18, 2025
50c31d3
Test pre-v14 QPY rejects const-typed exprs.
kevinhartman Feb 18, 2025
7e43322
Merge branch 'main' of github.com:Qiskit/qiskit into const-expr
kevinhartman Feb 18, 2025
2449ee6
Merge branch 'const-expr' into expr-float
kevinhartman Feb 18, 2025
e55e189
QASM export for floats.
kevinhartman Feb 18, 2025
1d51022
QPY support for floats.
kevinhartman Feb 18, 2025
eb8f150
Fix lint.
kevinhartman Feb 18, 2025
415f62e
Merge branch 'expr-float' into expr-timing
kevinhartman Feb 18, 2025
d38f3e9
Settle on Duration circuit core type.
kevinhartman Feb 19, 2025
fd66c1d
QPY serialization for durations and stretches.
kevinhartman Feb 19, 2025
e9b6d97
Add QPY testing.
kevinhartman Feb 19, 2025
52da3cc
QASM support for stretch and duration.
kevinhartman Feb 19, 2025
a3be688
Fix lint.
kevinhartman Feb 19, 2025
2ff7e7a
Merge branch 'expr-timing' into math-expr
kevinhartman Feb 19, 2025
6e8080c
Add arithmetic operators to QASM.
kevinhartman Feb 19, 2025
9266166
QPY testing for arithmetic operations.
kevinhartman Feb 19, 2025
e92dcc5
QASM testing for arithmetic operations.
kevinhartman Feb 19, 2025
2d8f1b7
Merge branch 'math-expr' into circuit-stretch
kevinhartman Feb 19, 2025
f5a5457
Update tests for blocked const vars.
kevinhartman Feb 19, 2025
6d7b2af
Only test declare stretch QASM; fix lint.
kevinhartman Feb 19, 2025
6ad69d4
Special case for stretch in add_uninitialized_var.
kevinhartman Feb 19, 2025
af71e3a
Remove outdated docstring comment.
kevinhartman Feb 19, 2025
bddbc66
Remove outdated comment.
kevinhartman Feb 19, 2025
07771f1
Merge branch 'main' of github.com:Qiskit/qiskit into const-expr
kevinhartman Feb 20, 2025
9332ed3
Merge branch 'const-expr' into expr-float
kevinhartman Feb 20, 2025
17241c6
Merge branch 'expr-float' into expr-timing
kevinhartman Feb 20, 2025
ca91bfd
Don't use match since we still support Python 3.9.
kevinhartman Feb 20, 2025
368b0ac
Merge branch 'expr-timing' into math-expr
kevinhartman Feb 20, 2025
7fcb098
Merge branch 'math-expr' into circuit-stretch
kevinhartman Feb 20, 2025
723e4f0
Block const stores.
kevinhartman Feb 20, 2025
ad87e78
Fix enum match.
kevinhartman Feb 20, 2025
9afd68c
Merge branch 'expr-timing' into math-expr
kevinhartman Feb 20, 2025
86ac649
Merge branch 'math-expr' into circuit-stretch
kevinhartman Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions crates/circuit/src/duration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This code is part of Qiskit.
//
// (C) Copyright IBM 2025
//
// This code is licensed under the Apache License, Version 2.0. You may
// obtain a copy of this license in the LICENSE.txt file in the root directory
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

use pyo3::prelude::*;

#[pyclass(eq, module = "qiskit._accelerate.circuit")]
#[derive(PartialEq, Clone, Copy, Debug)]
#[allow(non_camel_case_types)]
pub enum Duration {
dt(u64),
ns(f64),
us(f64),
ms(f64),
s(f64),
}

impl Duration {
fn __repr__(&self) -> String {
match self {
Duration::ns(t) => format!("Duration.ns({})", t),
Duration::us(t) => format!("Duration.us({})", t),
Duration::ms(t) => format!("Duration.ms({})", t),
Duration::s(t) => format!("Duration.s({})", t),
Duration::dt(t) => format!("Duration.dt({})", t),
}
}
}
2 changes: 2 additions & 0 deletions crates/circuit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod converters;
pub mod dag_circuit;
pub mod dag_node;
mod dot_utils;
pub mod duration;
pub mod error;
pub mod gate_matrix;
pub mod imports;
Expand Down Expand Up @@ -157,6 +158,7 @@ macro_rules! impl_intopyobject_for_copy_pyclass {
}

pub fn circuit(m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<duration::Duration>()?;
m.add_class::<circuit_data::CircuitData>()?;
m.add_class::<circuit_instruction::CircuitInstruction>()?;
m.add_class::<dag_circuit::DAGCircuit>()?;
Expand Down
2 changes: 2 additions & 0 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ def __array__(self, dtype=None, copy=None):
\end{pmatrix}
"""

from qiskit._accelerate.circuit import Duration # pylint: disable=unused-import

from .exceptions import CircuitError
from . import _utils
from .quantumcircuit import QuantumCircuit
Expand Down
8 changes: 8 additions & 0 deletions qiskit/circuit/classical/expr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@
"greater",
"greater_equal",
"index",
"add",
"sub",
"mul",
"div",
"lift_legacy_condition",
]

Expand All @@ -234,5 +238,9 @@
shift_left,
shift_right,
index,
add,
sub,
mul,
div,
lift_legacy_condition,
)
Loading