Quantum Inspire and Qiskit

Koen Martens
Qiskit
Published in
8 min readFeb 13, 2019

Last year here at QuTech we released Quantum Inspire, an on-line platform to show-case our work and enable the world to interact with quantum computing. QuTech is the advanced research center for Quantum Computing and Quantum Internet, a collaboration founded in 2014 by Delft University of Technology (TU Delft) and the Netherlands Organisation for Applied Scientific Research (TNO).

The cloud-based Quantum Inspire platform offers a graphical user interface as well as an API for more advanced use. Recently we have also released integration for IBM’s Qiskit. Quantum Inspire working in tandem with Qiskit enables users to get all the functionality and tools provided by Quantum Inspire, while also leveraging Qiskit which provides access to additional simulators, real quantum hardware and any other plugins compatible for Qiskit. All in a single development environment.

In the following paragraphs I will briefly introduce Quantum Inspire and the Qiskit integration for Quantum Inspire.

The web interface

First, let’s have a quick look at the web interface.

Quantum Inspire editor

The main interactive element in the web interface is the editor. It provides a text-window where you can enter quantum instructions using QuTech’s cQASM 1.0 syntax. The experiments can be queued for execution from the web interface, and results can be inspected once they are done.

Simulation results

You do not need to have an account to run your first experiments. However, to use more advanced features (such as retaining previous experiments and results and creating multiple projects side-by-side) registration is required. It’s as simple as entering an email address and choosing a password. After confirming your email address, your account is active and ready to use.

API and SDK, programmatic access

We also wanted to offer a more programmatic way of interacting with the platform and its backends. Of course, it is possible to talk directly to the API, but that does require the user to get into the mechanics of doing http requests and parsing responses. All that distracts from the true purpose of the system: to explore quantum computing.

Qiskit provides a rich set of primitives to interact with quantum computers and quantum simulators and abstracts the mechanics of requests and responses into a more high-level domain-specific language. Instead of re-inventing the wheel and adding yet another quantum computing framework to the world, we decided to add support to Qiskit for the Quantum Inspire backends.

Example

Let’s dive right in, and show an example of how to use the Quantum Inspire backends with Qiskit. I will assume a basic understanding of Python development in general.

If you are already familiar with Qiskit, the code below will be very recognizable. Our Qiskit integration follows the BackendProvider mechanism introduced in Qiskit 0.7.0, by offering the QuantumInspireBackendProvider. Once a backend instance has been provided, it is used the same as one would use the existing AER or IBMQ backends.

I prefer to run things in a Python virtual environment to keep dependencies from different projects separated, so let’s set that up first. You can skip this step if you don’t want to use a virtual environment, although I heartily recommend you to start using them if you don’t already). Assuming you are on a unix-based system (for example, Linux or the Windows Subsystem for Linux):

python3 -m venv env
. ./env/bin/activate

On a MS Windows based environment, one would use something like:

python3 -m venv env
env\Scripts\activate

Next, we need to install Qiskit and the Quantum Inspire SDK, which can most conveniently be done using Python’s package manager, pip:

pip install qiskit
pip install quantuminspire

This will install the latest public release versions of Qiskit and the Quantum Inspire SDK. If you are interested in the latest development version instead, you can also check out the Quantum Inspire SDK on github.

Now open your favourite editor or IDE, and create a new Python file named example_qiskit_entangle.py.

First, we start with some boilerplate and the necessary imports:

"""Example usage of the Quantum Inspire backend with the QisKit SDK.A simple example that demonstrates how to use the SDK to create a circuit to create a Bell state, and simulate the circuit on Quantum Inspire.For documentation on how to use QisKit we refer to [https://qiskit.org/](https://qiskit.org/).Specific to Quantum Inspire is the creation of the QI instance, which is used to set the authentication of the user and provides a Quantum Inspire backend that is used to execute the circuit.Copyright 2018-19 QuTech Delft. Licensed under the Apache License, Version 2.0.
"""
from getpass import getpassfrom qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.tools.compiler import execute
from quantuminspire.qiskit import QI

After some introductory documentation, we import the relevant modules from Qiskit (the QuantumRegister, ClassicalRegister and QuantumCircuit classes and the execute method). The special bit here is the last line, where we import the Quantum Inspire BackendProvider as QI.

In order to ask for credentials, we add a convenience method that will ask the user for their email and password and return these as a tuple:

def get_authentication():
"""Gets the authentication for connecting to the
Quantum Inspire API.
"""
print(‘Enter email:’)
email = input()
print(‘Enter password’)
password = getpass()
return email, password

We intend to improve on this in the near future by using API tokens that can be stored on disk to avoid having to type in the email address and password each time we run an experiment.

Now follows the main bulk of the example:

if __name__ == '__main__':
if 'authentication' not in vars().keys():
authentication = get_authentication()
QI.set_authentication_details(*authentication)
qi_backend = QI.get_backend('QX single-node simulator')

First of all, we populate the authentication tuple with email and password values. These are passed to the QI object (which is a BackendProvider) by means of the set_authentication_details method. This authenticates the backend provider with the Quantum Inspire platform.

We then obtain a Backend instance from the provider QI by asking for the backend with the name “QX single-node simulator”. If we want, we can request a list of backends from QI by calling QI.backends(). At the time of writing this, for standard users, there will be only one backend shown: the QX single-node simulator. This backend executes experiments on a cloud-hosted instance of QX simulator.

Next, we set up the quantum circuit:

    q = QuantumRegister(2)
b = ClassicalRegister(2)
circuit = QuantumCircuit(q, b)
circuit.h(q[0])
circuit.cx(q[0], q[1])
circuit.measure(q, b)

First we define a register q of 2 qubits. Next, we also define a classical register that is 2 bits wide named b to contain our measurement results. With these we create the QuantumCircuit named circuit.

The operations are then added to the circuit. We create a basic Bell-state by applying a Hadamard gate to qubit 0, followed by a Controlled-NOT where qubit 0 is the control qubit and qubit 1 is the controlled qubit. Finally, we measure both qubits and store the measurement result in the classical register.

Execution is as easy as specifying the qi_backend provided earlier to the execute function:

    qi_job = execute(circuit, backend=qi_backend, shots=256)

This will create a BaseJob instance. We can check progress of this job through the system by calling the qi_job.status() method. But for this simple example, let’s just request the result directly:

    qi_result = qi_job.result()

This will wait for the job to complete, and returns a Result object, which we can then inspect:

    histogram = qi_result.get_counts(circuit)
print(‘\nState\tCounts’)
[print(‘{0}\t{1}’.format(state, counts)) for state, counts in histogram.items()]

The full source code is included in the SDK available from the github repo.

Let’s run the example and see what the result is:

(env) ~$ python example_qiskit_entangle.py
Enter email: demo@quantum-inspire.com
Enter password Password: *********
State Counts
00 124
11 132
(env) ~$

As expected for this Bell-state, we measure an (approximately) equal number of instances of both outcomes 00 and 11.

Of course, if you prefer you can use the backend from a jupyter notebook. Two examples have been included in the SDK:

Future plans

What does the future hold?

While the ability to simulate qubits already allows us to explore the world of quantum computing, it does not offer us anything we can not do on classical computers (since the simulations by definition run on classical computers). It is the intention to add access to real quantum computers being developed at QuTech to Quantum Inspire. With the help of our unified API and Qiskit’s unified backend provider mechanism, it will be a seamless switch between simulation (on our or Qiskit’s simulators) and execution on real hardware.

The cQASM 1.0 language and QX Simulator support classical feedback. Based on the result of measuring a qubit, a subsequent single-qubit gate may execute or not. This feature is not yet exposed through the Qiskit integration, but it is high on our list to implement.

While cQASM 1.0 already contains constructs for classical feedback, it is expected that cQASM 2.0 will expand on this concept of classical-quantum interaction with a much richer expressive ability. Once the specification of this next version of cQASM solidifies we intend to integrate this into the platform. What this means for the Qiskit integration is not entirely thought-out yet, but the aim is to expose this new functionality through Qiskit as well.

Final words

We are quite excited to be able to offer access to Quantum Inspire through the popular, well-established and maturing platform that Qiskit has become over the past years. We invite everyone to try their algorithms on Quantum Inspire, and welcome all feedback, both on the Qiskit and SDK integration as well as on the platform in general.

If you have any issues with or feature requests for the SDK, please use the issue tracker on github. For comments on the web interface or general comments, feel free to send us an email at webmaster@quantum-inspire.com.

--

--

Koen Martens
Qiskit
Writer for

Senior Software Designer at Topic Embedded Systems, retired hacker, pinball wizard, nerd. Currently working as software architect at QuTech for Quantum Inspire.