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 will be translated
to 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, OutputQVar, QVar, PHASE, allocate
from classiq import create_model, synthesize, show
@QFunc
def foo(r: QParam[float], qv: QVar[1]) -> None:
PHASE(theta=r * pi, target=qv)
@QFunc
def main(res: OutputQVar[1]) -> None:
allocate(1, res)
foo(r=1, qv=res)
foo(r=0.5, qv=res)
model = create_model(main)
qprog = synthesize(model)
show(qprog)
Note that main
outputs a single-qubit quantum variable to be sampled during
execution. The variable qv
is declared using OutputQVar[1]
and allocated
using the builtin function allocate
. foo
is then called twice, each time
applying a phase on the state.
Running the snippet above results in the following circuit:
In the rest of this section we'll explore various additional capabilities classiq
allows when creating models.