Python Model Editor: Creating QMOD models using Python¶
classiq python package allows you to create QMOD models using Python.
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) -> None: PHASE(theta=r * pi, target=qv) @QFunc def main(res: OutputQVar) -> None: allocate(1, res) foo(r=1, qv=res) foo(r=0.5, qv=res) model = create_model(main) qprog = synthesize(model) show(qprog)
main outputs a single-qubit quantum variable to be sampled during
execution. The variable
qv is declared using
OutputQVar and allocated
using the builtin function
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
allows when creating models.