Skip to content

Serialization API

qm.serialization.generate_qua_script.generate_qua_script

generate_qua_script(
    prog: Program, config: Optional[FullQuaConfig] = None
) -> str

Serializes a QUA program into a runnable QUA Python script.

The returned string is standalone Python source that reconstructs the given program, useful for debugging, sharing, or archiving a program.

Note

This function must be called outside of a program() scope.

Note

In some cases the serialization may be incomplete. When that happens, the generated script silently contains a SERIALIZATION WAS NOT COMPLETE comment block with the raw protobuf representation of the program. This indicates a problem in the serialization itself and should be reported to Quantum Machines.

PARAMETER DESCRIPTION
prog

The QUA program() object to serialize.

TYPE: Program

config

A QUA configuration to embed in the generated script. When omitted, the script is generated without a configuration.

TYPE: Optional[FullQuaConfig] DEFAULT: None

RETURNS DESCRIPTION
str

The generated QUA Python script as a string.

RAISES DESCRIPTION
RuntimeError

If called inside a QUA program scope, or if the given config is invalid.

qm.serialization.generate_qua_script.assert_programs_are_equal

assert_programs_are_equal(
    prog1: QuaProgram, prog2: QuaProgram
) -> None

Asserts that two QUA programs are structurally equivalent.

Both programs are first normalized with standardize_program_for_comparison, so that differences that do not affect runtime behavior (source locations, variable and stream names, result-analysis ordering) are ignored.

PARAMETER DESCRIPTION
prog1

The first program to compare.

TYPE: QuaProgram

prog2

The second program to compare.

TYPE: QuaProgram

RAISES DESCRIPTION
AssertionError

If the two programs are not structurally equivalent.