From aed465a298141c50ad6d583e0593d74c7724e25c Mon Sep 17 00:00:00 2001 From: Oscar Puente <156957451+orpuente-MS@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:23:11 -0800 Subject: [PATCH] update PyO3 to latest version --- Cargo.lock | 91 +++++------ Cargo.toml | 4 +- pip/src/fs.rs | 11 +- pip/src/interop.rs | 14 +- pip/src/interpreter.rs | 147 +++++++++++------- pip/src/noisy_simulator.rs | 5 +- .../src/estimates/physical_estimation.rs | 8 +- .../physical_estimation/estimate_frontier.rs | 3 +- .../estimate_without_restrictions.rs | 3 +- .../src/system/modeling/tfactory.rs | 4 +- .../src/system/serialization.rs | 2 +- wasm/src/lib.rs | 4 +- wasm/src/tests.rs | 6 +- 13 files changed, 163 insertions(+), 139 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f495d0171..c18c852995 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -133,7 +133,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -288,7 +288,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -416,7 +416,7 @@ checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -530,7 +530,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -817,7 +817,7 @@ checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -860,7 +860,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -1105,9 +1105,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.22.4" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00e89ce2565d6044ca31a3eb79a334c3a79a841120a98f64eea9f579564cb691" +checksum = "57fe09249128b3173d092de9523eaa75136bf7ba85e0d69eca241c7939c933cc" dependencies = [ "cfg-if", "indoc", @@ -1125,9 +1125,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.4" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8afbaf3abd7325e08f35ffb8deb5892046fcb2608b703db6a583a5ba4cea01e" +checksum = "1cd3927b5a78757a0d71aa9dff669f903b1eb64b54142a9bd9f757f8fde65fd7" dependencies = [ "once_cell", "python3-dll-a", @@ -1136,9 +1136,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.4" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec15a5ba277339d04763f4c23d85987a5b08cbb494860be141e6a10a8eb88022" +checksum = "dab6bb2102bd8f991e7749f130a70d05dd557613e39ed2deeee8e9ca0c4d548d" dependencies = [ "libc", "pyo3-build-config", @@ -1146,34 +1146,34 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.4" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e0f01b5364bcfbb686a52fc4181d412b708a68ed20c330db9fc8d2c2bf5a43" +checksum = "91871864b353fd5ffcb3f91f2f703a22a9797c91b9ab497b1acac7b07ae509c7" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] name = "pyo3-macros-backend" -version = "0.22.4" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a09b550200e1e5ed9176976d0060cbc2ea82dc8515da07885e7b8153a85caacb" +checksum = "43abc3b80bc20f3facd86cd3c60beed58c3e2aa26213f3cda368de39c60a27e4" dependencies = [ "heck", "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] name = "python3-dll-a" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0b78171a90d808b319acfad166c4790d9e9759bbc14ac8273fe133673dd41b" +checksum = "9b66f9171950e674e64bad3456e11bb3cca108e5c34844383cfe277f45c8a7a8" dependencies = [ "cc", ] @@ -1788,9 +1788,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.209" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -1808,13 +1808,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -1921,9 +1921,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.76" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -1980,7 +1980,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -2012,7 +2012,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] [[package]] @@ -2093,27 +2093,27 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -2131,9 +2131,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2141,22 +2141,25 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" @@ -2440,5 +2443,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.87", ] diff --git a/Cargo.toml b/Cargo.toml index 1223595473..6c927a5e89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,11 +73,11 @@ regex-lite = "0.1" rustc-hash = "1" serde = { version = "1.0", features = [ "derive" ] } serde-wasm-bindgen = "0.6" -wasm-bindgen = "0.2" +wasm-bindgen = "0.2.100" wasm-bindgen-futures = "0.4" rand = "0.8" serde_json = "1.0" -pyo3 = "0.22" +pyo3 = "0.23.4" quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "562e2c11ad685dd01bfc1ae975e00d4133615995" } async-trait = "0.1" tokio = { version = "1.35", features = ["macros", "rt"] } diff --git a/pip/src/fs.rs b/pip/src/fs.rs index 453a43ac22..6a79d01776 100644 --- a/pip/src/fs.rs +++ b/pip/src/fs.rs @@ -104,8 +104,7 @@ impl FileSystem for Py<'_> { } fn read_file(py: Python, read_file: &PyObject, path: &Path) -> PyResult<(Arc, Arc)> { - let read_file_result = - read_file.call1(py, PyTuple::new_bound(py, &[path.to_string_lossy()]))?; + let read_file_result = read_file.call1(py, PyTuple::new(py, &[path.to_string_lossy()])?)?; let tuple = read_file_result.downcast_bound::(py)?; @@ -114,7 +113,7 @@ fn read_file(py: Python, read_file: &PyObject, path: &Path) -> PyResult<(Arc PyResult> { let list_directory_result = - list_directory.call1(py, PyTuple::new_bound(py, &[path.to_string_lossy()]))?; + list_directory.call1(py, PyTuple::new(py, &[path.to_string_lossy()])?)?; list_directory_result .downcast_bound::(py)? @@ -147,7 +146,7 @@ fn resolve_path( ) -> PyResult { let resolve_path_result = resolve_path.call1( py, - PyTuple::new_bound(py, &[base.to_string_lossy(), path.to_string_lossy()]), + PyTuple::new(py, &[base.to_string_lossy(), path.to_string_lossy()])?, )?; Ok(PathBuf::from( @@ -167,7 +166,7 @@ fn fetch_github( path: &str, ) -> PyResult> { let fetch_github_result = - fetch_github.call1(py, PyTuple::new_bound(py, [owner, repo, r#ref, path]))?; + fetch_github.call1(py, PyTuple::new(py, [owner, repo, r#ref, path])?)?; Ok(fetch_github_result .downcast_bound::(py)? @@ -191,7 +190,7 @@ fn get_dict_string<'a>(dict: &Bound<'a, PyDict>, key: &'a str) -> PyResult, err: &PyErr) -> miette::Report { - if let Some(traceback) = err.traceback_bound(py) { + if let Some(traceback) = err.traceback(py) { match traceback.format() { Ok(traceback) => miette!(format!("{err}\n{traceback}",)), Err(traceback_err) => { diff --git a/pip/src/interop.rs b/pip/src/interop.rs index 7c961a6d6a..3f3fb75dbe 100644 --- a/pip/src/interop.rs +++ b/pip/src/interop.rs @@ -88,7 +88,7 @@ pub fn run_qasm3( ) -> PyResult { let mut receiver = OptionalCallbackReceiver { callback, py }; - let kwargs = kwargs.unwrap_or_else(|| PyDict::new_bound(py)); + let kwargs = kwargs.unwrap_or_else(|| PyDict::new(py)); let target = get_target_profile(&kwargs)?; let operation_name = get_operation_name(&kwargs)?; @@ -120,11 +120,7 @@ pub fn run_qasm3( .map_err(|errors| map_entry_compilation_errors(errors, &signature))?; match run_ast(&mut interpreter, &mut receiver, shots, seed) { - Ok(result) => Ok(PyList::new_bound( - py, - result.iter().map(|v| ValueWrapper(v.clone()).into_py(py)), - ) - .into_py(py)), + Ok(result) => Ok(PyList::new(py, result.iter().map(|v| ValueWrapper(v.clone())))?.into()), Err(errors) => Err(QSharpError::new_err(format_errors(errors))), } } @@ -166,7 +162,7 @@ pub(crate) fn resource_estimate_qasm3( fetch_github: Option, kwargs: Option>, ) -> PyResult { - let kwargs = kwargs.unwrap_or_else(|| PyDict::new_bound(py)); + let kwargs = kwargs.unwrap_or_else(|| PyDict::new(py)); let operation_name = get_operation_name(&kwargs)?; let search_path = get_search_path(&kwargs)?; @@ -228,7 +224,7 @@ pub(crate) fn compile_qasm3_to_qir( fetch_github: Option, kwargs: Option>, ) -> PyResult { - let kwargs = kwargs.unwrap_or_else(|| PyDict::new_bound(py)); + let kwargs = kwargs.unwrap_or_else(|| PyDict::new(py)); let target = get_target_profile(&kwargs)?; let operation_name = get_operation_name(&kwargs)?; @@ -367,7 +363,7 @@ pub(crate) fn compile_qasm3_to_qsharp( fetch_github: Option, kwargs: Option>, ) -> PyResult { - let kwargs = kwargs.unwrap_or_else(|| PyDict::new_bound(py)); + let kwargs = kwargs.unwrap_or_else(|| PyDict::new(py)); let operation_name = get_operation_name(&kwargs)?; let search_path = get_search_path(&kwargs)?; diff --git a/pip/src/interpreter.rs b/pip/src/interpreter.rs index 0a22140939..f658fe237a 100644 --- a/pip/src/interpreter.rs +++ b/pip/src/interpreter.rs @@ -17,7 +17,8 @@ use pyo3::{ create_exception, exceptions::{PyException, PyValueError}, prelude::*, - types::{PyComplex, PyDict, PyList, PyString, PyTuple, PyType}, + types::{PyDict, PyList, PyString, PyTuple, PyType}, + IntoPyObjectExt, }; use qsc::{ fir::{self}, @@ -76,10 +77,10 @@ fn _native<'a>(py: Python<'a>, m: &Bound<'a, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_function(wrap_pyfunction!(physical_estimates, m)?)?; - m.add("QSharpError", py.get_type_bound::())?; + m.add("QSharpError", py.get_type::())?; register_noisy_simulator_submodule(py, m)?; // QASM3 interop - m.add("QasmError", py.get_type_bound::())?; + m.add("QasmError", py.get_type::())?; m.add_function(wrap_pyfunction!(resource_estimate_qasm3, m)?)?; m.add_function(wrap_pyfunction!(run_qasm3, m)?)?; m.add_function(wrap_pyfunction!(compile_qasm3_to_qir, m)?)?; @@ -338,7 +339,7 @@ impl Interpreter { create_py_callable(py, make_callable, &namespace, &name, val)?; } } - Ok(ValueWrapper(value).into_py(py)) + Ok(ValueWrapper(value).into_pyobject(py)?.unbind()) } Err(errors) => Err(QSharpError::new_err(format_errors(errors))), } @@ -368,8 +369,8 @@ impl Interpreter { /// /// This circuit will contain the gates that have been applied /// in the simulator up to the current point. - fn dump_circuit(&mut self, py: Python) -> PyObject { - Circuit(self.interpreter.get_circuit()).into_py(py) + fn dump_circuit(&mut self, py: Python) -> PyResult { + Circuit(self.interpreter.get_circuit()).into_py_any(py) } #[pyo3(signature=(entry_expr=None, callback=None, noise=None))] @@ -391,7 +392,7 @@ impl Interpreter { }; match self.interpreter.run(&mut receiver, entry_expr, noise) { - Ok(value) => Ok(ValueWrapper(value).into_py(py)), + Ok(value) => Ok(ValueWrapper(value).into_pyobject(py)?.unbind()), Err(errors) => Err(QSharpError::new_err(format_errors(errors))), } } @@ -441,7 +442,7 @@ impl Interpreter { }; match self.interpreter.invoke(&mut receiver, callable.0, args) { - Ok(value) => Ok(ValueWrapper(value).into_py(py)), + Ok(value) => Ok(ValueWrapper(value).into_pyobject(py)?.unbind()), Err(errors) => Err(QSharpError::new_err(format_errors(errors))), } } @@ -481,7 +482,7 @@ impl Interpreter { }; match self.interpreter.circuit(entrypoint, false) { - Ok(circuit) => Ok(Circuit(circuit).into_py(py)), + Ok(circuit) => Circuit(circuit).into_py_any(py), Err(errors) => Err(QSharpError::new_err(format_errors(errors))), } } @@ -530,7 +531,7 @@ impl Interpreter { ) -> PyResult { let mut receiver = OptionalCallbackReceiver { callback, py }; - let kwargs = kwargs.unwrap_or_else(|| PyDict::new_bound(py)); + let kwargs = kwargs.unwrap_or_else(|| PyDict::new(py)); let operation_name = crate::interop::get_operation_name(&kwargs)?; let seed = crate::interop::get_seed(&kwargs); @@ -570,15 +571,13 @@ impl Interpreter { .map_err(|errors| map_entry_compilation_errors(errors, &signature))?; match run_ast(&mut self.interpreter, &mut receiver, shots, seed) { - Ok(result) => Ok(PyList::new_bound( - py, - result.iter().map(|v| ValueWrapper(v.clone()).into_py(py)), - ) - .into_py(py)), + Ok(result) => { + Ok(PyList::new(py, result.iter().map(|v| ValueWrapper(v.clone())))?.into()) + } Err(errors) => Err(QSharpError::new_err(format_errors(errors))), } } - _ => Ok(ValueWrapper(value).into_py(py)), + _ => Ok(ValueWrapper(value).into_pyobject(py)?.unbind()), } } } @@ -776,22 +775,8 @@ pub(crate) struct StateDumpData(pub(crate) DisplayableState); #[pymethods] impl StateDumpData { fn get_dict<'a>(&self, py: Python<'a>) -> PyResult> { - PyDict::from_sequence_bound(&PyList::new_bound( - py, - self.0 - .0 - .iter() - .map(|(k, v)| { - PyTuple::new_bound( - py, - &[ - k.clone().into_py(py), - PyComplex::from_doubles_bound(py, v.re, v.im).into(), - ], - ) - }) - .collect::>(), - )) + let dict = rustc_hash::FxHashMap::from_iter(self.0 .0.clone()); + dict.into_pyobject(py) } #[getter] @@ -870,44 +855,87 @@ pub(crate) enum Pauli { // Mapping of Q# value types to Python value types. pub(crate) struct ValueWrapper(pub(crate) Value); -impl IntoPy for ValueWrapper { - fn into_py(self, py: Python) -> PyObject { +impl<'py> IntoPyObject<'py> for ValueWrapper { + type Target = PyAny; + + type Output = Bound<'py, Self::Target>; + + type Error = pyo3::PyErr; + + fn into_pyobject(self, py: Python<'py>) -> std::result::Result { match self.0 { - Value::BigInt(val) => val.into_py(py), - Value::Int(val) => val.into_py(py), - Value::Double(val) => val.into_py(py), - Value::Bool(val) => val.into_py(py), - Value::String(val) => val.into_py(py), + Value::Int(val) => val.into_bound_py_any(py), + Value::BigInt(val) => val.into_bound_py_any(py), + Value::Double(val) => val.into_bound_py_any(py), + Value::Bool(val) => val.into_bound_py_any(py), + Value::String(val) => val.into_bound_py_any(py), Value::Result(val) => if val.unwrap_bool() { Result::One } else { Result::Zero } - .into_py(py), + .into_bound_py_any(py), Value::Pauli(val) => match val { - fir::Pauli::I => Pauli::I.into_py(py), - fir::Pauli::X => Pauli::X.into_py(py), - fir::Pauli::Y => Pauli::Y.into_py(py), - fir::Pauli::Z => Pauli::Z.into_py(py), + fir::Pauli::I => Pauli::I.into_bound_py_any(py), + fir::Pauli::X => Pauli::X.into_bound_py_any(py), + fir::Pauli::Y => Pauli::Y.into_bound_py_any(py), + fir::Pauli::Z => Pauli::Z.into_bound_py_any(py), }, Value::Tuple(val) => { if val.is_empty() { // Special case Value::unit as None - py.None() + Ok(py.None().into_bound(py)) } else { - PyTuple::new_bound(py, val.iter().map(|v| ValueWrapper(v.clone()).into_py(py))) - .into_py(py) + PyTuple::new(py, val.iter().map(|v| ValueWrapper(v.clone())))? + .into_bound_py_any(py) } } Value::Array(val) => { - PyList::new_bound(py, val.iter().map(|v| ValueWrapper(v.clone()).into_py(py))) - .into_py(py) + PyList::new(py, val.iter().map(|v| ValueWrapper(v.clone())))?.into_bound_py_any(py) } - _ => format!("<{}> {}", Value::type_name(&self.0), &self.0).into_py(py), + _ => format!("<{}> {}", Value::type_name(&self.0), &self.0).into_bound_py_any(py), } } } +// impl IntoPy for ValueWrapper { +// fn into_py(self, py: Python) -> PyObject { +// match self.0 { +// Value::BigInt(val) => val.into_py(py), +// Value::Int(val) => val.into_py(py), +// Value::Double(val) => val.into_py(py), +// Value::Bool(val) => val.into_py(py), +// Value::String(val) => val.into_py(py), +// Value::Result(val) => if val.unwrap_bool() { +// Result::One +// } else { +// Result::Zero +// } +// .into_py(py), +// Value::Pauli(val) => match val { +// fir::Pauli::I => Pauli::I.into_py(py), +// fir::Pauli::X => Pauli::X.into_py(py), +// fir::Pauli::Y => Pauli::Y.into_py(py), +// fir::Pauli::Z => Pauli::Z.into_py(py), +// }, +// Value::Tuple(val) => { +// if val.is_empty() { +// // Special case Value::unit as None +// py.None() +// } else { +// PyTuple::new_bound(py, val.iter().map(|v| ValueWrapper(v.clone()).into_py(py))) +// .into_py(py) +// } +// } +// Value::Array(val) => { +// PyList::new_bound(py, val.iter().map(|v| ValueWrapper(v.clone()).into_py(py))) +// .into_py(py) +// } +// _ => format!("<{}> {}", Value::type_name(&self.0), &self.0).into_py(py), +// } +// } +// } + pub(crate) struct OptionalCallbackReceiver<'a> { pub(crate) callback: Option, pub(crate) py: Python<'a>, @@ -924,10 +952,11 @@ impl Receiver for OptionalCallbackReceiver<'_> { callback .call1( self.py, - PyTuple::new_bound( + PyTuple::new( self.py, &[Py::new(self.py, Output(out)).expect("should be able to create output")], - ), + ) + .map_err(|_| Error)?, ) .map_err(|_| Error)?; } @@ -940,10 +969,11 @@ impl Receiver for OptionalCallbackReceiver<'_> { callback .call1( self.py, - PyTuple::new_bound( + PyTuple::new( self.py, &[Py::new(self.py, Output(out)).expect("should be able to create output")], - ), + ) + .map_err(|_| Error)?, ) .map_err(|_| Error)?; } @@ -956,10 +986,11 @@ impl Receiver for OptionalCallbackReceiver<'_> { callback .call1( self.py, - PyTuple::new_bound( + PyTuple::new( self.py, &[Py::new(self.py, Output(out)).expect("should be able to create output")], - ), + ) + .map_err(|_| Error)?, ) .map_err(|_| Error)?; } @@ -1043,8 +1074,8 @@ fn create_py_callable( let args = ( Py::new(py, GlobalCallable::from(val)).expect("should be able to create callable"), // callable id - PyList::new_bound(py, namespace.iter().map(ToString::to_string)), // namespace as string array - PyString::new_bound(py, name), // name of callable + PyList::new(py, namespace.iter().map(ToString::to_string))?, // namespace as string array + PyString::new(py, name), // name of callable ); // Call into the Python layer to create the function wrapping the callable invocation. diff --git a/pip/src/noisy_simulator.rs b/pip/src/noisy_simulator.rs index d536940765..e5e11f9047 100644 --- a/pip/src/noisy_simulator.rs +++ b/pip/src/noisy_simulator.rs @@ -12,10 +12,7 @@ pub(crate) fn register_noisy_simulator_submodule<'a>( py: Python<'a>, m: &Bound<'a, PyModule>, ) -> PyResult<()> { - m.add( - "NoisySimulatorError", - py.get_type_bound::(), - )?; + m.add("NoisySimulatorError", py.get_type::())?; m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/resource_estimator/src/estimates/physical_estimation.rs b/resource_estimator/src/estimates/physical_estimation.rs index 232c7c5dca..e63bc5d76b 100644 --- a/resource_estimator/src/estimates/physical_estimation.rs +++ b/resource_estimator/src/estimates/physical_estimation.rs @@ -645,7 +645,7 @@ impl<'a, F: Clone> FactoryForCycles<'a, F> { } } -impl<'a, F: Factory + Clone> Ord for FactoryForCycles<'a, F> { +impl Ord for FactoryForCycles<'_, F> { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.factory .normalized_volume() @@ -654,17 +654,17 @@ impl<'a, F: Factory + Clone> Ord for FactoryForCycles<'a, F> { } } -impl<'a, F: Factory + Clone> PartialOrd for FactoryForCycles<'a, F> { +impl PartialOrd for FactoryForCycles<'_, F> { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl<'a, F: Factory + Clone> PartialEq for FactoryForCycles<'a, F> { +impl PartialEq for FactoryForCycles<'_, F> { fn eq(&self, other: &Self) -> bool { (self.factory.normalized_volume(), self.num_cycles) == (other.factory.normalized_volume(), other.num_cycles) } } -impl<'a, F: Factory + Clone> Eq for FactoryForCycles<'a, F> {} +impl Eq for FactoryForCycles<'_, F> {} diff --git a/resource_estimator/src/estimates/physical_estimation/estimate_frontier.rs b/resource_estimator/src/estimates/physical_estimation/estimate_frontier.rs index 15f1582713..0f2fb1c551 100644 --- a/resource_estimator/src/estimates/physical_estimation/estimate_frontier.rs +++ b/resource_estimator/src/estimates/physical_estimation/estimate_frontier.rs @@ -216,11 +216,10 @@ impl< } impl< - 'a, E: ErrorCorrection, B: FactoryBuilder + Clone>, L: Overhead, - > Deref for EstimateFrontier<'a, E, B, L> + > Deref for EstimateFrontier<'_, E, B, L> { type Target = PhysicalResourceEstimation; diff --git a/resource_estimator/src/estimates/physical_estimation/estimate_without_restrictions.rs b/resource_estimator/src/estimates/physical_estimation/estimate_without_restrictions.rs index b9534293c0..60fefe17d3 100644 --- a/resource_estimator/src/estimates/physical_estimation/estimate_without_restrictions.rs +++ b/resource_estimator/src/estimates/physical_estimation/estimate_without_restrictions.rs @@ -278,11 +278,10 @@ impl< } impl< - 'a, E: ErrorCorrection, B: FactoryBuilder + Clone>, L: Overhead, - > Deref for EstimateWithoutRestrictions<'a, E, B, L> + > Deref for EstimateWithoutRestrictions<'_, E, B, L> { type Target = PhysicalResourceEstimation; diff --git a/resource_estimator/src/system/modeling/tfactory.rs b/resource_estimator/src/system/modeling/tfactory.rs index f47ed4b262..effaea7763 100644 --- a/resource_estimator/src/system/modeling/tfactory.rs +++ b/resource_estimator/src/system/modeling/tfactory.rs @@ -26,7 +26,7 @@ pub enum TFactoryQubit<'a> { Physical(&'a PhysicalQubit), } -impl<'a> TFactoryQubit<'a> { +impl TFactoryQubit<'_> { pub fn physical_qubits(&self) -> u64 { match self { Self::Logical(qubit) => qubit.physical_qubits(), @@ -286,7 +286,7 @@ pub struct TFactoryDistillationUnit<'a> { qubit_t_error_rate: f64, } -impl<'a> fmt::Debug for TFactoryDistillationUnit<'a> { +impl fmt::Debug for TFactoryDistillationUnit<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TFactoryDistillationUnit") .field("unit_type", &self.unit_type.to_string()) diff --git a/resource_estimator/src/system/serialization.rs b/resource_estimator/src/system/serialization.rs index 891de1a360..a72af42fe8 100644 --- a/resource_estimator/src/system/serialization.rs +++ b/resource_estimator/src/system/serialization.rs @@ -44,7 +44,7 @@ pub(crate) mod time { /// /// This adds the `ns` prefix to all time values and serializes them as a /// string. - #[allow(clippy::trivially_copy_pass_by_ref)] // forced by serde interface + #[allow(clippy::trivially_copy_pass_by_ref, clippy::ref_option)] // forced by serde interface pub(crate) fn serialize( time: &Option, serializer: S, diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index e644fe6f64..edc8fb0a5d 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -60,7 +60,7 @@ pub fn get_qir(program: ProgramConfig) -> Result { let (source_map, capabilities, language_features, store, deps) = into_qsc_args(program, None).map_err(compile_errors_into_qsharp_errors_json)?; - _get_qir( + get_qir_( source_map, language_features, capabilities, @@ -69,7 +69,7 @@ pub fn get_qir(program: ProgramConfig) -> Result { ) } -pub(crate) fn _get_qir( +pub(crate) fn get_qir_( sources: SourceMap, language_features: LanguageFeatures, capabilities: TargetCapabilityFlags, diff --git a/wasm/src/tests.rs b/wasm/src/tests.rs index 3b6d79f075..260324a62a 100644 --- a/wasm/src/tests.rs +++ b/wasm/src/tests.rs @@ -7,7 +7,7 @@ use qsc::{ interpret, LanguageFeatures, PackageStore, PauliNoise, SourceMap, TargetCapabilityFlags, }; -use crate::_get_qir; +use crate::get_qir_; use super::run_internal_with_features; @@ -513,7 +513,7 @@ fn test_doc_gen() { } else if !filename.eq("index.md") { assert!(std::path::Path::new(&filename) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("md"))); + .is_some_and(|ext| ext.eq_ignore_ascii_case("md"))); assert!( text.starts_with("---\n"), "file {name} does not start with metadata\ncontents: {text}" @@ -542,5 +542,5 @@ fn code_with_errors_returns_errors() { "[{\"document\":\"test.qs\",\"diagnostic\":{\"range\":{\"start\":{\"line\":4,\"character\":16},\"end\":{\"line\":4,\"character\":19}},\"message\":\"syntax error: expected `;`, found keyword `let`\",\"severity\":\"error\",\"code\":\"Qsc.Parse.Token\"},\"stack\":null}]", ) "#]] - .assert_debug_eq(&_get_qir(sources, language_features, capabilities, store, &[])); + .assert_debug_eq(&get_qir_(sources, language_features, capabilities, store, &[])); }