Getting started
Installation
For now, we support Python versions 3.9 to 3.11, and all of Windows, Linux and MacOS (specifically, Linux was validated on Ubuntu LTS 20.04, while Ubuntu 18.04 is not supported, so your milage may vary).
To install mpqp, you can run in a terminal
$ pip install mpqp
And if you have already a previous version and want to update to the latest version, run instead
$ pip install -U mpqp
Note
For Mac users, additional steps are required before installation,
specifically because of the myqlm
library. To run these steps, you can
either follow their instructions on
this page
or run the script we created to facilitate this step:
$ curl -L https://raw.githubusercontent.com/ColibrITD-SAS/mpqp/main/mac-install.sh | bash -s -- <your-python-bin>
where <your-python-bin>
is the binary you use to invoke python. For instance, it could
be python
, python3
, or python3.9
.
Warning
The migration from qiskit
version 0.x
to 1.x
caused a few issues.
In case you had a qiskit 0.x
environment, you might encounter an error
such as
ImportError: Qiskit is installed in an invalid environment that has both Qiskit >=1.0 and an earlier version...
To fix this, we provide a script you can run that will fix your environment. In a terminal, simply run.
$ update_qiskit
Alternatively, if you want to keep your old qiskit environment, you can also create a new virtual environment.
Your first circuit
A circuit is created by providing QCircuit
with a list of Instruction
(gates and measurements). To run a circuit, you can then use the
run()
function.
>>> from mpqp import QCircuit
>>> from mpqp.gates import X, CNOT
>>> from mpqp.measures import BasisMeasure
>>> from mpqp.execution import run, IBMDevice
>>> circuit = QCircuit([X(0), CNOT(0, 1), BasisMeasure([0, 1], shots=100)])
>>> print(circuit)
┌───┐ ┌─┐
q_0: ┤ X ├──■──┤M├───
└───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
└───┘ ║ └╥┘
c: 2/═══════════╩══╩═
0 1
>>> print(run(circuit, IBMDevice.AER_SIMULATOR))
Result: IBMDevice, AER_SIMULATOR
Counts: [0, 0, 0, 100]
Probabilities: [0, 0, 0, 1]
Samples:
State: 11, Index: 3, Count: 100, Probability: 1
Error: None
Set up remote accesses
Installing MPQP gives you access to setup_connections
, a script facilitating
the setup of remote QPU connections. The supported providers (Qiskit,
Qaptiva, Braket, Azure and IonQ) can be set up from this script.
To run the script, simply run the following command in your terminal:
$ setup_connections
Each of these providers has their own set of data needed to set up the connection, detailed up in subsections below.
To see which devices are available, checkout the Devices section.
IBM Quantum (Qiskit)
For this provider, you only need your account API token
, which you can find on your
account page. The token will be configured once for all users.
Atos/Eviden (QLM/Qaptiva)
For this provider, several connection methods exist. For now, we only support the username/password method. You should have received you username and password by email.
AWS Braket
For configuring access to AWS Braket, you first need to have awscli
installed on your machine. To check if it is
already installed, you can run this command:
$ aws --version
For
Windows
, installingmpqp
can be sufficient since the Python packageaws-configure
(in the requirements) also installsawscli
locally. If it is not the case, you can execute the following command (in a terminal where you have admin access) to installawscliV2
:> msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
For
MacOS
, on some versions, the installation ofaws-configure
can be sufficient. If it is not the case, you can install it usingbrew
:$ brew install awscli
or execute the script we prepared for installing
awscliv2
:$ ./mpqp/mpqp_scripts/awscli_installation/mac_awscli_install.sh
For
Linux
, one can use the dedicated script for installingawscliv2
:$ ./mpqp/mpqp_scripts/awscli_installation/linux_awscli_install.sh
Amazon Web Services propose two different ways to authenticate for access remote services (including remote
simulators and QPUs via Braket): the IAM
authentication, and the SSO
one. When you run the setup_connections
script and select AWS configuration, you will have to choose between one of the two above.
- IAM: All the necessary credentials can be found in your AWS console.
In the console, go to
IAM
. In theUsers
tab, click on your username. In theSecurity credential
tab, you’ll find anAccess keys
section. In this section, you can create a new access key forMPQP/Braket
(with “Local code” or “Third-party service” as usecase), or use an existing one. You should save the secret access key because you will not be able to recover it later. This will give you your key and your secret, but for the configuration, you also need to input a region (for exampleus-east-1
). In short, when runningsetup_connections
, it will execute theaws configure
command that will ask you the following credentials:AWS Access Key ID
,AWS Secret Access Key
,Default region name
.
- SSO: Standing for “Single-Sign-On”, SSO enables organizations to simplify and strengthen password security by giving
access to all connected services with a signe login. It is the recommended way to authenticate to Amazon Web Services. To recover your SSO credentials, you have to follow the
SSO start url
provided by your AWS administrator, (for example https://d-4859u1689s.awsapps.com/start ).You will need you username and password attached (and potentially MFA) to login. Then, in the
AWS Access Portal
, you can find the different sso sessions and profile associated with your company account. Click on theAccess key
(with the key symbol) to retrieve your SSO credentials. When runningsetup_connections
, you will be asked for:AWS Access Key ID
,AWS Secret Access Key
,AWS Session Token
,Default region name
.
Microsoft Azure
For this provider, you need to have an Azure account and create an
Azure Quantum workspace. To create an Azure Quantum workspace, follow the
steps on:
Azure Quantum workspace.
Once you have your Quantum workspace, you can go to the Overview
section,
where you will find your Resource ID
and Location
.
You might encounter a pop-up requesting Azure authentication for each Azure job submission. This occurs because your security token is reset at the end of each session. In order to avoid this, you can use the Azure CLI.
First, install the Azure CLI: refer to the guide on their website How to install the Azure CLI.
Next, log in to Azure:
Using interactive login:
$ az login
For username and password authentication (note that this method doesn’t work with Microsoft accounts or accounts with two-factor authentication):
$ az login -u [email protected] -p=VerySecret
For additional details and options, see the documentation of az login.
IonQ (Cirq)
- For this provider, you need to have an IonQ account and create an
API token
. You can obtain it from the IonQ Console under IonQ setting keys.
Execute examples
A few examples are provided in the examples
folder of the repo. To try them
out, you can either download them individually from our GitHub repository or clone the repository and
execute them as follows:
$ python -m examples.scripts.bell_pair
$ python -m examples.scripts.demonstration
$ python -m examples.scripts.observable_job
For more information, please refer to the notebook page.