Cette page n'a pas encore été traduite. Vous voyez la version originale en anglais.
Install the new Qiskit 1.0 package
Qiskit 1.0 uses a different packaging structure than previous Qiskit versions and will likely cause problems in environments that use packages that are not ready for Qiskit 1.0.
Do not try to upgrade an existing Python virtual environment to Qiskit 1.0 in-place.
We will not make similar breaking packaging changes in the future. This is a one-time event, at the release of Qiskit 1.0, specifically so that our packaging story will be as easy as possible in the future.
This guide is divided into the following sections. You only need to review the sections that are relevant to you.
- Users should read the For users section.
- If you develop or maintain a package that depends on Qiskit, read the For developers section.
- If you encounter problems installing or importing Qiskit 1.0, review the Troubleshooting section.
If you are interested in understanding the old package structure and why it changed, review the overview of the breaking package changes.
For users
You must start a new virtual environment to install Qiskit 1.0. It is very tricky and error-prone to upgrade an existing installation in-place to Qiskit 1.0.
The examples in this section use the venv module that is part of the Python standard library.
If you use a different tool, such as virtualenv or conda, consult its documentation for help.
For Linux and macOS commands, a bash-like syntax is used. PowerShell is used for Windows commands.
Create the new environment
-
Create a new virtual environment in each project directory you're working in, using your preferred version of Python 3.8 or later.
- macOS
- Linux
- Windows
python3 -m venv .venvpython3 -m venv .venvpython -m venv .venv
-
Activate the environment.
- macOS
- Linux
- Windows
source .venv/bin/activatesource .venv/bin/activate.venv\Scripts\activate.ps1 -
Install packages as desired. You should do this by using only one
pip installcommand with all the dependencies on it.pip install 'qiskit>=1'You can optionally include additional packages by including them as arguments. For example:
pip install 'qiskit>=1' jupyterlab pandas matplotlibQiskit 1.0 includes breaking changes, so several packages are marked as not-yet-compatible with it. Therefore, you might see errors from
pipuntil new versions of those packages are released. Old versions of packages might also depend on the legacyqiskit-terrapackage. Such packages might not return errors when running this command, but might raise an error when runningimport qiskit. You should not install any packages that depend directly onqiskit-terra.conseilOne way to require
pipto forbidqiskit-terrafrom individualinstallcommands is to use a constraints file that requires thatqiskit-terrais set to an impossible version. For example, a constraints file that includes the lineqiskit-terra>=1.0will mean that if a dependency attempts to installqiskit-terra, no published versions will match the requirements.We have provided such a file in a GitHub Gist at https://qisk.it/1-0-constraints, which you can use like this:
pip install -c https://qisk.it/1-0-constraints qiskit [other packages]If a package requires
qiskit-terra, you will see a resolution failure.attentionDo not install packages that are incompatible with Qiskit 1.0 on this virtual environment. If you need to use such packages, install them in a separate virtual environment with Qiskit 0.45 or 0.46.
If you have an existing environment, you can use
pipdeptreeto query the requirements of your installed packages to see if they requireqiskit<1. For any that requireqiskit<1, check for updates that make it compatible with Qiskit 1.0.If you encounter issues, consult the troubleshooting section, or ask on Qiskit Slack. If you think there is a bug, you can create an issue against Qiskit.
-
If you are not planning to use the environment immediately, use the
deactivatecommand to leave it.
Use the new environment
Each time you start a new command line session, you must navigate to your project directory and "activate" the environment by running the activate command:
- macOS
- Linux
- Windows
source .venv/bin/activate
source .venv/bin/activate
.venv\Scripts\activate.ps1
For developers
If you maintain a package that depends on Qiskit, use this information to learn how to correctly express your compatibility and test against Qiskit 1.0.
Recommendations for requirements
We recommend that your package requires qiskit>=0.45,<1 (or other appropriate lower bound) if you are not certain whether the package is compatible with Qiskit 1.0.
This is the same recommendation being made for NumPy 2.0 compatibility.
A Qiskit 1.0 release candidate, version 1.0.0rc1, will be released on 1 February 2024. You should test your package against this, and as soon as possible, release a new (compatible) version of your package with its upper requirement unpinned.
Recommendations for testing against Qiskit 1.0
These recommendations apply to testing proactively against the Qiskit main branch, and to testing against the 1.0.0rc1 (and later, if applicable) release candidate.
We do not recommend initially branch-protecting on CI success against the Qiskit main branch because Qiskit changes could prevent you from merging PRs.
After the release of Qiskit release candidates, and after all of your package's dependencies support Qiskit 1.0, we do recommend branch-protecting on success against the latest release candidate, to ensure that the package remains compatible with Qiskit 1.0.
If neither your package, nor any of its transitive dependencies, has a requirement pin on qiskit<1, you should create a testing virtual environment as you normally would, in a single pip install command, and directly specify qiskit==1.0.0rc1 or qiskit==git+https://github.com/Qiskit/qiskit.git@main as appropriate.
This is the most reliable way to ensure that you have a completely valid environment.
If the only component of your package's dependency graph that has a requirement pin on qiskit<1 is your own package, you might want to have your CI suite first temporarily patch your requirements file to allow Qiskit 1.0, and then install the environment in a single step as before.
Alternatively, use the following rules for general-purpose environment upgrades, but switch to single-environment resolution as soon as feasible.
If at least one of your transitive dependencies does not yet have a release version that allows Qiskit 1.0 support, you must make manual changes. There are several strategies to try, in approximate order of preference (most preferable to least):
- Install the problematic dependency from its own
mainbranch, if its development version has relaxed the pin, so you can build the test environment in a single step. - Exclude the use of that dependency from the test environment, if possible.
- Create a test environment in the same way you would normally, and then manually override it to use Qiskit 1.0.
Manually upgrade an existing environment
This process deliberately creates an invalid environment. Therefore, any test using it is less valid. Tests might appear to pass, but this does not guarantee that the package is compatible with Qiskit 1.0. This could happen because the environment is not self-consistent and could contain files that do not exist in a valid environment, or the behavior of an overridden package might change with Qiskit 1.0.
If one of your dependencies pins qiskit<1 even on their development branch, it might not work in any way with Qiskit 1.0, and if your tests cannot run because of this, you might have to wait for them (or work with them) to become compatible.
To upgrade an environment in situ, follow these steps:
-
Create an environment as usual, ensuring that there are no packages that extend the
qiskitorqiskit.providersnamespace installed. -
Uninstall both
qiskitandqiskit-terrato make sure that neither is present:
pip uninstall --yes qiskit qiskit-terra
At this point, the environment's site-packages should not contain a qiskit directory. You don't need to verify this on every CI run, but if you are debugging a script locally, follow these steps to verify:
- Run the following command from within the
pythonof the virtual environment:
import site
print(site.getsitepackages())
-
Verify that those directories do not contain a
qiskitdirectory. If they do, you likely have namespace-extending packages installed, and you should find these and remove the dependency. -
Install the target version of Qiskit 1.0 with one of these commands:
- After the desired release candidate has been published:
pip install 'qiskit==1.0.0rc1' - For a
main-branch dependency (or substitute whatevergitrevision identifier you prefer after the@).pip install 'git+https://github.com/Qiskit/qiskit.git@main'
You now have an environment that Qiskit allows you to test in. If import qiskit results in an ImportError, or if you are struggling to find your dependencies, see the advice in the section about the invalid-environment protections in Qiskit.
Sample manual GitHub Actions workflows
The following workflows set up a scheduled job to run overnight. This job sets up a testing environment for Qiskit 1.0 and runs pytest (or whatever test steps you need).
For a package that has no transitive dependencies qiskit<1:
on:
schedule:
- cron: '0 3 * * *'
jobs:
test_main:
name: Test Qiskit main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Create environment
run: |
set -e
# First ensure the standard tools are up-to-date.
python -m pip install --upgrade pip wheel setuptools
# Note that this resolves everything in a single command.
# If it fails, at least one package likely requires `qiskit<1`.
python -m pip install --upgrade \
-c constraints.txt \
-r requirements-dev.txt \
. \
'git+https://github.com/Qiskit/qiskit.git@main'
- name: Run tests
run: pytest
For a package that has unavoidable transitive dependencies that pin qiskit<1, build an invalid environment:
on:
schedule:
- cron: '0 3 * * *'
jobs:
test_main:
name: Test Qiskit main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Create environment
run: |
set -e
python -m pip install --upgrade pip wheel setuptools
# Install the regular test environment.
python -m pip install --upgrade \
-c constraints.txt \
-r requirements-dev.txt \
.
# Uninstall `qiskit` and `qiskit-terra`.
python -m pip uninstall --yes qiskit qiskit-terra
# Install the new version of Qiskit
python -m pip install 'git+https://github.com/Qiskit/qiskit.git@main'
- name: Run tests
run: pytest