catalyst.passes.pipeline

pipeline(pass_pipeline: dict[str, dict[str, str]])[source]

Configures the Catalyst MLIR pass pipeline for quantum circuit transformations for a QNode within a qjit-compiled program.

Parameters

pass_pipeline (dict[str, dict[str, str]]) – A dictionary that specifies the pass pipeline order, and optionally arguments for each pass in the pipeline. Keys of this dictionary should correspond to names of passes found in the catalyst.passes module, values should either be empty dictionaries (for default pass options) or dictionaries of valid keyword arguments and values for the specific pass. The order of keys in this dictionary will determine the pass pipeline. If not specified, the default pass pipeline will be applied.

Returns

A decorator that can be applied to a qnode.

Return type

callable

For a list of available passes, please see the catalyst.passes module.

The default pass pipeline when used with Catalyst is currently empty.

Example

pipeline can be used to configure the pass pipeline order and options of a QNode within a qjit-compiled function.

Configuration options are passed to specific passes via dictionaries:

my_pass_pipeline = {
    "cancel_inverses": {},
    "my_circuit_transformation_pass": {"my-option" : "my-option-value"},
}

@pipeline(my_pass_pipeline)
@qnode(dev)
def circuit(x):
    qml.RX(x, wires=0)
    return qml.expval(qml.PauliZ(0))

@qjit
def fn(x):
    return jnp.sin(circuit(x ** 2))

pipeline can also be used to specify different pass pipelines for different parts of the same qjit-compiled workflow:

my_pipeline = {
    "cancel_inverses": {},
    "my_circuit_transformation_pass": {"my-option" : "my-option-value"},
}

my_other_pipeline = {"cancel_inverses": {}}

@qjit
def fn(x):
    circuit_pipeline = pipeline(my_pipeline)(circuit)
    circuit_other = pipeline(my_other_pipeline)(circuit)
    return jnp.abs(circuit_pipeline(x) - circuit_other(x))

Note

As of Python 3.7, the CPython dictionary implementation orders dictionaries based on insertion order. However, for an API gaurantee of dictionary order, collections.OrderedDict may also be used.

Note that the pass pipeline order and options can be configured globally for a qjit-compiled function, by using the circuit_transform_pipeline argument of the qjit() decorator.

my_pass_pipeline = {
    "cancel_inverses": {},
    "my_circuit_transformation_pass": {"my-option" : "my-option-value"},
}

@qjit(circuit_transform_pipeline=my_pass_pipeline)
def fn(x):
    return jnp.sin(circuit(x ** 2))

Global and local (via @pipeline) configurations can coexist, however local pass pipelines will always take precedence over global pass pipelines.