catalyst.QJIT

class QJIT(fn, compile_options)[source]

Bases: CatalystCallable

Class representing a just-in-time compiled hybrid quantum-classical function.

Note

QJIT objects are created by the qjit() decorator. Please see the qjit() documentation for more details.

Parameters:
  • fn (Callable) – the quantum or classical function to compile

  • compile_options (CompileOptions) – compilation options to use

Variables:
  • original_function – This attribute stores fn, the quantum or classical function object to compile, as is, without any modifications

  • jaxpr – This attribute stores the Jaxpr compiled from the function as a string.

  • mlir – This attribute stores the MLIR compiled from the function as a string.

  • llvmir – This attribute stores the LLVM IR representation compiled from the function as a string.

llvmir

LLVMIR textual representation.

mlir

The canonicalized MLIR representation of the QJIT object after lowering, if available.

mlir_opt

The MLIR representation of the QJIT object after optimization, if available.

llvmir

LLVMIR textual representation.

mlir

The canonicalized MLIR representation of the QJIT object after lowering, if available.

The MLIR for a program can only be generated once capture and generate_ir have been run, typically via AOT or JIT compilation.

Returns:

The textual MLIR module for the QJIT object. None: If the MLIR has not yet been generated for the program.

Return type:

str

mlir_opt

The MLIR representation of the QJIT object after optimization, if available.

The optimized MLIR for a program can only be generated once capture and generate_ir have been run, typically via AOT or JIT compilation.

Returns:

The textual MLIR module after applying the QJIT object’s pipelines. None: If MLIR has not yet been generated for the program.

Return type:

str

__call__(*args, **kwargs)

Call self as a function.

aot_compile()

Compile Python function on initialization using the type hint signature.

call_with_wrapper(wrapper, call_args, ...)

Adds an additional wrapper to the wrapped function before invoking the __call__ method of this class.

capture(args, **kwargs)

Capture the JAX program representation (JAXPR) of the wrapped function.

compile()

Compile an MLIR module to LLVMIR and shared library code.

generate_ir()

Generate Catalyst's intermediate representation (IR) as an MLIR module.

jit_compile(args, **kwargs)

Compile Python function on invocation using the provided arguments.

pre_compilation()

Perform pre-processing tasks on the Python function, such as AST transformations.

run(args, kwargs)

Invoke a previously compiled function with the supplied arguments.

__call__(*args, **kwargs)[source]

Call self as a function.

aot_compile()[source]

Compile Python function on initialization using the type hint signature.

call_with_wrapper(wrapper, call_args, call_kwargs)

Adds an additional wrapper to the wrapped function before invoking the __call__ method of this class. The wrapper is expected to act like a decorator.

capture(args, **kwargs)[source]

Capture the JAX program representation (JAXPR) of the wrapped function.

Parameters:

args (Iterable) – arguments to use for program capture

Returns:

captured JAXPR PyTreeDef: PyTree metadata of the function output Tuple[Any]: the dynamic argument signature

Return type:

ClosedJaxpr

compile()[source]

Compile an MLIR module to LLVMIR and shared library code.

Returns:

the compilation result and LLVMIR

Return type:

Tuple[CompiledFunction, str]

generate_ir()[source]

Generate Catalyst’s intermediate representation (IR) as an MLIR module.

Returns:

the in-memory MLIR module and its string representation

Return type:

Tuple[ir.Module, str]

jit_compile(args, **kwargs)[source]

Compile Python function on invocation using the provided arguments.

Parameters:

args (Iterable) – arguments to use for program capture

Returns:

whether the provided arguments will require promotion to be used with the compiled

function

Return type:

bool

pre_compilation()[source]

Perform pre-processing tasks on the Python function, such as AST transformations.

run(args, kwargs)[source]

Invoke a previously compiled function with the supplied arguments.

Parameters:
  • args (Iterable) – the positional arguments to the compiled function

  • kwargs – the keyword arguments to the compiled function

Returns:

results of the execution arranged into the original function’s output PyTrees

Return type:

Any