✨ MLIR - Add missing Quantum Computation gates in Round Trip Pass #664
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: MLIR CI | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "mlir/**" | |
pull_request: | |
paths: | |
- "mlir/**" | |
- ".github/workflows/ci_mlir.yml" | |
merge_group: | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
cpp-test-mlir-ubuntu: | |
name: 🐧 Test MLIR with LLVM@${{ matrix.llvm-version }} | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
llvm-version: [19, 20] | |
fail-fast: false | |
env: | |
CMAKE_BUILD_PARALLEL_LEVEL: 4 | |
CTEST_PARALLEL_LEVEL: 4 | |
FORCE_COLOR: 3 | |
steps: | |
# check out the repository | |
- uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
# install a specific version of the LLVM toolchain | |
- name: Install llvm and mlir | |
run: | | |
sudo apt-get update | |
wget https://apt.llvm.org/llvm.sh -O ${{ runner.temp }}/llvm_install.sh | |
chmod +x ${{ runner.temp }}/llvm_install.sh | |
if sudo ${{ runner.temp }}/llvm_install.sh ${{ matrix.llvm-version }}; then | |
sudo apt-get install -y libmlir-${{ matrix.llvm-version }}-dev \ | |
mlir-${{ matrix.llvm-version }}-tools \ | |
clang-${{ matrix.llvm-version}} \ | |
clang-tools-${{ matrix.llvm-version }} \ | |
|| exit 1 | |
else | |
echo "Installation from script failed." | |
exit 1 | |
fi | |
echo "CC=clang-${{ matrix.llvm-version }}" >> $GITHUB_ENV | |
echo "CXX=clang++-${{ matrix.llvm-version }}" >> $GITHUB_ENV | |
echo "MLIR_DIR=/usr/lib/llvm-${{ matrix.llvm-version }}/lib/cmake/mlir" >> $GITHUB_ENV | |
echo "LLVM_DIR=/usr/lib/llvm-${{ matrix.llvm-version }}/lib/cmake/llvm" >> $GITHUB_ENV | |
# set up ccache for faster C++ builds | |
- name: Setup ccache | |
uses: Chocobo1/setup-ccache-action@v1 | |
with: | |
prepend_symlinks_to_path: false | |
override_cache_key: c++-tests-mlir-ubuntu-${{ matrix.llvm-version }} | |
# set up mold as linker for faster C++ builds | |
- name: Set up mold as linker | |
uses: rui314/setup-mold@v1 | |
# set up uv for faster Python package management | |
- name: Install the latest version of uv | |
uses: astral-sh/setup-uv@v6 | |
with: | |
python-version: 3.13 | |
activate-environment: true | |
# make sure ninja is installed | |
- name: Install Ninja | |
run: uv tool install ninja | |
# make sure the lit test runner is installed | |
- name: Install lit | |
run: uv pip install lit | |
# configure the project with CMake | |
- name: Configure CMake for MLIR | |
run: | | |
cmake -G Ninja -S . -B build \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DBUILD_MQT_CORE_MLIR=ON \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) | |
# build the project and run the tests | |
- name: Build MLIR components and directly run lit tests | |
run: cmake --build build --config Release --target mqt-core-mlir-lit-test | |
# build the MLIR unittests | |
- name: Build MLIR unittests | |
run: cmake --build build --config Release --target mqt-core-mlir-translation-test | |
# run unit tests | |
- name: Run unit tests | |
run: ctest -C Release --output-on-failure --test-dir build/mlir --repeat until-pass:3 --timeout 600 | |
cpp-test-mlir-windows: | |
name: 🏁 Test MLIR with LLVM@${{ matrix.llvm-version }} | |
runs-on: windows-latest | |
strategy: | |
matrix: | |
llvm-version: [19, 20] | |
fail-fast: false | |
env: | |
CMAKE_BUILD_PARALLEL_LEVEL: 4 | |
CTEST_PARALLEL_LEVEL: 4 | |
FORCE_COLOR: 3 | |
outputs: | |
llvm-latest-tag: ${{ steps.get-latest.outputs.latest }} | |
steps: | |
# check out the repository | |
- uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
- name: Find latest release of llvm-project | |
id: get-latest | |
run: | | |
$tag = git ls-remote --tags https://github.com/llvm/llvm-project.git "llvmorg-${{ matrix.llvm-version }}.*" | | |
Where-Object { $_ -match "llvmorg-\d+\.\d+\.\d+" } | | |
Sort-Object -Property { | |
if ($_ -match "llvmorg-(\d+)\.(\d+)\.(\d+)") { | |
[int]$Matches[1]*10000 + [int]$Matches[2]*100 + [int]$Matches[3] | |
} | |
} | | |
Select-Object -Last 1 | |
$latest = $tag | ForEach-Object { | |
if ($_ -match "refs/tags/llvmorg-(\d+\.\d+\.\d+)") { | |
$Matches[1] # Extract just the version number (e.g., "20.1.0") | |
} | |
} | | |
Where-Object { $_ -ne $null } | |
echo "Latest tag: $tag" | |
echo "latest=$latest" >> $env:GITHUB_OUTPUT | |
- name: Try to get MLIR from cache | |
uses: actions/cache@v4 | |
id: mlir-cache | |
with: | |
path: ${{ github.workspace }}/llvm-install | |
key: ${{ runner.os }}-llvm-${{ steps.get-latest.outputs.latest }} | |
restore-keys: | | |
${{ runner.os }}-llvm-${{ steps.get-latest.outputs.latest }} | |
# build the llvm-project from source | |
- name: Install llvm and mlir | |
if: steps.mlir-cache.outputs.cache-hit != 'true' | |
run: | | |
git clone --depth 1 https://github.com/llvm/llvm-project.git --branch llvmorg-${{ steps.get-latest.outputs.latest }} | |
cd llvm-project | |
cmake -S llvm -B build_llvm ` | |
-DLLVM_ENABLE_PROJECTS=mlir ` | |
-DLLVM_BUILD_EXAMPLES=OFF ` | |
-DLLVM_TARGETS_TO_BUILD="X86" ` | |
-DCMAKE_BUILD_TYPE=Release ` | |
-DLLVM_BUILD_TESTS=OFF ` | |
-DLLVM_INCLUDE_TESTS=OFF ` | |
-DLLVM_INCLUDE_EXAMPLES=OFF ` | |
-DLLVM_ENABLE_ASSERTIONS=ON ` | |
-DLLVM_ENABLE_UTILS=ON ` | |
-DLLVM_INSTALL_UTILS=ON ` | |
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\llvm-install | |
cmake --build build_llvm --target install --config Release | |
# set up uv for faster Python package management | |
- name: Install the latest version of uv | |
uses: astral-sh/setup-uv@v6 | |
with: | |
python-version: 3.13 | |
activate-environment: true | |
# make sure the lit test runner is installed | |
- name: Install lit | |
run: uv pip install lit | |
# configure the project with CMake | |
- name: Configure CMake for MLIR | |
run: | | |
cmake -S . -B build ` | |
-DCMAKE_BUILD_TYPE=Release ` | |
-DBUILD_MQT_CORE_MLIR=ON ` | |
-DCMAKE_PREFIX_PATH=${{ github.workspace }}\llvm-install ` | |
-DLLVM_EXTERNAL_LIT=${{ github.workspace }}\.venv\Scripts\lit.exe | |
# build the project and run the lit tests | |
- name: Build MLIR components and directly run lit tests | |
run: | | |
cmake --build build --config Release --target quantum-opt | |
$targetPath = "${{ github.workspace }}\\build\\mlir\\tools\\quantum-opt\\Release\\quantum-opt.exe" | |
$batchContent = '"{0}" "$@"' -f $targetPath | |
# Write to a directory that's definitely in PATH | |
$batchContent | Out-File -FilePath "C:\Windows\quantum-opt" -Encoding ascii | |
# Verify the batch file | |
Get-Content "C:\Windows\quantum-opt" | |
Write-Output "Batch file created at C:\Windows\quantum-opt pointing to $targetPath" | |
cmake --build build --config Release --target mqt-core-mlir-lit-test | |
# build the MLIR unittests | |
- name: Build MLIR unittests | |
run: cmake --build build --config Release --target mqt-core-mlir-translation-test | |
# run unit tests | |
- name: Run unit tests | |
run: ctest -C Release --output-on-failure --test-dir build/mlir --repeat until-pass:3 --timeout 600 | |
cpp-test-mlir-macos: | |
name: 🍎 Test MLIR with LLVM@${{ matrix.llvm-version }} on ${{ matrix.macos-version }} | |
runs-on: ${{ matrix.macos-version }} | |
strategy: | |
matrix: | |
macos-version: [macos-13, macos-14] | |
llvm-version: [19, 20] | |
fail-fast: false | |
env: | |
CMAKE_BUILD_PARALLEL_LEVEL: 4 | |
CTEST_PARALLEL_LEVEL: 4 | |
FORCE_COLOR: 3 | |
steps: | |
# Check out the repository | |
- uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
# Install llvm and ninja | |
- name: Install llvm@${{ matrix.llvm-version }} and Ninja via Homebrew | |
run: | | |
brew install llvm@${{ matrix.llvm-version }} ninja | |
# Set compiler and environment variables | |
- name: Set compiler and CMake environment variables | |
run: | | |
if [ "$(uname -m)" = "x86_64" ]; then | |
LLVM_PREFIX="/usr/local/opt/llvm@${{ matrix.llvm-version }}" | |
else | |
LLVM_PREFIX="/opt/homebrew/opt/llvm@${{ matrix.llvm-version }}" | |
fi | |
echo "CC=$LLVM_PREFIX/bin/clang" >> $GITHUB_ENV | |
echo "CXX=$LLVM_PREFIX/bin/clang++" >> $GITHUB_ENV | |
echo "LLVM_DIR=$LLVM_PREFIX/lib/cmake/llvm" >> $GITHUB_ENV | |
echo "MLIR_DIR=$LLVM_PREFIX/lib/cmake/mlir" >> $GITHUB_ENV | |
echo "$LLVM_PREFIX/bin" >> $GITHUB_PATH | |
# Set up uv for faster Python package management | |
- name: Install the latest version of uv | |
uses: astral-sh/setup-uv@v6 | |
with: | |
python-version: 3.13 | |
activate-environment: true | |
# Install lit | |
- name: Install lit | |
run: uv pip install lit | |
# Configure with CMake | |
- name: Configure CMake for MLIR | |
run: | | |
cmake -G Ninja -S . -B build \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DBUILD_MQT_CORE_MLIR=ON \ | |
-DCMAKE_C_COMPILER=$CC \ | |
-DCMAKE_CXX_COMPILER=$CXX \ | |
-DLLVM_DIR=$LLVM_DIR \ | |
-DMLIR_DIR=$MLIR_DIR \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) | |
# Build and run tests | |
- name: Build MLIR components and directly run lit tests | |
run: cmake --build build --config Release --target mqt-core-mlir-lit-test | |
# Build the MLIR unittests | |
- name: Build MLIR unittests | |
run: cmake --build build --config Release --target mqt-core-mlir-translation-test | |
# Run unit tests | |
- name: Run unit tests | |
run: ctest -C Release --output-on-failure --test-dir build/mlir --repeat until-pass:3 --timeout 600 | |
cpp-test-mlir-coverage: | |
name: 📊 MLIR Coverage with LLVM@${{ matrix.llvm-version }} | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
llvm-version: [19, 20] | |
fail-fast: false | |
env: | |
CMAKE_BUILD_PARALLEL_LEVEL: 4 | |
CTEST_PARALLEL_LEVEL: 4 | |
FORCE_COLOR: 3 | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
# check out the repository | |
- uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
# install a specific version of the LLVM toolchain | |
- name: Install llvm and mlir | |
run: | | |
sudo apt-get update | |
wget https://apt.llvm.org/llvm.sh -O ${{ runner.temp }}/llvm_install.sh | |
chmod +x ${{ runner.temp }}/llvm_install.sh | |
if sudo ${{ runner.temp }}/llvm_install.sh ${{ matrix.llvm-version }}; then | |
sudo apt-get install -y libmlir-${{ matrix.llvm-version }}-dev \ | |
mlir-${{ matrix.llvm-version }}-tools \ | |
clang-${{ matrix.llvm-version }} \ | |
llvm-${{ matrix.llvm-version }}-tools \ | |
clang-tools-${{ matrix.llvm-version }} \ | |
|| exit 1 | |
else | |
echo "Installation from script failed." | |
exit 1 | |
fi | |
echo "CC=clang-${{ matrix.llvm-version }}" >> $GITHUB_ENV | |
echo "CXX=clang++-${{ matrix.llvm-version }}" >> $GITHUB_ENV | |
echo "MLIR_DIR=/usr/lib/llvm-${{ matrix.llvm-version }}/lib/cmake/mlir" >> $GITHUB_ENV | |
echo "LLVM_DIR=/usr/lib/llvm-${{ matrix.llvm-version }}/lib/cmake/llvm" >> $GITHUB_ENV | |
# set up ccache for faster C++ builds | |
- name: Setup ccache | |
uses: Chocobo1/setup-ccache-action@v1 | |
with: | |
prepend_symlinks_to_path: false | |
override_cache_key: c++-coverage-mlir-${{ matrix.llvm-version }} | |
# set up mold as linker for faster C++ builds | |
- name: Set up mold as linker | |
uses: rui314/setup-mold@v1 | |
# set up uv for faster Python package management | |
- name: Install the latest version of uv | |
uses: astral-sh/setup-uv@v6 | |
with: | |
python-version: 3.13 | |
activate-environment: true | |
# make sure ninja is installed | |
- name: Install Ninja | |
run: uv tool install ninja | |
# install gcovr for coverage reporting | |
- name: Install gcovr | |
run: uv tool install gcovr | |
# make sure the lit test runner is installed | |
- name: Install lit | |
run: uv pip install lit | |
# configure the project with CMake for coverage | |
- name: Configure CMake for MLIR Coverage | |
run: | | |
cmake -G Ninja -S . -B build \ | |
-DCMAKE_BUILD_TYPE=Debug \ | |
-DBUILD_MQT_CORE_MLIR=ON \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) \ | |
-DENABLE_COVERAGE=ON | |
# build the project and run the tests with coverage | |
- name: Build MLIR components and run tests with coverage | |
run: cmake --build build --config Debug --target mqt-core-mlir-lit-test | |
# build the MLIR unittests | |
- name: Build MLIR unittests | |
run: cmake --build build --config Debug --target mqt-core-mlir-translation-test | |
# run unit tests | |
- name: Run unit tests | |
run: ctest -C Debug --output-on-failure --test-dir build/mlir --repeat until-pass:3 --timeout 600 | |
# run gcovr to generate coverage data | |
- name: Generate coverage data as XML | |
run: | | |
gcovr \ | |
--gcov-executable "/usr/lib/llvm-${{ matrix.llvm-version }}/bin/llvm-cov gcov" \ | |
--exclude build \ | |
--exclude-unreachable-branches \ | |
--exclude-noncode-lines \ | |
--exclude-throw-branches \ | |
--print-summary \ | |
--keep \ | |
--json \ | |
-o coverage-llvm-${{ matrix.llvm-version }}.json | |
# generate coverage report | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v5 | |
with: | |
flags: mlir | |
name: mlir-coverage-llvm-${{ matrix.llvm-version }} | |
fail_ci_if_error: true | |
use_oidc: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }} | |
files: coverage-llvm-${{ matrix.llvm-version }}.json |