Skip to content

Commit

Permalink
Daily rc sync to main (#1447)
Browse files Browse the repository at this point in the history
Automatic sync from the release candidate to main during a feature
freeze.

---------

Co-authored-by: erick-xanadu <[email protected]>
Co-authored-by: Raul Torres <[email protected]>
Co-authored-by: Mehrdad Malek <[email protected]>
Co-authored-by: Joey Carter <[email protected]>
Co-authored-by: David Ittah <[email protected]>
Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: paul0403 <[email protected]>
Co-authored-by: Ritu Thombre <[email protected]>
Co-authored-by: Ritu Thombre <[email protected]>
Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Sengthai Heng <[email protected]>
Co-authored-by: GitHub Actions Bot <>
  • Loading branch information
13 people authored Jan 13, 2025
1 parent c1a422c commit 0ef8e42
Show file tree
Hide file tree
Showing 41 changed files with 1,027 additions and 1,717 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build-wheel-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,10 @@ jobs:
- name: Install Python dependencies
run: |
python${{ matrix.python_version }} -m pip install pytest pytest-xdist pytest-mock
# During the 0.10.0 release cycle we discovered that having exactly 2700 test items distributed on
# exactly 3 cores (e.g. GH M1 runner) produces a lot of test failures. Randomizing the test order
# (pytest-randomly) fixes the issue for now.
python${{ matrix.python_version }} -m pip install pytest pytest-xdist pytest-mock pytest-randomly
- name: Install PennyLane Plugins
run: |
Expand All @@ -462,7 +465,7 @@ jobs:
run: |
python${{ matrix.python_version }} -m pytest frontend/test/pytest -n auto
python${{ matrix.python_version }} -m pytest frontend/test/pytest --backend="lightning.kokkos" -n auto
python${{ matrix.python_version }} -m pytest frontend/test/async_tests
python${{ matrix.python_version }} -m pytest frontend/test/async_tests -p no:randomly
python${{ matrix.python_version }} -m pytest frontend/test/pytest --runbraket=LOCAL -n auto
python${{ matrix.python_version }} -m pytest frontend/test/test_oqc/oqc -n auto
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-catalyst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ jobs:
echo "OQC_LIB_DIR=$(pwd)/oqc-build" >> $GITHUB_ENV
echo "OQD_LIB_DIR=$(pwd)/oqd-build" >> $GITHUB_ENV
echo "CATALYST_BIN_DIR=$(pwd)/quantum-build/bin" >> $GITHUB_ENV
chmod +x $(pwd)/quantum-build/bin/catalyst-cli # artifact upload does not preserve permissions
chmod +x $(pwd)/quantum-build/bin/catalyst # artifact upload does not preserve permissions
- name: Run Python Lit Tests
run: |
Expand Down Expand Up @@ -559,7 +559,7 @@ jobs:
echo "MLIR_LIB_DIR=$(pwd)/llvm-build/lib" >> $GITHUB_ENV
echo "OQD_LIB_DIR=$(pwd)/oqd-build" >> $GITHUB_ENV
echo "CATALYST_BIN_DIR=$(pwd)/quantum-build/bin" >> $GITHUB_ENV
chmod +x $(pwd)/quantum-build/bin/catalyst-cli # artifact upload does not preserve permissions
chmod +x $(pwd)/quantum-build/bin/catalyst # artifact upload does not preserve permissions
- name: Run Python Pytest Tests (backend=lightning.kokkos)
run: |
Expand Down Expand Up @@ -616,7 +616,7 @@ jobs:
echo "RUNTIME_LIB_DIR=$(pwd)/runtime-build/lib" >> $GITHUB_ENV
echo "MLIR_LIB_DIR=$(pwd)/llvm-build/lib" >> $GITHUB_ENV
echo "CATALYST_BIN_DIR=$(pwd)/quantum-build/bin" >> $GITHUB_ENV
chmod +x $(pwd)/quantum-build/bin/catalyst-cli # artifact upload does not preserve permissions
chmod +x $(pwd)/quantum-build/bin/catalyst # artifact upload does not preserve permissions
- name: Run Python Pytest Tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-pl-compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
echo "RUNTIME_LIB_DIR=$(pwd)/runtime-build/lib" >> $GITHUB_ENV
echo "MLIR_LIB_DIR=$(pwd)/llvm-build/lib" >> $GITHUB_ENV
echo "CATALYST_BIN_DIR=$(pwd)/quantum-build/bin" >> $GITHUB_ENV
chmod +x $(pwd)/quantum-build/bin/catalyst-cli # artifact upload does not preserve permissions
chmod +x $(pwd)/quantum-build/bin/catalyst # artifact upload does not preserve permissions
- name: Run Frontend Tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ wheel:
cp $(COPY_FLAGS) $(DIALECTS_BUILD_DIR)/python_packages/quantum/mlir_quantum/dialects/*$${file}* $(MK_DIR)/frontend/mlir_quantum/dialects ; \
done
mkdir -p $(MK_DIR)/frontend/catalyst/bin
cp $(COPY_FLAGS) $(DIALECTS_BUILD_DIR)/bin/catalyst-cli $(MK_DIR)/frontend/catalyst/bin
cp $(COPY_FLAGS) $(DIALECTS_BUILD_DIR)/bin/catalyst $(MK_DIR)/frontend/catalyst/bin
find $(MK_DIR)/frontend -type d -name __pycache__ -exec rm -rf {} +

$(PYTHON) -m pip wheel --no-deps . -w dist
Expand Down
42 changes: 21 additions & 21 deletions doc/catalyst-cli/catalyst-cli.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Catalyst Command Line Interface
===============================

Catalyst includes a standalone command-line-interface compiler tool ``catalyst-cli`` that
Catalyst includes a standalone command-line tool, ``catalyst``, that
compiles quantum programs written in our MLIR dialects into an object file,
independent of the Catalyst Python frontend.

Expand All @@ -13,47 +13,47 @@ This compiler tool combines three stages of compilation:
`LLVM IR <https://llvm.org/docs/LangRef.html>`_.
#. ``llc``: Performs lower-level optimizations on the LLVM IR input and creates the object file.

``catalyst-cli`` runs all three stages under the hood by default, but it also has the ability to run
each stage individually. For example:
The ``catalyst`` tool will run all three stages under the hood by default, but it also has the
ability to run each stage individually. For example:

.. code-block:: console
# Creates both the optimized IR and an object file
catalyst-cli input.mlir -o output.o
catalyst input.mlir -o output.o
# Only performs MLIR optimizations and translates to LLVM dialect
catalyst-cli --tool=opt input.mlir -o llvm-dialect.mlir
catalyst --tool=opt input.mlir -o llvm-dialect.mlir
# Only lowers LLVM dialect input to LLVM IR
catalyst-cli --tool=translate llvm-dialect.mlir -o llvm-ir.ll
catalyst --tool=translate llvm-dialect.mlir -o llvm-ir.ll
# Only performs lower-level optimizations and creates object file (object.o)
catalyst-cli --tool=llc llvm-ir.ll -o output.ll --module-name object
catalyst --tool=llc llvm-ir.ll -o output.ll --module-name object
.. note::

If Catalyst is built from source, the ``catalyst-cli`` executable will be located in
If Catalyst is built from source, the ``catalyst`` executable will be located in
the ``mlir/build/bin/`` directory relative to the root of your Catalyst source directory.

If Catalyst is installed via pip or from wheels, the executable will be located
in the ``catalyst/bin/`` directory relative to the environments installation directory.
If Catalyst is installed via pip or from wheels, the executable will be located
in the ``catalyst/bin/`` directory relative to the environment's installation directory.

Usage
-----

.. code-block:: console
catalyst-cli [options] <input file>
catalyst [options] <input file>
Calling ``catalyst-cli`` without any options runs the three compilation stages (``quantum-opt``,
Calling ``catalyst`` without any options runs the three compilation stages (``quantum-opt``,
``mlir-translate`` and ``llc``) using all default configurations, and outputs by default an object
file named ``catalyst_module.o``. The name of the output file can be set by changing the output
file named ``catalyst_module.o``. The name of the output file can be set by changing the output
module name using the ``--module-name`` option (the default module name is ``catalyst_module``).

Command line options
^^^^^^^^^^^^^^^^^^^^

The complete list of options for the Catalyst CLI tool can be displayed by running ``catalyst-cli --help``.
The complete list of options for the Catalyst CLI tool can be displayed by running ``catalyst --help``.
As this list contains *all* available options, including those for configuring LLVM, the options
most relevant to the usage of the Catalyst CLI tool are covered in more detail below.

Expand Down Expand Up @@ -111,7 +111,7 @@ name. Currently, the following pipelines are available:
``hlo-lowering-pipeline``,
``quantum-compilation-pipeline``,
``bufferization-pipeline``,
``llvm-dialect-lowering-pipeline``, and finally
``llvm-dialect-lowering-pipeline``, and finally
``default-catalyst-pipeline`` which encompasses all the above as the default pipeline used by the
Catalyst CLI tool if no pass option is specified.

Expand All @@ -138,7 +138,7 @@ applies the pass ``inline-nested-module``, we would specify this pipeline config
The workspace directory where intermediate files are saved. The default is the current working
directory.

Note that the workspace directory must exist before running ``catalyst-cli`` with this option.
Note that the workspace directory must exist before running ``catalyst`` with this option.

``--module-name=<name>``
""""""""""""""""""""""""
Expand Down Expand Up @@ -210,7 +210,7 @@ pass that is applied, and the ``-o`` option to set the name of the output IR fil

.. code-block::
catalyst-cli my_circuit.mlir \
catalyst my_circuit.mlir \
--tool=opt \
--catalyst-pipeline="pipe(remove-chained-self-inverse;merge-rotations)" \
--mlir-print-ir-after-all \
Expand Down Expand Up @@ -259,23 +259,23 @@ optimized MLIR.

For a list of transformation passes currently available in Catalyst, see the
:ref:`catalyst-s-transformation-library` documentation. The available passes are also listed in the
``catalyst-cli --help`` message.
``catalyst --help`` message.

MLIR Plugins
------------

``mlir-opt``-like tools are able to take plugins as inputs.
These plugins are shared objects that include dialects and passes written by third parties.
This means that you can write dialects and passes that can be used with ``catalyst-cli`` and ``quantum-opt``.
This means that you can write dialects and passes that can be used with ``catalyst`` and ``quantum-opt``.

As an example, the `LLVM repository includes a very simple plugin <https://github.com/llvm/llvm-project/tree/main/mlir/examples/standalone/standalone-plugin>`_.
To build it, simply run ``make plugin`` and the standalone plugin
will be built in the root directory of the Catalyst project.

With this, you can now run your own passes by using the following flags:

``catalyst-cli --load-dialect-plugin=$YOUR_PLUGIN --load-pass-plugin=$YOUR_PLUGIN $YOUR_PASS_NAME file.mlir``
``catalyst --load-dialect-plugin=$YOUR_PLUGIN --load-pass-plugin=$YOUR_PLUGIN $YOUR_PASS_NAME file.mlir``

Concretely for the example plugin, you can use the following command:

``catalyst-cli --tool=opt --load-pass-plugin=standalone/build/lib/StandalonePlugin.so --load-dialect-plugin=standalone/build/lib/StandalonePlugin.so --pass-pipeline='builtin.module(standalone-switch-bar-foo)' a.mlir``
``catalyst --tool=opt --load-pass-plugin=standalone/build/lib/StandalonePlugin.so --load-dialect-plugin=standalone/build/lib/StandalonePlugin.so --pass-pipeline='builtin.module(standalone-switch-bar-foo)' a.mlir``
8 changes: 4 additions & 4 deletions doc/dev/plugins.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MLIR Plugins
============

This page outlines documentation on how to start developping an MLIR plugin that can work with Catalyst.
This page outlines documentation on how to start developing an MLIR plugin that can work with Catalyst.
An MLIR plugin is a shared object that implements a compilation pass compatible with the MLIR framework.
Catalyst is built on top of MLIR, this means that MLIR plugins work with Catalyst.
This can enable anyone to build quantum compilation passes and new dialects as well.
Expand All @@ -20,7 +20,7 @@ It is intended to show how one would build an MLIR plugin, rather than showing a

You can use the ``StandalonePlugin.so`` plugin

* with either ``quantum-opt`` or ``catalyst-cli``,
* with either ``quantum-opt`` or ``catalyst``,
* load it from Python and transform a quantum program.

For example, if you are interested in using it from the command line interface, you can use the following flags to load the standalone plugin:
Expand Down Expand Up @@ -257,7 +257,7 @@ One also needs to link the MLIRQuantum library and change the plugin tool to cat
LINK_LIBS
MLIRStandalone
Please note that if you are using the Catalyst or Gradient dialects, you should also add MLIRCatalyst and MLIRGradient to the list of dependences and libraries to be linked.
Please note that if you are using the Catalyst or Gradient dialects, you should also add MLIRCatalyst and MLIRGradient to the list of dependencies and libraries to be linked.

4. Modify the standalone plugin to modify quantum operations.

Expand Down Expand Up @@ -325,7 +325,7 @@ The next step is changing the contents of the function itself:
And then we can run ``make all`` again.
The shared object of the standalone plugin should be available in ``mlir/build/lib/StandalonePlugin.so``.
This shared object can be used with ``catalyst-cli`` and ``quantum-opt``.
This shared object can be used with both the ``catalyst`` and ``quantum-opt`` tools.
From here, you can change the name of the pass, change the name of the shared object, and implement more complex transformations.


Expand Down
5 changes: 2 additions & 3 deletions doc/releases/changelog-0.10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@
[a separate github branch](https://github.com/PennyLaneAI/catalyst/commit/ba7b3438667963b307c07440acd6d7082f1960f3).
[(#872)](https://github.com/PennyLaneAI/catalyst/pull/872)

* The `catalyst-cli` documentation has been updated to reflect the removal of the `func-name` option
for transformation passes.
[(#1368)](https://github.com/PennyLaneAI/catalyst/pull/1368)
* The `verbose` parameter of :func:`~.qjit` was incorrectly listed as `verbosity` in the API documentation. This is now fixed.
[(#1440)](https://github.com/PennyLaneAI/catalyst/pull/1440)

* Added more details to catalyst-cli documentation specifiying available options for
checkpoint-stage and default pipelines
Expand Down
9 changes: 3 additions & 6 deletions frontend/catalyst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@
"mlir_quantum._mlir_libs._quantumDialects.mitigation"
)

from catalyst import debug, logging
from catalyst import debug, logging, passes
from catalyst.api_extensions import *
from catalyst.api_extensions import __all__ as _api_extension_list
from catalyst.autograph import *
from catalyst.autograph import __all__ as _autograph_functions
from catalyst.compiler import CompileOptions
from catalyst.debug.assertion import debug_assert
from catalyst.jit import QJIT, qjit
from catalyst.passes import Pass, PassPlugin, apply_pass, apply_pass_plugin, pipeline
from catalyst.passes.pass_api import pipeline
from catalyst.utils.exceptions import (
AutoGraphError,
CompileError,
Expand Down Expand Up @@ -187,11 +187,8 @@
"debug_assert",
"CompileOptions",
"debug",
"apply_pass",
"apply_pass_plugin",
"passes",
"pipeline",
"Pass",
"PassPlugin",
*_api_extension_list,
*_autograph_functions,
)
10 changes: 4 additions & 6 deletions frontend/catalyst/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,17 @@ def __init__(self, options: Optional[CompileOptions] = None):

@debug_logger
def get_cli_command(self, tmp_infile_name, output_ir_name, module_name, workspace):
"""Prepare the command for catalyst-cli to compile the file.
"""Prepare the command to run the Catalyst CLI to compile the file.
Args:
module_name (str): Module name to use for naming
workspace (Directory): directory that holds output files and/or debug dumps.
Returns:
cmd (str): The command to be executed.
"""
cli_build_path = get_bin_path("cli", "CATALYST_BIN_DIR") + "/catalyst-cli"
cli_build_path = get_bin_path("cli", "CATALYST_BIN_DIR") + "/catalyst"
if not path.isfile(cli_build_path):
raise FileNotFoundError("catalyst-cli executable was not found.") # pragma: nocover
raise FileNotFoundError("catalyst executable was not found.") # pragma: nocover
cmd = [cli_build_path]
cmd += [tmp_infile_name, "-o", output_ir_name]
cmd += ["--module-name", module_name, "--workspace", str(workspace)]
Expand Down Expand Up @@ -356,9 +356,7 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory):
if result.stderr:
print(result.stderr.strip(), file=self.options.logfile)
except subprocess.CalledProcessError as e: # pragma: nocover
raise CompileError(
f"catalyst-cli failed with error code {e.returncode}: {e.stderr}"
) from e
raise CompileError(f"catalyst failed with error code {e.returncode}: {e.stderr}") from e

with open(output_ir_name, "r", encoding="utf-8") as f:
out_IR = f.read()
Expand Down
3 changes: 2 additions & 1 deletion frontend/catalyst/jax_primitives_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ def transform_named_sequence_lowering(jax_ctx: mlir.LoweringRuleContext, pipelin
with ir.InsertionPoint(bb_named_sequence):
target = bb_named_sequence.arguments[0]
for _pass in pipeline:
options = _pass.get_options()
apply_registered_pass_op = ApplyRegisteredPassOp(
result=transform_mod_type, target=target, pass_name=_pass.name
result=transform_mod_type, target=target, pass_name=_pass.name, options=options
)
target = apply_registered_pass_op.result
transform_yield_op = YieldOp(operands_=[]) # pylint: disable=unused-variable
Expand Down
2 changes: 1 addition & 1 deletion frontend/catalyst/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def qjit(
compilation. If ``True``, intermediate representations are available via the
:attr:`~.QJIT.mlir`, :attr:`~.QJIT.jaxpr`, and :attr:`~.QJIT.qir`, representing
different stages in the optimization process.
verbosity (bool): If ``True``, the tools and flags used by Catalyst behind the scenes are
verbose (bool): If ``True``, the tools and flags used by Catalyst behind the scenes are
printed out.
logfile (Optional[TextIOWrapper]): File object to write verbose messages to (default -
``sys.stderr``).
Expand Down
Loading

0 comments on commit 0ef8e42

Please sign in to comment.