# Using the SDK

The PlanQK Quantum SDK provides an easy way for developing quantum circuits using Qiskit (opens new window) to be run on quantum devices provided by the PlanQK Platform (opens new window). The SDK is an extension for the Qiskit 1.0 SDK (opens new window) and provides the same functionality and syntax as well as some PlanQK specific commands.

# Installation

You need to have Python 3.10 or higher installed. The package is released on PyPI and can be installed via pip:

pip install --upgrade planqk-quantum
1

NOTE

Ensure that you have versions older than Qiskit SDK 1.0 uninstalled before installing the PlanQK Quantum SDK. The best way to ensure this is to create a new virtual environment and install the PlanQK Quantum SDK there.

# Execute your first circuit

In your Qiskit code you can access the PlanQK quantum backends through the PlanqkQuantumProvider class. Import the class and instantiate it as shown below:

from planqk.qiskit import PlanqkQuantumProvider
1

If you are already logged in with the PlanQK CLI you can create the provider object without any parameters:

provider = PlanqkQuantumProvider()
1

Alternatively, you can also create the provider object by passing your PlanQK personal access token:

provider = PlanqkQuantumProvider(access_token="your-access-token")
1

If you want to login with your organization, you can additionally pass the organization id as a parameter. The organization id can be found in the organization settings on the PlanQK Platform:

provider = PlanqkQuantumProvider(access_token="your-access-token", organization_id="your-organization-id")
1

After you have created the provider object you can list all backends supported by the PlanQK Platform and select the one you want to use. The available backends and their names can be also found here, e.g., the azure.ionq.simulator backend:

# list all available PlanQK quantum backends
backends = provider.backends()

# select a certain backend
backend = provider.get_backend(name="azure.ionq.simulator")
1
2
3
4
5

Now you can execute your Qiskit circuit on the selected backend, retrieve its job object, retrieve its results, cancel it etc. The full example would look like this:

from planqk.qiskit import PlanqkQuantumProvider

from qiskit.circuit import QuantumCircuit, transpile

# instantiate the PlanQK provider and select a backend
provider = PlanqkQuantumProvider()
backend = provider.get_backend(name="azure.ionq.simulator")

# create a qiskit circuit
circuit = QuantumCircuit(3, 3)
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(1, 2)
circuit.measure(range(3), range(3))

# transpile circuit for backend
circuit = transpile(circuit, backend)
# execute circuit on selected backend
job = backend.run(circuit, shots=1000)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

NOTE

Executing your Qiskit code on the PlanQK platform may lead to execution costs depending on selected backend and number of shots. Please find an overview about the costs for each backend on our pricing page (opens new window).

# Deploy your circuit as a PlanQK Service

To deploy your circuit to the PlanQK Platform you may adapt the program.py file of the python-starter template.

NOTE

To create a new development project, you may run planqk init and select Starter Qiskit as coding template. Further instructions are available here.

The program.py file contains a run() method which is called when the service is executed. Copy and paste the code from above into the run() method and add the following line at the end of the function:

return ResultResponse(result={"status": "COMPLETED"})
1

You may want to add some additional information to the ResultResponse object, e.g., the actual results of your circuit. You are now able to deploy your circuit as a PlanQK Service.

Use planqk up to deploy your service to the PlanQK Platform. Next, you may use planqk run to execute your service.

# What's next?