Executing quantum programs

This framework provides Quantum Processing Units (QPU) to execute any quantum job. Our QPUs are listed in the qat.qpus module. Quantum Circuit, Schedule, etc. must be lifted into a quantum Job by using their to_job() method to be executable on the QPU. The job object (detailed in the job section) contains additional information, such as:

  • number of shots

  • what should be measures (sampling, observable)

  • etc.

A job can be submitted to a QPU by:

  • calling the submit() method of the selected QPU

  • calling the run() method of the job (this method takes the selected QPU in argument, if no QPU is specified, the default QPU is selected)

A job can be executed using the submit() method of the selected QPU

from qat.qpus import get_default_qpu
from qat.lang import qrout, H, CNOT

@qrout
def bell_pair():
    H(0)
    CNOT(0, 1)

job = bell_pair.to_job()
result = get_default_qpu().submit(job)

for sample in result:
    print(f"{sample.state}: {sample.probability}")
|00>: 0.4999999999999999
|11>: 0.4999999999999999

A job can be executed using the run() method

from qat.lang import qrout, H, CNOT

@qrout
def bell_pair():
    H(0)
    CNOT(0, 1)

job = bell_pair.to_job()
result = job.run()  # Use default QPU

for sample in result:
    print(f"{sample.state}: {sample.probability}")
|00>: 0.4999999999999999
|11>: 0.4999999999999999

The QPU can be selected using a Python context

from qat.qpus import CLinalg
from qat.lang import qrout, H, CNOT

@qrout
def bell_pair():
    H(0)
    CNOT(0, 1)

job = bell_pair.to_job()

with CLinalg():
    result = job.run()

for sample in result:
    print(f"{sample.state}: {sample.probability}")
|00>: 0.4999999999999999
|11>: 0.4999999999999999

Any QPU of this framework can be extended using plugins. A plugin will extend the capabilities of a QPU, and can be used, for instance:

  • to compile jobs before running them on the QPU - the extended QPU won’t have any gate set limitation, topology limitation, etc.

  • to support variational computing

  • etc.

This framework provides plugins to support Variational computing, such as ScipyMinimizePlugin. This plugin tries to minimize the average value of the observable

A job can be executed using the submit() method of the selected QPU

from qat.qpus import get_default_qpu
from qat.plugins import ScipyMinimizePlugin
from qat.lang import qrout, RX
from qat.core import Observable

@qrout
def circuit(theta):
    RX(theta)(0)

job = circuit.to_job(observable=Observable.z(0))
qpu = ScipyMinimizePlugin() | get_default_qpu()
result = qpu.submit(job)

print("Average value:", result.value)
print("Angles:", result.parameter_map)
Average value: -1.0
Angles: {'theta': 3.1415926450772336}

A job can be executed using the run() method

from qat.plugins import ScipyMinimizePlugin
from qat.lang import qrout, RX
from qat.core import Observable

@qrout
def circuit(theta):
    RX(theta)(0)

job = circuit.to_job(observable=Observable.z(0))

with ScipyMinimizePlugin():
    result = job.run()

print("Average value:", result.value)
print("Angles:", result.parameter_map)
Average value: -0.9999999999994693
Angles: {'theta': 3.1415916234142305}