This repository contains a prototype demonstration for a Catalyst-jeff integration. Currently, only an exporter is available in the form of an MLIR plugin. It takes Catalyst MLIR and serializes it to jeff's binary format.
Warning
This prototype is not in active development and will likely not work with newer versions of jeff , last known version to work is prior to the introduction of function declarations in the spec.
The project assumes that the Catalyst repository has been cloned locally and the compiler built from source. It also assumes that jeff is available locally. By default, it assumes all projects are located side-by-side in the directory structure.
To build it, the following commands suffice:
cmake -B build -S . -G Ninja
cmake --build buildThis will produce a catalyst-jeff.dylib (or similar depending on platform) in the build directory,
which is the plugin that can be loaded into the Catalyst compiler.
If you are using a different directory layout, or CMake is having difficulty finding the dependencies, you can use the following flags to customize their locations:
cmake -B build -S . -G Ninja -DJEFF_SOURCE_DIR=../jeff -DCATALYST_SOURCE_DIR=../catalyst
cmake --build buildIf Catalyst was built with non-standard build directories, the following flags are also available:
-DCATALYST_BUILD_DIR= and -DMLIR_BUILD_DIR=.
The plugin defines a jeff-export pass that can be run on Catalyst programs, for instance this
example.mlir. Note that the instructions supported by the plugin are currently limited.
func.func @hello(%phi: f64) -> i1 {
%c0 = arith.constant 0 : i64
%c5 = arith.constant 5 : i64
%r = quantum.alloc(%c5) : !quantum.reg
%q = quantum.extract %r[%c0] : !quantum.reg -> !quantum.bit
%q1 = quantum.custom "Hadamard"() %q : !quantum.bit
%q2 = quantum.custom "RY"(%phi) %q1 : !quantum.bit
%m, %q3 = quantum.measure %q2 : i1, !quantum.bit
%r1 = quantum.insert %r[%c0], %q3 : !quantum.reg, !quantum.bit
quantum.dealloc %r1 : !quantum.reg
func.return %m : i1
}The IR can then be serialized using the following command:
quantum-opt --load-pass-plugin=build/catalyst-jeff.dylib --pass-pipeline="builtin.module(jeff-export)" examples/example.mlirIt produces a catalyst.jeff encoded binary file in the current directory.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.