Skip to content

Python Model Editor: Creating QMOD Models Using Python

The Classiq Python package allows you to create QMOD models using Python. With Classiq you can write a collection of Python functions that are then translated into native QMOD function definitions and subsequently can be used to define a QMOD model.

The following code snippet demonstrates the usage.

from math import pi
from classiq import QFunc, QParam, Output, QBit, PHASE, allocate
from classiq import create_model, synthesize, show

def foo(r: QParam[float], qv: QBit) -> None:
    PHASE(theta=r * pi, target=qv)

def main(res: Output[QBit]) -> None:
    allocate(1, res)
    foo(r=1, qv=res)
    foo(r=0.5, qv=res)

model = create_model(main)
qprog = synthesize(model)

Note that main outputs a single-qubit quantum variable to be sampled during execution. The qv variable is declared using Output[QBit] and allocated using the built-in allocate function. foo is then called twice, each time applying a phase on the state. Running the snippet above results in the following quantum program.


The rest of this section explores additional capabilities that the Classiq package allows when creating models.