Skip to main content

CLI for executing quantum circuits

Project description

CI badge Release badge

Cortex CLI

Command-line interface (CLI) for interacting with an IQM quantum computer.

Installing Cortex CLI

Requirements for installing:

  • Python 3.9

  • pip

$ pip install iqm-cortex-cli

Using Cortex CLI

For general usage instructions, run

$ cortex --help

Initialization

First, Cortex CLI needs initialization, which produces a configuration file:

$ cortex init

Cortex CLI will ask a few questions. You can also pass the values via command line to avoid having an interactive prompt. See cortex init --help for details.

Login

To log in, use

$ cortex auth login

This will ask you to enter your username and password.

After a successful authentication, tokens will be saved into a tokens file (path specified in the configuration file), and a token manager daemon will start in the background. Token manager will periodically refresh the session and re-write the tokens file. To login and get tokens once, without starting a token manager daemon, run cortex auth login --no-daemon.

If the tokens file already exists, then running cortex auth login will first attempt to refresh the session without asking you for a username and password. If that fails (because existing tokens may already have expired), you’ll be asked to re-enter your credentials.

See cortex auth login --help for more details.

Status

To see the current status of the token manager daemon, use:

$ cortex auth status

If the tokens file exists, cortex auth status will report whether the corresponding token manager daemon is running. It will also print the time of the last successful refresh request, and how much time is left until current tokens expire.

See cortex auth status --help for more details.

Logout

To log out, run

$ cortex auth logout

This will send a logout request to the authentication server, kill the token manager daemon (if any), and delete the tokens file.

You may want to stop the token manager, but maintain the session on the server and keep the tokens file intact. To do so, run:

$ cortex auth logout --keep-tokens

See cortex auth logout --help for more details.

Multiple configuration files

By default, all Cortex CLI commands read the configuration file from the default location ~/.config/iqm-cortex-cli/config.json. You can specify a different filepath by providing the --config-file value, for example:

$ cortex auth status --config-file /home/joe/config.json
$ cortex auth login --config-file /home/joe/config.json
$ cortex auth logout --config-file /home/joe/config.json

Circuit validation

$ cortex circuit validate my_circuit.qasm

validates the quantum circuit in file my_circuit.qasm, and reports errors if the circuit is not valid OpenQASM 2.0. The exit code is 0 if and only if the circuit is valid.

Executing circuits on a quantum computer

You can execute a quantum circuit on an IQM quantum computer with

$ export IQM_SERVER_URL="https://example.com/iqm-server"
$ cortex circuit run --settings "path/to/settings.json" --shots 100 --qubit-mapping my_qubit_mapping.json my_circuit.qasm

The server URL and settings path can be set either with command-line options or as environment variables.

By default, authentication is handled the same way as with other Cortex CLI commands. You can override this and provide your own server URL, username, and password by setting environment variables IQM_AUTH_SERVER, IQM_AUTH_USERNAME and IQM_AUTH_PASSWORD.

Note that the circuit needs to be transpiled so that it only contains operations natively supported by the IQM quantum computer you are using.

For information on all the parameters and their usage, run

$ cortex circuit run --help

The results of the measurements in the circuit are returned in JSON format:

{"measurement_0":
  [
    [1, 0, 1, 1],
    [1, 0, 0, 1],
    [1, 0, 1, 1]
  ]
}

The dictionary keys are measurement keys from the circuit. The value for each measurement is a 2-D array of binary integers. The first index goes over the shots, and the second over the qubits in the measurement. For example, in the example above, “measurement_0” is a 4-qubit measurement, and the number of shots is three.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iqm-cortex_cli-0.5.tar.gz (656.4 kB view hashes)

Uploaded Source

Built Distribution

iqm_cortex_cli-0.5-py3-none-any.whl (20.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page