From 5f3dc42cb148c4cb095979cf4e1684573ff2c026 Mon Sep 17 00:00:00 2001 From: Kevin Hartman Date: Wed, 22 Nov 2023 11:34:44 -0500 Subject: [PATCH] Initial commit of Python bindings. --- crates/accelerate/src/lib.rs | 2 ++ crates/accelerate/src/quantum_info/mod.rs | 21 ++++++++++++++++ .../src/quantum_info/two_qubit_decompose.rs | 24 +++++++++++++++++++ qiskit/__init__.py | 1 + test/python/quantum_info/test_accelerate.py | 23 ++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 crates/accelerate/src/quantum_info/mod.rs create mode 100644 crates/accelerate/src/quantum_info/two_qubit_decompose.rs create mode 100644 test/python/quantum_info/test_accelerate.py diff --git a/crates/accelerate/src/lib.rs b/crates/accelerate/src/lib.rs index 9e7d4cbddf72..5e73f74f9a24 100644 --- a/crates/accelerate/src/lib.rs +++ b/crates/accelerate/src/lib.rs @@ -32,6 +32,7 @@ mod sampled_exp_val; mod sparse_pauli_op; mod stochastic_swap; mod vf2_layout; +mod quantum_info; #[inline] pub fn getenv_use_multiple_threads() -> bool { @@ -54,6 +55,7 @@ fn _accelerate(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pymodule!(pauli_exp_val::pauli_expval))?; m.add_wrapped(wrap_pymodule!(dense_layout::dense_layout))?; m.add_wrapped(wrap_pymodule!(quantum_circuit::quantum_circuit))?; + m.add_wrapped(wrap_pymodule!(quantum_info::quantum_info))?; m.add_wrapped(wrap_pymodule!(error_map::error_map))?; m.add_wrapped(wrap_pymodule!(sparse_pauli_op::sparse_pauli_op))?; m.add_wrapped(wrap_pymodule!(results::results))?; diff --git a/crates/accelerate/src/quantum_info/mod.rs b/crates/accelerate/src/quantum_info/mod.rs new file mode 100644 index 000000000000..2308ac36e6ab --- /dev/null +++ b/crates/accelerate/src/quantum_info/mod.rs @@ -0,0 +1,21 @@ +// This code is part of Qiskit. +// +// (C) Copyright IBM 2023 +// +// 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. + +pub mod two_qubit_decompose; + +use pyo3::prelude::*; + +#[pymodule] +pub fn quantum_info(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_wrapped(wrap_pyfunction!(two_qubit_decompose::decompose_two_qubit_product_gate))?; + Ok(()) +} diff --git a/crates/accelerate/src/quantum_info/two_qubit_decompose.rs b/crates/accelerate/src/quantum_info/two_qubit_decompose.rs new file mode 100644 index 000000000000..86f4d8f6f80d --- /dev/null +++ b/crates/accelerate/src/quantum_info/two_qubit_decompose.rs @@ -0,0 +1,24 @@ +// This code is part of Qiskit. +// +// (C) Copyright IBM 2023 +// +// 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::*; + +#[pyfunction] +#[pyo3( +text_signature = "(special_unitary_matrix)" +)] +pub fn decompose_two_qubit_product_gate( + py: Python<'_>, + special_unitary_matrix: &PyAny, +) -> PyObject { + "This is a string.".into_py(py) +} diff --git a/qiskit/__init__.py b/qiskit/__init__.py index 219d305321f3..289b1b128759 100644 --- a/qiskit/__init__.py +++ b/qiskit/__init__.py @@ -26,6 +26,7 @@ # and not have to rely on attribute access. No action needed for top-level extension packages. sys.modules["qiskit._accelerate.nlayout"] = qiskit._accelerate.nlayout sys.modules["qiskit._accelerate.quantum_circuit"] = qiskit._accelerate.quantum_circuit +sys.modules["qiskit._accelerate.quantum_info"] = qiskit._accelerate.quantum_info sys.modules["qiskit._accelerate.stochastic_swap"] = qiskit._accelerate.stochastic_swap sys.modules["qiskit._accelerate.sabre_swap"] = qiskit._accelerate.sabre_swap sys.modules["qiskit._accelerate.sabre_layout"] = qiskit._accelerate.sabre_layout diff --git a/test/python/quantum_info/test_accelerate.py b/test/python/quantum_info/test_accelerate.py new file mode 100644 index 000000000000..a399e44753d9 --- /dev/null +++ b/test/python/quantum_info/test_accelerate.py @@ -0,0 +1,23 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2023. +# +# 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. + +"""Tests for synthesis routines in qiskit._accelerate.quantum_info.""" +from qiskit._accelerate.quantum_info import decompose_two_qubit_product_gate + +from qiskit.test import QiskitTestCase + + +class TestAccelerate(QiskitTestCase): + """Test accelerate.""" + + def test_decompose_two_qubit_product_gate(self): + self.assertIsNotNone(decompose_two_qubit_product_gate(None))