From e40660e31019ac0e487429d61105eddb0352b072 Mon Sep 17 00:00:00 2001 From: alexanderlerner Date: Mon, 7 Oct 2024 17:38:56 -0400 Subject: [PATCH 01/30] flesh out getting started guide --- docs/getting_started.rst | 83 +++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index fa9a7b0..6c0c83b 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -4,16 +4,34 @@ Getting Started ===================== Welcome to Fast-Pauli from `Qognitive `_, an open-source Python / C++ library for optimized operations on Pauli matrices and Pauli strings -based on `PauliComposer `_. In this guide, -we'll introduce some of the important operations to help users get started. For more details, -see the API documentation. +based on `PauliComposer `_. +In this guide, we'll introduce some of the important operations to help users get started as well as some conceptual background on Pauli matrices and Pauli strings. + +For more details, see the :doc:`python_api` or :doc:`cpp_api` documentation. For tips on installing the library, check out the guide: :doc:`index`. Pauli Matrices ------------------------ -For a conceptual overview of Pauli matrices, see `here `_. +For a more in-depth overview of Pauli matrices, see `here `_. + +In math and physics, a `Pauli matrix `_, named after the physicist Wolfgang Pauli, is any one of the special 2 x 2 complex matrices in the set (often denoted by the greek letter :math:`\sigma`) : + +.. math:: + + \sigma_0 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} + \sigma_x = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} + \sigma_y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} + \sigma_z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} + +All the pauli matrices share the properties that they are: + +1. Hermitian (equal to their own conjugate transpose) :math:`\sigma_i = \sigma_i^\dagger` for all :math:`i \in \{x, y, z\}` +2. Involutory (they are their own inverse) :math:`\sigma_i^2 = \sigma_0` for all :math:`i \in \{x, y, z\}` +3. Unitary (their inverse is equal to their conjugate transpose) :math:`\sigma_i^{-1} = \sigma_i^\dagger` for all :math:`i \in \{x, y, z\}` + +with the identity matrix :math:`\sigma_0` or the :math:`2 \times 2` Identity matrix :math:`I` being the trivial case. In ``fast_pauli``, we represent pauli matrices using the ``Pauli`` class. For example, to represent the Pauli matrices, we can do: @@ -26,13 +44,23 @@ In ``fast_pauli``, we represent pauli matrices using the ``Pauli`` class. For ex pauli_y = fp.Pauli('Y') pauli_z = fp.Pauli('Z') + str(pauli_0) # returns "I" + We can also multiply two ``Pauli`` objects together to get a ``Pauli`` object representing the tensor product of the two pauli matrices. +The result includes a phase factor because Pauli matrices do not necessarily commute. They exhibit the following `commutation relations `_: + +.. math:: + + \sigma_x \sigma_y = i \sigma_z \\ + \sigma_y \sigma_z = i \sigma_x \\ + \sigma_z \sigma_x = i \sigma_y + +For example, we can compute the resulting ``Pauli`` object from multiplying :math:`\sigma_x` and :math:`\sigma_y` as follows: .. code-block:: python + # phase = i, new_pauli = fp.Pauli('Z') phase, new_pauli = pauli_x @ pauli_y - # returns "I" - str(pauli_0) From here, we can also convert our ``Pauli`` object back to a dense numpy array if we'd like: @@ -43,6 +71,21 @@ From here, we can also convert our ``Pauli`` object back to a dense numpy array Pauli Strings ------------------------ +Pauli strings, also known as Pauli words, are tensor-product combinations of Pauli matrices. For example, the following is a valid Pauli string: + +.. math:: + + \mathcal{\hat{P}} = \sigma_x \otimes \sigma_y \otimes \sigma_z + +where :math:`\otimes` denotes the tensor product, and we can more simply denote by + +.. math:: + + \mathcal{\hat{P}} = XYZ + +Other valid Pauli strings include ``III``, ``IXYZ``, ``IZYX``, etc. In general, a Pauli string of length ``N`` is a tensor product of ``N`` +Pauli matrices. A ``N``-length Pauli String in dense form is a :math:`2^N \times 2^N` matrix, so ``XYZ`` is a :math:`8 \times 8` matrix. + In ``fast_pauli``, we represent Pauli strings using the ``PauliString`` class. For example, to construct the Pauli string ``X, Y, Z``, we can do: .. code-block:: python @@ -61,16 +104,12 @@ Pauli Strings also support operations like addition, multiplication, and more. F P1.dim P1.n_qubits - # Add two Pauli strings. Return type is a PauliOp because - # the product is not a Pauli string - P3 = P1 + P2 - # Multiply two Pauli strings. phase, new_string = P1 @ P2 -We can also do more complicated things, like compute the action of a Pauli string :math:`\mathcal{\hat{P}}` on a quantum state :math:`| \psi \rangle`, :math:`\mathcal{\hat{P}}| \psi \rangle`, or -compute the expectation value of a Pauli string with a state :math:`\langle \psi | \mathcal{\hat{P}} | \psi \rangle`: +We can also do more complicated things, like compute the action of a Pauli string :math:`\mathcal{\hat{P}}` on a vector :math:`| \psi \rangle`, :math:`\mathcal{\hat{P}}| \psi \rangle`, or +compute the expectation value of a Pauli string with a state :math:`\langle \psi | \mathcal{\hat{P}} | \psi \rangle`. As a side note, in this guide we will use state and vector interchangeably: .. code-block:: python @@ -94,13 +133,14 @@ We can also convert ``PauliString`` objects back to dense numpy arrays if we'd l # Returns "XYZ" P_str = str(P) -For more details on the ``PauliString`` class, see the Python or C++ API documentation. +For more details on the ``PauliString`` class, see the :doc:`python_api` or :doc:`cpp_api` documentation. Pauli Operators ------------------------ -The ``PauliOp`` class lets us represent operators that are linear combinations of Pauli strings with complex coefficients. More specifically, -we can represent an arbitrary operator :math:`A` as a sum of Pauli strings :math:`P_i` with complex coefficients :math:`c_i`: +The ``PauliOp`` class lets us represent operators that are linear combinations of Pauli strings with complex coefficients. +In physics, an operator is represented by a matrix in a given basis. +For example, in the Pauli basis, we can represent an arbitrary operator :math:`A` as a sum of Pauli strings :math:`P_i` with complex coefficients :math:`c_i`: .. math:: @@ -122,7 +162,7 @@ that represents the operator :math:`A = 0.5 * XYZ + 0.5 * YYZ`, we can do: A.dim A.n_pauli_strings -Just like with ``PauliString`` objects, we can apply ``PauliOp`` objects to a set of quantum states or compute expectation values, as well as arithmetic +Just like with ``PauliString`` objects, we can apply ``PauliOp`` objects to a set of vectors, or compute expectation values, as well as arithmetic operations and dense matrix conversions. Just like with ``PauliString`` objects, we can also convert ``PauliOp`` objects back to dense numpy arrays if we'd like or get their string representation, in this case a list of strings: @@ -132,6 +172,13 @@ or get their string representation, in this case a list of strings: pauli_strings = ['XYZ', 'YYZ'] A = fp.PauliOp(coeffs, pauli_strings) + # Adding two Pauli strings returns a PauliOp. + # The returned object is a PauliOp because + # the sum is a linear combination of Pauli strings + P1 = fp.PauliString('XYZ') + P2 = fp.PauliString('YZX') + O = P1 + P2 + # PauliOp supports addition, subtraction, multiplication, # scaling, as well as have PauliString objects # as the second operand. All valid operations: @@ -141,7 +188,7 @@ or get their string representation, in this case a list of strings: s = fp.PauliString('XYZ') A4 = A1 + s - # Apply A to a state or set of states + # Apply A to a state / vector or set of states states = np.random.rand(10, 8) + 1j * np.random.rand(10, 8) new_states = A.apply(states) @@ -170,5 +217,5 @@ between ``PauliOp`` objects and ``SparsePauliOp`` objects from Qiskit: P = fp.PauliString('XYZ') qiskit_pauli = fp.to_qiskit(P) -For more details on Qiskit conversions, see the Python or C++ API documentation. +For more details on Qiskit conversions, see the :doc:`python_api` or :doc:`cpp_api` documentation. From 927ea0f8527573027dd0c8045dbe49c73cee934e Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Mon, 7 Oct 2024 17:41:16 -0400 Subject: [PATCH 02/30] update to pyproject to get the pip wheel/cibuildwheel to build --- CMakeLists.txt | 2 +- pyproject.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aad11ec..18d1243 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ find_package(OpenMP REQUIRED) # Setup Python find_package(Python 3.10 # This is a minimum version - COMPONENTS Interpreter Development REQUIRED) + COMPONENTS Interpreter Development.Module REQUIRED) # Our primary target add_library(fast_pauli INTERFACE) diff --git a/pyproject.toml b/pyproject.toml index 8ea1ba8..d311a11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ authors = [ ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] version = "0.0.8" +requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.10", @@ -178,5 +179,5 @@ docstring-code-format = true # pip install -e . --verbose -C cmake.args="-DCMAKE_CXX_COMPILER=clang++-18" [tool.scikit-build] cmake.build-type = "Release" -build-dir = "build" +build-dir = "build/{wheel_tag}" # TODO add more options here From 9152bbf2eaed58080ca1786651528b007e96b5e3 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Mon, 7 Oct 2024 18:44:27 -0400 Subject: [PATCH 03/30] run pytest on cibuildwheel --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index d311a11..38b878e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,3 +181,7 @@ docstring-code-format = true cmake.build-type = "Release" build-dir = "build/{wheel_tag}" # TODO add more options here + +[tool.cibuildwheel] +test-requires = "pytest" +test-command = "pytest {project}/tests" From 0c7deee582cd8dfddecf7bec7b6850fe782311c9 Mon Sep 17 00:00:00 2001 From: alexanderlerner Date: Mon, 7 Oct 2024 19:08:14 -0400 Subject: [PATCH 04/30] updated from comments --- docs/getting_started.rst | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 6c0c83b..cdabc62 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -20,7 +20,6 @@ In math and physics, a `Pauli matrix `_: - -.. math:: - - \sigma_x \sigma_y = i \sigma_z \\ - \sigma_y \sigma_z = i \sigma_x \\ - \sigma_z \sigma_x = i \sigma_y +The result includes a phase factor because the product of two Pauli matrices is not another Pauli matrix. For example, we can compute the resulting ``Pauli`` object from multiplying :math:`\sigma_x` and :math:`\sigma_y` as follows: @@ -71,20 +64,20 @@ From here, we can also convert our ``Pauli`` object back to a dense numpy array Pauli Strings ------------------------ -Pauli strings, also known as Pauli words, are tensor-product combinations of Pauli matrices. For example, the following is a valid Pauli string: +Pauli strings are tensor-product combinations of Pauli matrices. For example, the following is a valid Pauli string: .. math:: \mathcal{\hat{P}} = \sigma_x \otimes \sigma_y \otimes \sigma_z -where :math:`\otimes` denotes the tensor product, and we can more simply denote by +where :math:`\otimes` denotes the tensor or `Kronecker `_ product, and we can more simply denote by .. math:: \mathcal{\hat{P}} = XYZ -Other valid Pauli strings include ``III``, ``IXYZ``, ``IZYX``, etc. In general, a Pauli string of length ``N`` is a tensor product of ``N`` -Pauli matrices. A ``N``-length Pauli String in dense form is a :math:`2^N \times 2^N` matrix, so ``XYZ`` is a :math:`8 \times 8` matrix. +A Pauli string of length ``N`` is a tensor product of ``N`` +Pauli matrices. A ``N``-length Pauli String is a :math:`2^N \times 2^N` matrix, so ``XYZ`` is a :math:`8 \times 8` matrix. In ``fast_pauli``, we represent Pauli strings using the ``PauliString`` class. For example, to construct the Pauli string ``X, Y, Z``, we can do: @@ -140,7 +133,7 @@ Pauli Operators The ``PauliOp`` class lets us represent operators that are linear combinations of Pauli strings with complex coefficients. In physics, an operator is represented by a matrix in a given basis. -For example, in the Pauli basis, we can represent an arbitrary operator :math:`A` as a sum of Pauli strings :math:`P_i` with complex coefficients :math:`c_i`: +For example we can represent any arbitrary operator :math:`A` as a sum of Pauli strings :math:`P_i` with complex coefficients :math:`c_i`: .. math:: @@ -151,8 +144,8 @@ that represents the operator :math:`A = 0.5 * XYZ + 0.5 * YYZ`, we can do: .. code-block:: python - coeffs = np.array([0.5, 0.5], dtype=complex) - pauli_strings = ['XYZ', 'YYZ'] + coeffs = np.array([0.5, 0.5], dtype=complex) # represent c_i in the sum above + pauli_strings = ['XYZ', 'YYZ'] # represent P_i in the sum above A = fp.PauliOp(coeffs, pauli_strings) # Get the number of qubits the operator acts on, From 10ba4165e8ea6481722e55c6d555318007a14b7b Mon Sep 17 00:00:00 2001 From: alexanderlerner Date: Mon, 7 Oct 2024 19:11:55 -0400 Subject: [PATCH 05/30] tiny typo --- docs/getting_started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index cdabc62..213e8a2 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -133,7 +133,7 @@ Pauli Operators The ``PauliOp`` class lets us represent operators that are linear combinations of Pauli strings with complex coefficients. In physics, an operator is represented by a matrix in a given basis. -For example we can represent any arbitrary operator :math:`A` as a sum of Pauli strings :math:`P_i` with complex coefficients :math:`c_i`: +For example, we can represent any arbitrary operator :math:`A` as a sum of Pauli strings :math:`P_i` with complex coefficients :math:`c_i`: .. math:: From 1d58f6e801aba036af357d9565b85fc57a899a87 Mon Sep 17 00:00:00 2001 From: alexanderlerner Date: Mon, 7 Oct 2024 19:46:09 -0400 Subject: [PATCH 06/30] address comments --- docs/getting_started.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 213e8a2..08ee157 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -45,7 +45,7 @@ In ``fast_pauli``, we represent pauli matrices using the ``Pauli`` class. For ex str(pauli_0) # returns "I" -We can also multiply two ``Pauli`` objects together to get a ``Pauli`` object representing the tensor product of the two pauli matrices. +We can also multiply two ``Pauli`` objects together to get a ``Pauli`` object representing the matrix product of the two pauli matrices. The result includes a phase factor because the product of two Pauli matrices is not another Pauli matrix. For example, we can compute the resulting ``Pauli`` object from multiplying :math:`\sigma_x` and :math:`\sigma_y` as follows: @@ -123,8 +123,8 @@ We can also convert ``PauliString`` objects back to dense numpy arrays if we'd l P = fp.PauliString('XYZ') P_np = P.to_tensor() - # Returns "XYZ" - P_str = str(P) + + P_str = str(P) # Returns "XYZ" For more details on the ``PauliString`` class, see the :doc:`python_api` or :doc:`cpp_api` documentation. @@ -156,7 +156,7 @@ that represents the operator :math:`A = 0.5 * XYZ + 0.5 * YYZ`, we can do: A.n_pauli_strings Just like with ``PauliString`` objects, we can apply ``PauliOp`` objects to a set of vectors, or compute expectation values, as well as arithmetic -operations and dense matrix conversions. Just like with ``PauliString`` objects, we can also convert ``PauliOp`` objects back to dense numpy arrays if we'd like +operations. Just like with ``PauliString`` objects, we can also convert ``PauliOp`` objects back to dense numpy arrays if we'd like or get their string representation, in this case a list of strings: .. code-block:: python From ce7c24bd87c8a08c3521567907feda38f4600741 Mon Sep 17 00:00:00 2001 From: Alex Lerner <99294195+alexanderlerner@users.noreply.github.com> Date: Mon, 7 Oct 2024 19:50:02 -0400 Subject: [PATCH 07/30] Update docs/getting_started.rst Co-authored-by: James E T Smith --- docs/getting_started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 08ee157..2e1fb92 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -3,7 +3,7 @@ Getting Started ===================== -Welcome to Fast-Pauli from `Qognitive `_, an open-source Python / C++ library for optimized operations on Pauli matrices and Pauli strings +Welcome to :code:`fast-pauli` from `Qognitive `_, an open-source Python / C++ library for optimized operations on Pauli matrices and Pauli strings based on `PauliComposer `_. In this guide, we'll introduce some of the important operations to help users get started as well as some conceptual background on Pauli matrices and Pauli strings. From 662242d1600da9a5aa8a58db7e2185bca7f2a6a2 Mon Sep 17 00:00:00 2001 From: Alex Lerner <99294195+alexanderlerner@users.noreply.github.com> Date: Mon, 7 Oct 2024 19:50:11 -0400 Subject: [PATCH 08/30] Update docs/getting_started.rst Co-authored-by: James E T Smith --- docs/getting_started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 2e1fb92..140b90d 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -7,7 +7,7 @@ Welcome to :code:`fast-pauli` from `Qognitive `_, an based on `PauliComposer `_. In this guide, we'll introduce some of the important operations to help users get started as well as some conceptual background on Pauli matrices and Pauli strings. -For more details, see the :doc:`python_api` or :doc:`cpp_api` documentation. +For more details on our programmatic interface, see the :doc:`python_api` or :doc:`cpp_api` documentation. For tips on installing the library, check out the guide: :doc:`index`. From ec0ed0bfe8db869778b875d71c8d360b02f2fa55 Mon Sep 17 00:00:00 2001 From: Alex Lerner <99294195+alexanderlerner@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:45:22 -0400 Subject: [PATCH 09/30] Apply suggestions from code review Co-authored-by: James E T Smith --- docs/getting_started.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 140b90d..6aded88 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -7,10 +7,9 @@ Welcome to :code:`fast-pauli` from `Qognitive `_, an based on `PauliComposer `_. In this guide, we'll introduce some of the important operations to help users get started as well as some conceptual background on Pauli matrices and Pauli strings. +If you want to follow along with this guide, please follow the installation instructions in :doc:`index`. For more details on our programmatic interface, see the :doc:`python_api` or :doc:`cpp_api` documentation. -For tips on installing the library, check out the guide: :doc:`index`. - Pauli Matrices ------------------------ @@ -24,7 +23,7 @@ In math and physics, a `Pauli matrix Date: Tue, 8 Oct 2024 09:46:37 -0400 Subject: [PATCH 10/30] address comments --- docs/getting_started.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 140b90d..cdf48a5 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -77,9 +77,10 @@ where :math:`\otimes` denotes the tensor or `Kronecker `_, allowing for easy interfacing with certain Qiskit objects. For example, we can convert +``fast_pauli`` also has integration with `IBM's Qiskit SDK `_, allowing for easy interfacing with certain Qiskit objects. For example, we can convert between ``PauliOp`` objects and ``SparsePauliOp`` objects from Qiskit: .. code-block:: python - # Convert a Fast-Pauli PauliOp to a Qiskit SparsePauliOp object and back + # Convert a fast_pauli PauliOp to a Qiskit SparsePauliOp object and back O = fp.PauliOp([1], ['XYZ']) qiskit_op = fp.to_qiskit(O) fast_pauli_op = fp.from_qiskit(qiskit_op) - # Convert a Fast-Pauli PauliString to a Qiskit Pauli object + # Convert a fast_pauli PauliString to a Qiskit Pauli object P = fp.PauliString('XYZ') qiskit_pauli = fp.to_qiskit(P) -For more details on Qiskit conversions, see the :doc:`python_api` or :doc:`cpp_api` documentation. +For more details on Qiskit conversions, see the :doc:`python_api` documentation. From 11597185a8d1e57b9fa5da6f15d7e93c974e548e Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 09:59:24 -0400 Subject: [PATCH 11/30] config --- Makefile | 2 +- pyproject.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a20403c..3fd31aa 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ format: .PHONY: clean clean: - rm -rf build dist + rm -rf build dist wheelhouse .PHONY: pre-commit-setup pre-commit-setup: diff --git a/pyproject.toml b/pyproject.toml index 38b878e..8b2a640 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -183,5 +183,6 @@ build-dir = "build/{wheel_tag}" # TODO add more options here [tool.cibuildwheel] +build-frontend = "build" test-requires = "pytest" -test-command = "pytest {project}/tests" +test-command = "pytest {project}/tests/fast_pauli" From e0745f5dd060b0c840b5831279d7307e4f110e84 Mon Sep 17 00:00:00 2001 From: alexanderlerner Date: Tue, 8 Oct 2024 10:21:19 -0400 Subject: [PATCH 12/30] wording --- docs/getting_started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 9ccf35f..886d6df 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -45,7 +45,7 @@ In ``fast_pauli``, we represent pauli matrices using the ``Pauli`` class. For ex str(pauli_0) # returns "I" We can also multiply two ``Pauli`` objects together to get a ``Pauli`` object representing the matrix product of the two pauli matrices. -The result includes a phase factor because the product of two Pauli matrices is not another Pauli matrix. +The result includes a phase factor because the product of two Pauli matrices is not another Pauli matrix, but rather a Pauli matrix multiplied by either ``i`` or ``-i`` which we call a phase factor. For example, we can compute the resulting ``Pauli`` object from multiplying :math:`\sigma_x` and :math:`\sigma_y` as follows: From 2ea79930c2c66d59ce59fdc11288b84b493cf242 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 10:31:14 -0400 Subject: [PATCH 13/30] fix pytest in cibuildwheel --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8b2a640..ee42b4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -185,4 +185,4 @@ build-dir = "build/{wheel_tag}" [tool.cibuildwheel] build-frontend = "build" test-requires = "pytest" -test-command = "pytest {project}/tests/fast_pauli" +test-command = "pytest -s -vv --import-mode importlib {project}/tests/fast_pauli" From f51472603e7e08e876b1a5dc89c613ba2f9d16b7 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 11:01:31 -0400 Subject: [PATCH 14/30] update action --- .github/workflows/release.yml | 19 ++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f21a1e..d5c9a42 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ on: permissions: id-token: write # This is required for requesting the JWT jobs: - main-build: + source_dist_build: runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -30,3 +30,20 @@ jobs: CXX: ${{ matrix.compiler }} - name: Publish release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + wheels_build: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + # macos-13 is an intel runner, macos-14 is apple silicon + os: [ubuntu-latest, macos-13, macos-14] + steps: + - uses: actions/checkout@v4 + - name: Build wheels + uses: pypa/cibuildwheel@v2.21.2 + with: + config-file: "{package}/pyproject.toml" + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl diff --git a/pyproject.toml b/pyproject.toml index ee42b4f..93f3e34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -183,6 +183,7 @@ build-dir = "build/{wheel_tag}" # TODO add more options here [tool.cibuildwheel] +build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" test-requires = "pytest" test-command = "pytest -s -vv --import-mode importlib {project}/tests/fast_pauli" From 778e99647d1628d67541f914f3e459b5bc46a9b5 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 11:04:20 -0400 Subject: [PATCH 15/30] increment version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 93f3e34..0a810ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ authors = [ { name="Jeffrey Berger", email="jeff.berger@qognitive.io" }, ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] -version = "0.0.8" +version = "0.0.9" requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", From 9c62ef1ea8792ac3e0bd8c4e41b3426fdd21446b Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 11:15:32 -0400 Subject: [PATCH 16/30] remove mac for wheels --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d5c9a42..ca79e3d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,8 @@ jobs: strategy: matrix: # macos-13 is an intel runner, macos-14 is apple silicon - os: [ubuntu-latest, macos-13, macos-14] + # os: [ubuntu-latest, macos-13, macos-14] + os: [ubuntu-latest] steps: - uses: actions/checkout@v4 - name: Build wheels From d6335bd118352a097c240d69860bb1f444a0efc5 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 11:18:54 -0400 Subject: [PATCH 17/30] increment version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0a810ee..872f9b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ authors = [ { name="Jeffrey Berger", email="jeff.berger@qognitive.io" }, ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] -version = "0.0.9" +version = "0.0.10" requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", From 07d5697bf92bdc199d39a74bff9d7724ecacd335 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 12:18:06 -0400 Subject: [PATCH 18/30] use setuptools_scm for versioning --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 872f9b7..4416bbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ requires = [ # scikit-build-core uses cmake as needed (do not list it here) "scikit-build-core", + "setuptools_scm[toml]>=8", ] build-backend = "scikit_build_core.build" @@ -41,7 +42,6 @@ authors = [ { name="Jeffrey Berger", email="jeff.berger@qognitive.io" }, ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] -version = "0.0.10" requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", @@ -49,6 +49,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] +dynamic = ["version"] [project.optional-dependencies] @@ -180,8 +181,13 @@ docstring-code-format = true [tool.scikit-build] cmake.build-type = "Release" build-dir = "build/{wheel_tag}" +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["fast_pauli/__version__.py"] # TODO add more options here +[tool.setuptools_scm] +write_to = "fast_pauli/__version__.py" + [tool.cibuildwheel] build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" From 6038d2fa5252d6b13ff48310e4ff900fbd156f2a Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 12:41:06 -0400 Subject: [PATCH 19/30] add missing publish instructions --- .github/workflows/release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ca79e3d..511641a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: env: BUILD_OS: ${{ matrix.os }} CXX: ${{ matrix.compiler }} - - name: Publish release distributions to PyPI + - name: Publishi source dist release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 wheels_build: name: Build wheels on ${{ matrix.os }} @@ -47,4 +47,6 @@ jobs: - uses: actions/upload-artifact@v4 with: name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} - path: ./wheelhouse/*.whl + path: ./dist/*.whl + - name: Publish wheel release distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 From d9fbd18d94cc8159352508300381cf2a430639f4 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 12:43:25 -0400 Subject: [PATCH 20/30] add missing dev dependencies --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 4416bbb..ae8ba40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ dynamic = ["version"] [project.optional-dependencies] dev = [ + "cibuildwheel", "clang-format", "cmake-format", "pre-commit", @@ -61,6 +62,7 @@ dev = [ "ruff", "pytest", "pytest-benchmark", + "setuptools_scm", "sphinx", "sphinx_rtd_theme", "sphinx-autobuild", From 59a98a5b6bf53432643de06717fab8459684a0d7 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 12:44:58 -0400 Subject: [PATCH 21/30] Revert "use setuptools_scm for versioning" This reverts commit 07d5697bf92bdc199d39a74bff9d7724ecacd335. --- pyproject.toml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ae8ba40..07eefe4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ requires = [ # scikit-build-core uses cmake as needed (do not list it here) "scikit-build-core", - "setuptools_scm[toml]>=8", ] build-backend = "scikit_build_core.build" @@ -42,6 +41,7 @@ authors = [ { name="Jeffrey Berger", email="jeff.berger@qognitive.io" }, ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] +version = "0.0.10" requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", @@ -49,7 +49,6 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] -dynamic = ["version"] [project.optional-dependencies] @@ -183,13 +182,8 @@ docstring-code-format = true [tool.scikit-build] cmake.build-type = "Release" build-dir = "build/{wheel_tag}" -metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" -sdist.include = ["fast_pauli/__version__.py"] # TODO add more options here -[tool.setuptools_scm] -write_to = "fast_pauli/__version__.py" - [tool.cibuildwheel] build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" From 991be2c8a56b1632e881d4e0707c8bdb1fa816bb Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 12:50:26 -0400 Subject: [PATCH 22/30] version 0.0.11 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 07eefe4..af0f46d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ authors = [ { name="Jeffrey Berger", email="jeff.berger@qognitive.io" }, ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] -version = "0.0.10" +version = "0.0.11" requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", From 7a0b51e8bbc588cadefea279e04a01d3e5279522 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 12:18:06 -0400 Subject: [PATCH 23/30] use setuptools_scm for versioning --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index af0f46d..ae8ba40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ requires = [ # scikit-build-core uses cmake as needed (do not list it here) "scikit-build-core", + "setuptools_scm[toml]>=8", ] build-backend = "scikit_build_core.build" @@ -41,7 +42,6 @@ authors = [ { name="Jeffrey Berger", email="jeff.berger@qognitive.io" }, ] dependencies = ["numpy", "qiskit", "qiskit-algorithms"] -version = "0.0.11" requires-python = ">= 3.10" classifiers = [ "Programming Language :: Python :: 3 :: Only", @@ -49,6 +49,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] +dynamic = ["version"] [project.optional-dependencies] @@ -182,8 +183,13 @@ docstring-code-format = true [tool.scikit-build] cmake.build-type = "Release" build-dir = "build/{wheel_tag}" +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["fast_pauli/__version__.py"] # TODO add more options here +[tool.setuptools_scm] +write_to = "fast_pauli/__version__.py" + [tool.cibuildwheel] build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" From d9b524adca92ce474932e8c28f02fa9e277d1405 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 13:17:19 -0400 Subject: [PATCH 24/30] review python dependencies in action build --- .github/actions/build/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 1ca5496..2080915 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -7,7 +7,7 @@ runs: run: python3 ./.github/compiler_setup.py ${CXX} ${BUILD_OS} - name: Install Python dependencies shell: bash - run: python -m pip install cmake scikit-build-core + run: python -m pip install cmake scikit-build-core setuptools_scm build - name: Build shell: bash run: | @@ -24,5 +24,4 @@ runs: - name: Build Publishable release distributions for PyPI shell: bash run: | - python -m pip install build python -m build -s From e757ff5890de7b791db0a69a127330deaabf185a Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 13:31:08 -0400 Subject: [PATCH 25/30] change pypi location --- .github/workflows/release.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 511641a..76f9599 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,6 +47,6 @@ jobs: - uses: actions/upload-artifact@v4 with: name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} - path: ./dist/*.whl + path: /github/workspace/dist/*.whl - name: Publish wheel release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pyproject.toml b/pyproject.toml index ae8ba40..60367c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,7 +191,7 @@ sdist.include = ["fast_pauli/__version__.py"] write_to = "fast_pauli/__version__.py" [tool.cibuildwheel] -build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] +# build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" test-requires = "pytest" test-command = "pytest -s -vv --import-mode importlib {project}/tests/fast_pauli" From 5d86acf46731074aa3f174d9f2d9e9d97167ea2d Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 13:37:25 -0400 Subject: [PATCH 26/30] fix release path config --- .github/workflows/release.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 76f9599..22e48eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: env: BUILD_OS: ${{ matrix.os }} CXX: ${{ matrix.compiler }} - - name: Publishi source dist release distributions to PyPI + - name: Publish source dist release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 wheels_build: name: Build wheels on ${{ matrix.os }} @@ -44,9 +44,6 @@ jobs: uses: pypa/cibuildwheel@v2.21.2 with: config-file: "{package}/pyproject.toml" - - uses: actions/upload-artifact@v4 - with: - name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} - path: /github/workspace/dist/*.whl + output-dir: "/github/workspace/dist" - name: Publish wheel release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 From f5043c41e22c1a04266c50c452a4221ae530046c Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 13:47:23 -0400 Subject: [PATCH 27/30] uncomment build instructions --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 60367c5..ae8ba40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,7 +191,7 @@ sdist.include = ["fast_pauli/__version__.py"] write_to = "fast_pauli/__version__.py" [tool.cibuildwheel] -# build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] +build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" test-requires = "pytest" test-command = "pytest -s -vv --import-mode importlib {project}/tests/fast_pauli" From c18667c40f125a917fdfc3c16c423c9f5d59df85 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 13:54:40 -0400 Subject: [PATCH 28/30] temporarily enable a single wheel build --- .github/workflows/release.yml | 3 ++- pyproject.toml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 22e48eb..1992f26 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,6 +44,7 @@ jobs: uses: pypa/cibuildwheel@v2.21.2 with: config-file: "{package}/pyproject.toml" - output-dir: "/github/workspace/dist" - name: Publish wheel release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: ./fast_pauli/wheelhouse diff --git a/pyproject.toml b/pyproject.toml index ae8ba40..7156044 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,7 +191,8 @@ sdist.include = ["fast_pauli/__version__.py"] write_to = "fast_pauli/__version__.py" [tool.cibuildwheel] -build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] +# build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] +build = ["cp312-manylinux_x86_64"] build-frontend = "build" test-requires = "pytest" test-command = "pytest -s -vv --import-mode importlib {project}/tests/fast_pauli" From 5e928d35e49172f88c9e9f67fdf483005944361c Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 13:59:33 -0400 Subject: [PATCH 29/30] directory test --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1992f26..7c6df98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,4 +47,4 @@ jobs: - name: Publish wheel release distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: - packages-dir: ./fast_pauli/wheelhouse + packages-dir: wheelhouse From 4d57c1bb26b908d15623b281af5f9a756bf8788a Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 8 Oct 2024 14:06:54 -0400 Subject: [PATCH 30/30] more builds --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7156044..ae8ba40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,8 +191,7 @@ sdist.include = ["fast_pauli/__version__.py"] write_to = "fast_pauli/__version__.py" [tool.cibuildwheel] -# build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] -build = ["cp312-manylinux_x86_64"] +build = ["cp310-manylinux_x86_64", "cp311-manylinux_x86_64", "cp312-manylinux_x86_64", "cp313-manylinux_x86_64"] build-frontend = "build" test-requires = "pytest" test-command = "pytest -s -vv --import-mode importlib {project}/tests/fast_pauli"