Compiling a QGL2 Rabi SingleShot and plotting the output

In [ ]:
from pyqgl2.main import compile_function, qgl2_compile_to_hardware
from pyqgl2.test_cl import create_default_channelLibrary
from pyqgl2.qreg import QRegister
from QGL import plot_pulse_files, ChannelLibrary

In [ ]:
# Compile to hardware or just to QGL pulse sequence?
toHW = False
# Create a test library (or load one)
create_default_channelLibrary(toHW, True)

Compile QGL2 to QGL1

To turn on debug output, uncomment the next 4 lines

In [ ]:
# from pyqgl2.ast_util import NodeError
# from pyqgl2.debugmsg import DebugMsg

# DebugMsg.set_level(1)

Generate a list of the arguments to the QGL2 function

In [ ]:
qr = QRegister('q1')

In [ ]:
# Insert proper path to QGL2 source and name of qgl2main if not so marked
# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function
# True argument means save the QGL1 compiled function to a file
qgl1MainFunc = compile_function("../src/python/qgl2/basic_sequences/", "SingleShot", args, saveOutput=True)

Generate pulse sequences

In [ ]:
# Now run the QGL1 function, producing a list of sequences
# QGL2 to QGL1 compiled functions take no arguments
seqs = qgl1MainFunc()

Optional: Enable debug logging in compiler

In [ ]:
# import logging
# from QGL.Compiler import set_log_level
# # By default, uses custom log format at DEBUG
# set_log_level(loggerName='QGL.Compiler', levelDesired=logging.DEBUG)

Optionally compile to machine instructions

In [ ]:
if toHW:
    metaFileName = qgl2_compile_to_hardware(seqs, "SingleShot/SingleShot")
    print(f"Generated sequence details in '{metaFileName}'")
    # Plot the sequences
    from QGL.Scheduler import schedule
    from IPython.lib.pretty import pretty