Skip to content

Commit

Permalink
Merge remote-tracking branch 'ibm/main' into direct-pass-call
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Mar 5, 2025
2 parents 975769e + 9e455f2 commit 390fa85
Show file tree
Hide file tree
Showing 643 changed files with 18,986 additions and 41,064 deletions.
8 changes: 7 additions & 1 deletion .azure/lint_docs-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ jobs:
- bash: tools/install_ubuntu_docs_dependencies.sh
displayName: 'Install docs dependencies'

- bash: tox run -e docs,lint
- bash: tools/install_ubuntu_c_dependencies.sh
displayName: 'Install C dependencies'

- bash: |
set -e
make cformat
tox run -e docs,lint
displayName: 'Lint and docs'
- bash: rm -rf docs/_build/html/{.doctrees,.buildinfo}
Expand Down
1 change: 1 addition & 0 deletions .azure/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
popd
env:
QISKIT_PARALLEL: FALSE
QISKIT_IGNORE_USER_SETTINGS: TRUE
RUST_BACKTRACE: 1
displayName: 'Run Python tests'
Expand Down
1 change: 1 addition & 0 deletions .azure/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
stestr run
env:
QISKIT_PARALLEL: FALSE
QISKIT_IGNORE_USER_SETTINGS: TRUE
RUST_BACKTRACE: 1
displayName: "Run tests"
Expand Down
1 change: 1 addition & 0 deletions .azure/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
LANG: 'C.UTF-8'
PYTHONIOENCODING: 'utf-8:backslashreplace'
QISKIT_PARALLEL: FALSE
QISKIT_IGNORE_USER_SETTINGS: TRUE
RUST_BACKTRACE: 1
displayName: 'Run tests'
Expand Down
7 changes: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
BasedOnStyle: LLVM
ColumnLimit: '100'
IndentWidth: '4'
Language: Cpp
TabWidth: '4'
UseTab: Never
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
env:
QISKIT_TEST_CAPTURE_STREAMS: 1
QISKIT_PARALLEL: FALSE
QISKIT_IGNORE_USER_SETTINGS: TRUE
PYTHON: "coverage run --source qiskit --parallel-mode"

- name: Convert to lcov and combine data
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/ctests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Tests
on:
push:
branches: [ main, 'stable/*' ]
pull_request:
branches: [ main, 'stable/*' ]
merge_group:

jobs:
tests:
if: github.repository_owner == 'Qiskit'
name: linux-tests-c
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: cargo install cbindgen
- name: Run tests
run: make ctest
2 changes: 2 additions & 0 deletions .github/workflows/qpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ jobs:
- name: Run QPY backwards compatibility tests
working-directory: test/qpy_compat
run: ./run_tests.sh
env:
QISKIT_IGNORE_USER_SETTINGS: TRUE
1 change: 1 addition & 0 deletions .github/workflows/randomized_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
run: make test_randomized
env:
RUST_BACKTRACE: 1
QISKIT_IGNORE_USER_SETTINGS: TRUE
- name: Create comment on failed test run
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/slow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
env:
RUST_BACKTRACE: 1
QISKIT_TESTS: "run_slow"
QISKIT_IGNORE_USER_SETTINGS: TRUE
- name: Create comment on failed test run
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v4
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ concurrency:
jobs:
tests:
if: github.repository_owner == 'Qiskit'
name: macOS-arm64-tests-Python-${{ matrix.python-version }}
runs-on: macOS-14
name: ${{ matrix.os }}-arm64-tests-Python-${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Normally we test min and max version but we can't run python
# 3.9 on arm64 until actions/setup-python#808 is resolved
python-version: ["3.10", "3.13"]
python-version: ["3.9", "3.13"]
os: ["macOS-14", "ubuntu-24.04-arm"]
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/[email protected]
if: matrix.python-version == '3.10'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -36,7 +32,7 @@ jobs:
python -m pip install -U -r requirements.txt -c constraints.txt
python -m pip install -U -r requirements-dev.txt -c constraints.txt
python -m pip install -c constraints.txt -e .
if: matrix.python-version == '3.10'
if: matrix.python-version == '3.9'
env:
QISKIT_NO_CACHE_GATES: 1
- name: 'Install dependencies'
Expand All @@ -49,6 +45,9 @@ jobs:
run: |
python -m pip install -r requirements-optional.txt -c constraints.txt
python tools/report_numpy_state.py
if: matrix.python-version == '3.10'
if: matrix.python-version == '3.9'
- name: 'Run tests'
run: stestr run
env:
QISKIT_PARALLEL: FALSE
QISKIT_IGNORE_USER_SETTINGS: TRUE
44 changes: 13 additions & 31 deletions .github/workflows/wheels-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ on:
default: "default"
required: false

wheels-linux-aarch64:
description: >-
The action to take for Linux AArch64 wheels.
Choose from 'default', 'build' or 'skip'.
type: string
default: "default"
required: false

artifact-prefix:
description: "A prefix to give all artifacts uploaded with 'actions/upload-artifact'."
type: string
Expand Down Expand Up @@ -85,12 +77,12 @@ jobs:
# Used for the ARM builds.
- macos-14
- windows-latest
- ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
architecture: ${{ matrix.os == 'macos-14' && 'arm64' || 'x64' }}
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
Expand All @@ -108,22 +100,28 @@ jobs:
run: |
set -e
mkdir -p "$PGO_WORK_DIR"
if [[ `uname -m` == "aarch64" ]] ; then
INSTALL_RUST_PATH=tools/install_rust_msrv.sh
RUST_TOOLCHAIN=1.79
else
INSTALL_RUST_PATH=tools/install_rust.sh
RUST_TOOLCHAIN=stable
fi
cat >>"$GITHUB_ENV" <<EOF
CIBW_BEFORE_ALL_LINUX=yum install -y wget && {package}/$INSTALL_RUST_PATH
CIBW_BEFORE_BUILD=bash ./tools/build_pgo.sh $PGO_WORK_DIR $PGO_OUT_PATH
CIBW_ENVIRONMENT=RUSTUP_TOOLCHAIN=stable RUSTFLAGS='-Cprofile-use=$PGO_OUT_PATH -Cllvm-args=-pgo-warn-missing-function'
CIBW_ENVIRONMENT_MACOS=MACOSX_DEPLOYMENT_TARGET='10.12' RUSTUP_TOOLCHAIN=stable RUSTFLAGS='-Cprofile-use=$PGO_OUT_PATH -Cllvm-args=-pgo-warn-missing-function'
CIBW_ENVIRONMENT_LINUX=RUSTUP_TOOLCHAIN=stable RUSTFLAGS='-Cprofile-use=$PGO_OUT_PATH -Cllvm-args=-pgo-warn-missing-function' PATH="\$PATH:\$HOME/.cargo/bin" CARGO_NET_GIT_FETCH_WITH_CLI="true"
CIBW_ENVIRONMENT_LINUX=RUSTUP_TOOLCHAIN=$RUST_TOOLCHAIN RUSTFLAGS='-Cprofile-use=$PGO_OUT_PATH -Cllvm-args=-pgo-warn-missing-function' PATH="\$PATH:\$HOME/.cargo/bin" CARGO_NET_GIT_FETCH_WITH_CLI="true"
EOF
env:
PGO_WORK_DIR: ${{ github.workspace }}/pgo-data
PGO_OUT_PATH: ${{ github.workspace }}/merged.profdata
- uses: pypa/cibuildwheel@v2.22.0
- uses: pypa/cibuildwheel@v2.23.0
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
name: ${{ inputs.artifact-prefix }}wheels-tier-1-${{ matrix.os }}

wheels-linux-s390x:
name: "Wheels / Linux s390x"
if: (inputs.wheels-linux-s390x == 'default' && inputs.default-action || inputs.wheels-linux-s390x) == 'build'
Expand All @@ -138,7 +136,7 @@ jobs:
- uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: pypa/cibuildwheel@v2.22.0
- uses: pypa/cibuildwheel@v2.23.0
env:
CIBW_ARCHS_LINUX: s390x
CIBW_TEST_SKIP: "cp*"
Expand All @@ -161,7 +159,7 @@ jobs:
- uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: pypa/cibuildwheel@v2.22.0
- uses: pypa/cibuildwheel@v2.23.0
env:
CIBW_ARCHS_LINUX: ppc64le
CIBW_TEST_SKIP: "cp*"
Expand All @@ -170,22 +168,6 @@ jobs:
path: ./wheelhouse/*.whl
name: ${{ inputs.artifact-prefix }}wheels-linux-ppc64le

wheels-linux-aarch64:
name: "Wheels / Linux AArch64"
if: (inputs.wheels-linux-aarch64 == 'default' && inputs.default-action || inputs.wheels-linux-aarch64) == 'build'
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- uses: dtolnay/rust-toolchain@stable
- uses: pypa/[email protected]
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
name: ${{ inputs.artifact-prefix }}wheels-linux-aarch64

sdist:
name: "sdist"
if: (inputs.sdist == 'default' && inputs.default-action || inputs.sdist) == 'build'
Expand Down
2 changes: 1 addition & 1 deletion .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pull_request_rules:
actions:
backport:
branches:
- stable/1.3
- stable/1.4
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required (VERSION 3.27)
project (Qiskit)

# We are using CMake to build our C API test suite, and we leverage ctest to run
# those tests.
enable_testing ()

# The C API is provided by the qiskit_cext Rust crate. Its header gets
# generated by cbindgen (see `make cheader`). It is important that this done as
# a Release-build for cbindgen to work properly.
find_library (qiskit qiskit_cext PATHS target/release REQUIRED)

# Generally include the directory for the ``qiskit.h`` file.
include_directories (dist/c/include)

# The remaining CMake configuration is done inside of the C API test suite.
add_subdirectory (test/c)
53 changes: 52 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,53 @@ GitHub Action file. This same file may also include patches to dependencies to
make them compatible with Miri, which you would need to temporarily apply as
well.

### Testing the C API

The C API test suite is located at `test/c/`. It is built and run using `cmake`
and `ctest` which can be triggered simply via:
```bash
make ctest
```

#### Writing C API tests

The C API test suite automatically discovers any files inside `test/c/` matching
the pattern `test_*.c`. Each one of these files should follow a template similar
to the following.
```c
#include "common.h"

// Individual tests may be implemented by custom functions. The return value
// should be `Ok` (from `test/c/common.h`) when the test was successful or one
// of the other error codes (`>0`) indicating the error type.
int test_something()
{
return Ok;
}

// One main function must exist, WHOSE FUNCTION NAME MATCHES THE FILENAME!
int test_FILE_NAME()
{
// Ideally, this function should track the number of failed subtests.
int num_failed = 0;

// The RUN_TEST macro will execute the provided test function and perform a
// minimal amount of logging to indicate the success/failure of this test.
num_failed += RUN_TEST(test_something);

// Finally, this test should report the number of failed subtests.
fprintf(stderr, "=== Number of failed subtests: %i\n", num_failed);
fflush(stderr);

// And return the number of failed subtests. If this is greater than 0,
// ctest will indicate the failure.
return num_failed;
}
```

## Style and lint

Qiskit uses three tools for verify code formatting and lint checking. The
Qiskit uses three tools for Python code formatting and lint checking. The
first tool is [black](https://github.com/psf/black) which is a code formatting
tool that will automatically update the code formatting to a consistent style.
The second tool is [pylint](https://www.pylint.org/) which is a code linter
Expand Down Expand Up @@ -724,6 +768,13 @@ conform to the style guidelines. This is very similar to running `tox -eblack` f

Rust lint and formatting checks are included in the the `tox -elint` command. For CI to pass you will need both checks to pass without any warnings or errors. Note that this command checks the code but won't apply any modifications, if you need to update formatting, you'll need to run `cargo fmt`.

### C style and lint

Qiskit uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format C code.
The style is based on LLVM, with some few Qiskit-specific adjustments.
To check whether the C code conforms to the style guide, you can run `make cformat`. This check
will need to execute without any warnings or errors for CI to pass.
Automatic formatting can be applied by `make fix_cformat`.

## Building API docs locally

Expand Down
Loading

0 comments on commit 390fa85

Please sign in to comment.