catalyst.QJIT¶
- class QJIT(fn, compile_options)[source]¶
Bases:
CatalystCallableClass representing a just-in-time compiled hybrid quantum-classical function.
Note
QJITobjects are created by theqjit()decorator. Please see theqjit()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.
Attributes
LLVM IR after MLIR lowering and translation, before LLVM optimization.
The canonicalized MLIR representation of the QJIT object after lowering, if available.
The MLIR representation of the QJIT object after optimization, if available.
- llvmir¶
LLVM IR after MLIR lowering and translation, before LLVM optimization.
- 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
Methods
__call__(*args, **kwargs)Call self as a function.
aot_compile(*args, **kwargs)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 the MLIR module into a shared library.
Generate Catalyst's intermediate representation (IR) as an MLIR module.
jit_compile(args, **kwargs)Compile Python function on invocation using the provided arguments.
Perform pre-processing tasks on the Python function, such as AST transformations.
run(args, kwargs)Invoke a previously compiled function with the supplied arguments.
- aot_compile(*args, **kwargs)[source]¶
Compile Python function on initialization using the type hint signature. :param *args: positional arguments to compile the function for :param **kwargs: keyword arguments to compile the function for
- 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 the MLIR module into a shared library.
- Returns:
The compiled user function, or nothing on partial compilation.
- Return type:
CompiledFunction|None
- 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