autoqasm.types.deferred module

Deferred variable wrappers for lazy promotion of Python values to QASM variables.

These wrappers subclass Python’s numeric types (float, int) so they behave as plain literals when used as gate parameters, but lazily promote to oqpy variables when combined with QASM expressions via arithmetic or comparison operators.

class autoqasm.types.deferred.DeferredVarMixin[source]

Bases: object

Mixin that lazily promotes a Python numeric value to an oqpy variable when combined with a QASM expression. When used as a gate parameter the value remains a literal.

get_or_create_var()[source]

Return the promoted oqpy variable, creating it on first call.

class autoqasm.types.deferred.DeferredFloat(value, name)[source]

Bases: DeferredVarMixin, float

A Python float that lazily promotes to an oqpy FloatVar.

class autoqasm.types.deferred.DeferredInt(value, name)[source]

Bases: DeferredVarMixin, int

A Python int that lazily promotes to an oqpy IntVar.

autoqasm.types.deferred.make_deferred(value: Any, name: str) Any[source]

Wrap a plain Python value in a deferred wrapper that lazily promotes to a QASM variable when used in QASM expressions.

Returns the original value unchanged if it cannot be deferred.