Skip to content

Fix Kronecker delta creation for immutable backends (#33) #78

Fix Kronecker delta creation for immutable backends (#33)

Fix Kronecker delta creation for immutable backends (#33) #78

Workflow file for this run

# Copyright 2025 Google LLC
#
# 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.
name: Run Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8.x, 3.13.x]
compiler: [g++, clang]
target: [Debug]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install baseline for ${{ matrix.os }}, with ${{ matrix.compiler }}
run: |
sudo apt -y update
sudo apt -y upgrade
sudo apt -y install cmake \
${{ matrix.compiler }} \
libmpfr-dev \
python3-dev \
libboost-dev \
libmpfr6
- name: Install TNCO for ${{ matrix.os }}, with ${{ matrix.compiler }} and python==${{
matrix.python-version }} (${{ matrix.target }})
run: |
if [[ ${{ matrix.compiler }} == g++ ]]; then
export CC=gcc
export CXX=g++
elif [[ ${{ matrix.compiler }} == clang ]]; then
export CC=clang
export CXX=clang++
else
echo 'Not supported.'
return 1
fi
pip install .[parallel,testing] --config-settings=cmake.build-type=${{ matrix.target }} --verbose
- name: Run Tests for ${{ matrix.os }}, with ${{ matrix.compiler }} and python==${{
matrix.python-version }} (${{ matrix.target }})
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'g++' && matrix.python-version
== '3.13.x'
run: |
pip install pytest-sugar
PYTEST_FRACTION_N_TESTS=0.2 pytest --verbose --timeout=180 -n auto tests/*.py
- name: Run CLI for ${{ matrix.os }}, with ${{ matrix.compiler }} and python==${{
matrix.python-version }} (${{ matrix.target }})
run: |
# Install cirq to generate a random circuit
pip install cirq
# Create random circuit
python -c 'import cirq; cirq.to_json(cirq.testing.random_circuit(8, 16, 1), "circuit.cirq")'
# Fix seed
SEED=${RANDOM}
# Run tnco twice with the same seed
tnco optimize circuit.cirq '(0, 1e5)' --n-steps=1e2 \
--n-runs=4 \
--verbose=10 \
--seed=${SEED} \
--output-filename=res_${SEED}_1.json
tnco optimize circuit.cirq '(0, 1e5)' --n-steps=1e2 \
--n-runs=4 \
--verbose=10 \
--seed=${SEED} \
--output-filename=res_${SEED}_2.json
# Check difference
diff <(cat res_${SEED}_1.json | jq . | grep -v runtime) \
<(cat res_${SEED}_2.json | jq . | grep -v runtime)
- name: Run Example for ${{ matrix.os }}, with ${{ matrix.compiler }} and python==${{
matrix.python-version }} (${{ matrix.target }})
run: |
pip install jupyterlab papermill
papermill examples/Optimization.ipynb /dev/null