diff --git a/.azure/wheels.yml b/.azure/wheels.yml index 5b106747fd2d..fa8ecd17a051 100644 --- a/.azure/wheels.yml +++ b/.azure/wheels.yml @@ -25,7 +25,7 @@ jobs: - bash: | set -e python -m pip install --upgrade pip - python -m pip install cibuildwheel==2.11.2 + python -m pip install cibuildwheel==2.13.0 python -m pip install -U twine cibuildwheel --output-dir wheelhouse . diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 7b7bebc33e0a..8a7e22bb9c82 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -24,7 +24,7 @@ jobs: with: platforms: all - name: Build wheels - uses: pypa/cibuildwheel@v2.11.2 + uses: pypa/cibuildwheel@v2.13.0 env: CIBW_ARCHS_LINUX: s390x CIBW_TEST_SKIP: "cp*" @@ -57,7 +57,7 @@ jobs: with: platforms: all - name: Build wheels - uses: pypa/cibuildwheel@v2.11.2 + uses: pypa/cibuildwheel@v2.13.0 env: CIBW_ARCHS_LINUX: ppc64le CIBW_TEST_SKIP: "cp*" @@ -90,7 +90,7 @@ jobs: with: platforms: all - name: Build wheels - uses: pypa/cibuildwheel@v2.11.2 + uses: pypa/cibuildwheel@v2.13.0 env: CIBW_ARCHS_LINUX: aarch64 - uses: actions/upload-artifact@v3 diff --git a/crates/accelerate/Cargo.toml b/crates/accelerate/Cargo.toml index 983729ddeb1b..cfb70dce6869 100644 --- a/crates/accelerate/Cargo.toml +++ b/crates/accelerate/Cargo.toml @@ -26,7 +26,7 @@ rustworkx-core = "0.12" # can be done in the workspace and inherited once we hit Rust 1.64. [dependencies.pyo3] version = "0.19.0" -features = ["extension-module", "hashbrown", "indexmap", "num-complex", "num-bigint"] +features = ["extension-module", "hashbrown", "indexmap", "num-complex", "num-bigint", "abi3-py38"] [dependencies.ndarray] version = "^0.15.6" diff --git a/crates/accelerate/src/results/marginalization.rs b/crates/accelerate/src/results/marginalization.rs index f71511f0e1b6..08e1b42e287e 100644 --- a/crates/accelerate/src/results/marginalization.rs +++ b/crates/accelerate/src/results/marginalization.rs @@ -152,19 +152,24 @@ pub fn marginal_memory( .collect() }; if return_int { - if out_mem.len() < parallel_threshold || !run_in_parallel { - Ok(out_mem - .iter() - .map(|x| BigUint::parse_bytes(x.as_bytes(), 2).unwrap()) - .collect::>() - .to_object(py)) - } else { - Ok(out_mem - .par_iter() - .map(|x| BigUint::parse_bytes(x.as_bytes(), 2).unwrap()) - .collect::>() - .to_object(py)) - } + // Replace with: + // + // .iter() + // .map(|x| BigUint::parse_bytes(x.as_bytes(), 2).unwrap()) + // .collect::>() + // .to_object(py)) + // + // (also this can be done in parallel, see + // https://github.com/Qiskit/qiskit-terra/pull/10120 for more + // details) + // + // After PyO3/pyo3#3198 is included in a pyo3 release. + let int_pyobject = py.import("builtins")?.getattr("int")?; + Ok(out_mem + .iter() + .map(|x| int_pyobject.call1((x, 2u8)).unwrap()) + .collect::>() + .to_object(py)) } else { Ok(out_mem.to_object(py)) } diff --git a/crates/qasm2/Cargo.toml b/crates/qasm2/Cargo.toml index 5a82991f3f02..91fa6472d261 100644 --- a/crates/qasm2/Cargo.toml +++ b/crates/qasm2/Cargo.toml @@ -13,4 +13,4 @@ crate-type = ["cdylib"] [dependencies] hashbrown = "0.13.2" -pyo3 = { version = "0.19.0", features = ["extension-module"] } +pyo3 = { version = "0.19.0", features = ["extension-module", "abi3-py38"] } diff --git a/pyproject.toml b/pyproject.toml index 53b83021584a..9a9663779a56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,13 @@ environment = 'RUSTUP_TOOLCHAIN="stable"' [tool.cibuildwheel.linux] before-all = "yum install -y wget && {package}/tools/install_rust.sh" environment = 'PATH="$PATH:$HOME/.cargo/bin" CARGO_NET_GIT_FETCH_WITH_CLI="true" RUSTUP_TOOLCHAIN="stable"' +repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel} && pipx run abi3audit --strict --report {wheel}" + +[tool.cibuildwheel.macos] +repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} && pipx run abi3audit --strict --report {wheel}" + +[tool.cibuildwheel.windows] +repair-wheel-command = "cp {wheel} {dest_dir}/. && pipx run abi3audit --strict --report {wheel}" [tool.ruff] select = [ diff --git a/qiskit/quantum_info/states/densitymatrix.py b/qiskit/quantum_info/states/densitymatrix.py index 124a382f01d1..8ed356327c45 100644 --- a/qiskit/quantum_info/states/densitymatrix.py +++ b/qiskit/quantum_info/states/densitymatrix.py @@ -382,6 +382,7 @@ def _expectation_value_pauli(self, pauli, qargs=None): x_max = qubits[pauli.x][-1] y_phase = (-1j) ** pauli._count_y() + y_phase = y_phase[0] return pauli_phase * density_expval_pauli_with_x( data, self.num_qubits, z_mask, x_mask, y_phase, x_max ) diff --git a/qiskit/quantum_info/states/statevector.py b/qiskit/quantum_info/states/statevector.py index 5c63a6628379..639f147b1e71 100644 --- a/qiskit/quantum_info/states/statevector.py +++ b/qiskit/quantum_info/states/statevector.py @@ -476,6 +476,7 @@ def _expectation_value_pauli(self, pauli, qargs=None): x_max = qubits[pauli.x][-1] y_phase = (-1j) ** pauli._count_y() + y_phase = y_phase[0] return pauli_phase * expval_pauli_with_x( self.data, self.num_qubits, z_mask, x_mask, y_phase, x_max diff --git a/releasenotes/notes/use-abi3-4a935e0557d3833b.yaml b/releasenotes/notes/use-abi3-4a935e0557d3833b.yaml new file mode 100644 index 000000000000..db946ded97ef --- /dev/null +++ b/releasenotes/notes/use-abi3-4a935e0557d3833b.yaml @@ -0,0 +1,17 @@ +--- +upgrade: + - | + By default Qiskit builds its compiled extensions using the + `Python Stable ABI `__ + with support back to the oldest version of Python supported by Qiskit + (currently 3.8). This means that moving forward there + will be a single precompiled wheels that are shipped on release that + works with all of Qiskit's supported Python versions. There isn't any + expected runtime performance difference using the limited API so it is + enabled by default for all builds now. + Previously, the compiled extensions were built using the version specific API and + would only work with a single Python version. This change was made + to reduce the number of package files we need to build and publish in each + release. When building Qiskit from source there should be no changes + necessary to the build process except that the default tags in the output + filenames will be different to reflect the use of the limited API. diff --git a/setup.py b/setup.py index 352df8669fe8..ec0420f70691 100755 --- a/setup.py +++ b/setup.py @@ -110,9 +110,13 @@ debug=rust_debug, ), RustExtension( - "qiskit._qasm2", "crates/qasm2/Cargo.toml", binding=Binding.PyO3, debug=rust_debug + "qiskit._qasm2", + "crates/qasm2/Cargo.toml", + binding=Binding.PyO3, + debug=rust_debug, ), ], + options={"bdist_wheel": {"py_limited_api": "cp38"}}, zip_safe=False, entry_points={ "qiskit.unitary_synthesis": [