Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hermitian Support for Finite-Shot Measurement Statistics #451

Open
wants to merge 135 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
f0733e7
add more tests
multiphaseCFD Jan 10, 2024
043bd0a
add lapack installation in ci
multiphaseCFD Jan 10, 2024
862070f
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Jan 10, 2024
19b7976
update README.rst
multiphaseCFD Jan 10, 2024
0025b72
use latest lightning branch
multiphaseCFD Jan 11, 2024
4a4ba17
add frontend test
multiphaseCFD Jan 11, 2024
8a7c804
quick fix
multiphaseCFD Jan 11, 2024
fc6c4f7
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Jan 11, 2024
d2a369f
test against PL master branch
multiphaseCFD Jan 12, 2024
0e563f2
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Jan 15, 2024
200e37d
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Jan 15, 2024
300ff89
test against master
multiphaseCFD Jan 16, 2024
116b4b3
test with bbee87b Lightning
multiphaseCFD Mar 21, 2024
7b74c10
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Mar 21, 2024
9db1bc1
update lightnng testing commit
multiphaseCFD Mar 21, 2024
e4426cd
wheel built with c9fba49
multiphaseCFD Mar 22, 2024
0090442
test against 18231b5
multiphaseCFD Mar 23, 2024
d83f283
test against 18231b5
multiphaseCFD Mar 23, 2024
93b6054
test with 8fa1367
multiphaseCFD Mar 23, 2024
89da0ee
test against bec4b4e
multiphaseCFD Mar 23, 2024
819e889
update workflow with py env and preinstalled scipy
multiphaseCFD Mar 23, 2024
3df3c41
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Mar 23, 2024
35b5533
update yml work flow
multiphaseCFD Mar 23, 2024
a91c893
update check-catalyst
multiphaseCFD Mar 23, 2024
a868802
revert changes in catalyst
multiphaseCFD Mar 23, 2024
ed64d03
add scipy to build depencies
multiphaseCFD Mar 23, 2024
4467024
test against 3f9b6a5
multiphaseCFD Mar 23, 2024
4cff4fe
install scipy for lightning backend cpp test
multiphaseCFD Mar 23, 2024
6999037
test against f71de3b
multiphaseCFD Mar 23, 2024
a8ac1bd
add scipy install for Catalyst-Runtime Build
multiphaseCFD Mar 23, 2024
6fbf6e6
install scipy for Runtime Code Coverage
multiphaseCFD Mar 23, 2024
89ab873
test against 8c1d354
multiphaseCFD Mar 23, 2024
7c97813
test against 57be532
multiphaseCFD Mar 26, 2024
11326af
add venv for ci
multiphaseCFD Mar 26, 2024
c8ded02
fix typo check-catalyst
multiphaseCFD Mar 27, 2024
c365730
add virtual env for Runtime Code Coverage
multiphaseCFD Mar 27, 2024
a687893
remove virtual env for frontend test
multiphaseCFD Mar 27, 2024
4891bc5
frontend test only
multiphaseCFD Mar 27, 2024
bd305d9
frontend test only
multiphaseCFD Mar 27, 2024
14fd068
frontend test only
multiphaseCFD Mar 27, 2024
d1343ac
Trigger CI
multiphaseCFD Mar 27, 2024
68d52e2
test linux wheels build
multiphaseCFD Mar 27, 2024
0b6b438
test 3.9 for debug
multiphaseCFD Mar 27, 2024
f1bb78d
update
multiphaseCFD Mar 27, 2024
1ff7f1e
test against 97830a3
multiphaseCFD Mar 27, 2024
c71e26d
revert changes in linux wheels build
multiphaseCFD Mar 27, 2024
4287394
test against a0db3f0
multiphaseCFD Mar 27, 2024
a1bcef8
add python3.10-12 test
multiphaseCFD Mar 27, 2024
279e901
fix check-catalyst yaml
multiphaseCFD Mar 27, 2024
c00438b
use venv to install scipy
multiphaseCFD Mar 27, 2024
8f87ac4
fix typo
multiphaseCFD Mar 27, 2024
1115b02
fix typo
multiphaseCFD Mar 27, 2024
7444ee4
use py3.10 for test
multiphaseCFD Mar 27, 2024
c3f9b36
revert changes in Frontend tests gcc workflow
multiphaseCFD Mar 27, 2024
eb04c77
add scipy to gcc frontend tests
multiphaseCFD Mar 27, 2024
d53517b
test for lightning frontend
multiphaseCFD Mar 28, 2024
a32ccdf
target at 5bcae01
multiphaseCFD Apr 1, 2024
2abcd3d
install scipy with python in virtual env
multiphaseCFD Apr 1, 2024
7c5ae40
fix path
multiphaseCFD Apr 1, 2024
9bb29e1
force install scipy to default venv
multiphaseCFD Apr 1, 2024
343b2ba
trigger ci
maliasadi Apr 2, 2024
b4b553a
Update lq tags
maliasadi Apr 4, 2024
9d85530
Add changelog
maliasadi Apr 4, 2024
8aa5a04
Update tests
maliasadi Apr 4, 2024
90ad52f
Merge branch 'main' into add_hermitian_shots
maliasadi Apr 4, 2024
934c80b
trigger ci
maliasadi Apr 4, 2024
5c4d9a2
Update check-catalyst
maliasadi Apr 4, 2024
7195af7
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Apr 25, 2024
6c1ae4b
avoid explicitly install scipy
multiphaseCFD Apr 25, 2024
490f7c2
enable_lapack for macos x86-64 wheel
multiphaseCFD Apr 25, 2024
d999dd3
update workflow
multiphaseCFD Apr 25, 2024
63f6bb9
update check-catalyst
multiphaseCFD Apr 25, 2024
a35da01
remove blanks
multiphaseCFD Apr 25, 2024
ba4bae5
ensure scipy is installed
multiphaseCFD Apr 25, 2024
7abb4ea
Set up Python step
maliasadi Apr 26, 2024
4fe8806
test against e91975e
multiphaseCFD Apr 26, 2024
b2ec3b5
test against c813e21
multiphaseCFD Apr 27, 2024
64f505d
test against 951e231
multiphaseCFD Apr 27, 2024
b2ee43d
test def8a26
multiphaseCFD Apr 27, 2024
5922f21
add pybind_Dir
multiphaseCFD Apr 27, 2024
cc427d1
test
multiphaseCFD Apr 27, 2024
cd56be7
Merge branch 'main' into add_hermitian_shots
multiphaseCFD May 9, 2024
ea4fbf7
add venv
multiphaseCFD May 9, 2024
ade3aa2
quick test
multiphaseCFD May 9, 2024
cf832ff
add pybind11 as dependency
multiphaseCFD May 9, 2024
d089593
check python
multiphaseCFD May 9, 2024
b401d64
python3->python
multiphaseCFD May 9, 2024
f8e106c
install scipy
multiphaseCFD May 9, 2024
3f9fb3c
tests
multiphaseCFD May 10, 2024
d94ec96
remove grep
multiphaseCFD May 10, 2024
ccecc1f
add lit
multiphaseCFD May 10, 2024
921dee1
enable_lapack
multiphaseCFD May 10, 2024
165f9da
llvm-lit->lit
multiphaseCFD May 10, 2024
bf9492d
specify python when make frontend
multiphaseCFD May 10, 2024
12df432
python_executable -> "python"
multiphaseCFD May 10, 2024
f2a66e1
change python
multiphaseCFD May 10, 2024
7f7da4f
update make coverage-frontend
multiphaseCFD May 10, 2024
71ec99b
install attrs
multiphaseCFD May 10, 2024
017c567
install --upgrade attrs
multiphaseCFD May 10, 2024
05a7052
test against dd3bafb
multiphaseCFD May 13, 2024
2fab1e2
Merge branch 'main' into add_hermitian_shots
multiphaseCFD May 13, 2024
79f5e19
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Jul 9, 2024
71af0cf
enable_lapack
multiphaseCFD Jul 9, 2024
832657c
test against recent changes
multiphaseCFD Jul 11, 2024
7de6965
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Jul 11, 2024
66720a5
test against 48da2c2
multiphaseCFD Aug 15, 2024
d84f9ba
test against dcb2e79
multiphaseCFD Aug 16, 2024
f58449f
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Aug 16, 2024
27b21c9
test against 5097351
multiphaseCFD Aug 16, 2024
f8fb90c
test against b1b2d60
multiphaseCFD Aug 16, 2024
9c694d0
test against 6c50b77
multiphaseCFD Aug 16, 2024
9b73fd0
revert some changes
multiphaseCFD Aug 16, 2024
504f9fe
test against 352e7d1
multiphaseCFD Aug 16, 2024
e9be89a
test for runtime-code-cov
multiphaseCFD Aug 16, 2024
0decf35
install scipy
multiphaseCFD Aug 16, 2024
bc64e1a
build python venv
multiphaseCFD Aug 16, 2024
41b7d85
update check-catalyst
multiphaseCFD Aug 17, 2024
0b0c0c4
quick test
multiphaseCFD Aug 17, 2024
17a61e8
update
multiphaseCFD Aug 17, 2024
b5cbc1a
check
multiphaseCFD Aug 17, 2024
04dca15
test against 2355a0a
multiphaseCFD Aug 17, 2024
02be098
update Runtime Code Coverage
multiphaseCFD Aug 17, 2024
708068d
test against 7d47297
multiphaseCFD Aug 17, 2024
ddfaba9
test against a599094
multiphaseCFD Aug 17, 2024
360607c
test against 05d9e4d
multiphaseCFD Aug 17, 2024
030f472
test against a3bef4c
multiphaseCFD Aug 17, 2024
3296112
Add PYTHON_LIBRARY option
multiphaseCFD Aug 17, 2024
cdd02b4
quick fix
multiphaseCFD Aug 17, 2024
d9c3921
test against 35c3bd4
multiphaseCFD Aug 17, 2024
25fe0b7
test 07626e5
multiphaseCFD Aug 17, 2024
b471aef
test against 4b40406
multiphaseCFD Aug 17, 2024
c0b1564
test against 4b40406
multiphaseCFD Aug 17, 2024
e53c243
default USE_PYTHON_HEADERS ON for lightning backend
multiphaseCFD Aug 17, 2024
151a4b8
test against 77a8b21
multiphaseCFD Aug 19, 2024
257f51d
Merge branch 'main' into add_hermitian_shots
multiphaseCFD Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .github/workflows/build-wheel-linux-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:

- name: Install Dependencies (Python)
run: |
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML scipy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking because these are build-time dependencies. Is scipy a built-time dependency if we are going the dynamic loading approach?


# Required for MHLO and building MLIR with protected symbols.
# (Don't forget to add the build directory to PATH in subsequent steps, so
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:

- name: Install Dependencies (Python)
run: |
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML scipy

- name: Get Cached LLVM Source
id: cache-llvm-source
Expand Down Expand Up @@ -285,13 +285,14 @@ jobs:
# Build Catalyst-Runtime
- name: Build Catalyst-Runtime
run: |
# TODO: Remove tmp tag 'add_dldso' before merge
cmake -S runtime -B runtime-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/runtime-build/lib \
-DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \
-Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \
-DENABLE_LIGHTNING_KOKKOS=ON \
-DLIGHTNING_GIT_TAG="v0.35.0" \
-DLIGHTNING_GIT_TAG="add_dldso" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving a comment here about our procedure to target development versions of lightning:

  • the tag should only consist of hashes/tags on the main branch
  • the tag needs to be set in each of the 3 wheel build actions
  • the tag needs to be set in the runtime make file
  • the tag needs to be set in the dependencies file as lightning=<test pypi version number corresponding to the desired git tag on main>

This ensures that the main branch of Catalyst builds reproducibly and correctly for CI & developers.

-DKokkos_ENABLE_SERIAL=ON \
-DKokkos_ENABLE_OPENMP=ON \
-DENABLE_WARNINGS=OFF \
Expand Down Expand Up @@ -356,7 +357,12 @@ jobs:
name: Test Wheels (Python ${{ matrix.python_version }}) on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

steps:
steps:
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}

- name: Checkout Catalyst repo
uses: actions/checkout@v3

Expand All @@ -366,14 +372,9 @@ jobs:
name: catalyst-manylinux2014_x86_64-wheel-py-${{ matrix.python_version }}.zip
path: dist

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}

- name: Install Python dependencies
run: |
python${{ matrix.python_version }} -m pip install pytest pytest-xdist
python${{ matrix.python_version }} -m pip install pytest pytest-xdist scipy
Copy link
Contributor

@dime10 dime10 Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant whether this is needed here (and in fact may be detrimental). At this point we are testing the built package, any (mandatory) dependencies should be handled by the package itself, and we should only install testing requirements or optional feature dependencies here.

Suggested change
python${{ matrix.python_version }} -m pip install pytest pytest-xdist scipy
python${{ matrix.python_version }} -m pip install pytest pytest-xdist


- name: Install PennyLane Plugins
run: |
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/build-wheel-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
key: ${{ runner.os }}-${{ runner.arch }}-enzyme-${{ needs.constants.outputs.llvm_version }}-${{ needs.constants.outputs.enzyme_version }}-generic-build

- name: Install Dependencies (Python)
run: python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML cmake ninja
run: python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML cmake ninja scipy

- name: Build LLVM / MLIR
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -227,7 +227,7 @@ jobs:

- name: Install Dependencies (Python)
run: |
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML cmake ninja delocate
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML cmake ninja delocate scipy

- name: Get Cached LLVM Source
id: cache-llvm-source
Expand Down Expand Up @@ -282,13 +282,14 @@ jobs:
# Build Catalyst-Runtime
- name: Build Catalyst-Runtime
run: |
# TODO: Remove tmp tag 'add_dldso' before merge
cmake -S runtime -B runtime-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/runtime-build/lib \
-DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \
-Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \
-DENABLE_LIGHTNING_KOKKOS=ON \
-DLIGHTNING_GIT_TAG="v0.35.0" \
-DLIGHTNING_GIT_TAG="add_dldso" \
-DKokkos_ENABLE_SERIAL=ON \
-DKokkos_ENABLE_OPENMP=ON \
-DKokkos_ENABLE_COMPLEX_ALIGN=OFF \
Expand Down Expand Up @@ -382,7 +383,7 @@ jobs:

- name: Install Python dependencies
run: |
python${{ matrix.python_version }} -m pip install pytest pytest-xdist
python${{ matrix.python_version }} -m pip install pytest pytest-xdist scipy

- name: Install PennyLane Plugins
run: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/build-wheel-macos-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ jobs:

- name: Install Dependencies (Python)
run: |
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML cmake ninja delocate
python${{ matrix.python_version }} -m pip install wheel numpy pybind11 PyYAML cmake ninja delocate scipy

- name: Get Cached LLVM Source
id: cache-llvm-source
Expand Down Expand Up @@ -255,12 +255,13 @@ jobs:
- name: Build Catalyst-Runtime
run: |
# Segfaults in computing Lightning's adjoint-jacobian when building with OMP
# TODO: Remove tmp tag 'add_dldso' before merge
cmake -S runtime -B runtime-build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/runtime-build/lib \
-DPYTHON_EXECUTABLE=$(which python${{ matrix.python_version }}) \
-Dpybind11_DIR=$(python${{ matrix.python_version }} -c "import pybind11; print(pybind11.get_cmake_dir())") \
-DLIGHTNING_GIT_TAG="v0.35.0" \
-DLIGHTNING_GIT_TAG="add_dldso" \
-DENABLE_LIGHTNING_KOKKOS=ON \
-DKokkos_ENABLE_SERIAL=ON \
-DKokkos_ENABLE_OPENMP=OFF \
Expand Down Expand Up @@ -352,7 +353,7 @@ jobs:

- name: Install Python dependencies
run: |
python${{ matrix.python_version }} -m pip install pytest pytest-xdist
python${{ matrix.python_version }} -m pip install pytest pytest-xdist scipy

- name: Install PennyLane Plugins
run: |
Expand Down
41 changes: 33 additions & 8 deletions .github/workflows/check-catalyst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ jobs:
compiler: ${{ fromJson(needs.constants.outputs.compilers) }}

steps:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'

- name: Checkout Catalyst repo
uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y -q install ninja-build make cmake clang libomp-dev
python -m pip install scipy

- name: Build Catalyst-Runtime
run: |
Expand Down Expand Up @@ -132,7 +138,7 @@ jobs:
steps:
- name: Checkout Catalyst repo
uses: actions/checkout@v3

multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
- name: Cache MHLO Source
id: cache-mhlo-source
uses: actions/cache@v3
Expand Down Expand Up @@ -386,6 +392,7 @@ jobs:
# macOS requirements.txt
python3 -m pip install cuda-quantum==0.6.0
python3 -m pip install oqc-qcaas-client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to replace python3 with python ( := python3.10) here? (You can remove the deps from apt-get install steps)

/opt/hostedtoolcache/Python/3.10.14/x64/bin/python -m pip install scipy --force-reinstall
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
make frontend

- name: Get Cached LLVM Build
Expand Down Expand Up @@ -443,8 +450,13 @@ jobs:
strategy:
matrix:
compiler: ${{ fromJson(needs.constants.outputs.compilers) }}

multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'

- name: Checkout Catalyst repo
uses: actions/checkout@v3

Expand All @@ -455,9 +467,8 @@ jobs:
- name: Install Deps
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip libomp-dev libasan6 make
python3 --version | grep ${{ needs.constants.outputs.primary_python_version }}
python3 -m pip install -r requirements.txt
sudo apt-get install -y libomp-dev libasan6 make
python -m pip install -r requirements.txt scipy
make frontend

- name: Get Cached LLVM Build
Expand Down Expand Up @@ -506,8 +517,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip libomp-dev libasan6 make
python3 --version | grep ${{ needs.constants.outputs.primary_python_version }}
python3 -m pip install -r requirements.txt
python --version | grep ${{ needs.constants.outputs.primary_python_version }}
python -m pip install -r requirements.txt
make frontend

- name: Get Cached LLVM Build
Expand Down Expand Up @@ -556,9 +567,12 @@ jobs:
compiler: ${{ fromJson(needs.constants.outputs.compilers) }}

steps:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed. right?

Copy link
Member Author

@multiphaseCFD multiphaseCFD Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, this set a venv to make sure that both scipy and lightning are installed in the same site-packages\

# - name: Collect Workflow Telemetry
# uses: catchpoint/workflow-telemetry-action@v2

- name: Checkout the repo
uses: actions/checkout@v3

Expand All @@ -572,6 +586,11 @@ jobs:
run: |
pip install numpy amazon-braket-sdk
echo "AWS_DEFAULT_REGION=us-east-1" >> $GITHUB_ENV

- name: Install additional dependencies (lightning device)
if: ${{ matrix.backend != 'openqasm' }}
run: |
pip install scipy

- name: Build Runtime test suite for Lightning simulator
if: ${{ matrix.backend == 'lightning' }}
Expand Down Expand Up @@ -619,13 +638,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.10'

- name: Checkout the repo
uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y -q install cmake ninja-build libomp-dev lcov
python -m pip install scipy

- name: Build Runtime test suite for Lightning simulator
run: |
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ coverage: coverage-frontend coverage-runtime

coverage-frontend:
@echo "Generating coverage report for the frontend"
$(ASAN_COMMAND) $(PYTHON) -m pip install scipy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$(ASAN_COMMAND) $(PYTHON) -m pip install scipy
$(PYTHON) -m pip install scipy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here (and other places) as well I would be hesitant to install scipy manually. There should be a clear strategy about how we are bringing in the scipy dependency.

If a built-time dependency, it can be added to the relevant build scripts in the corresponding setup step.

If a run-time dependency, it should probably only be placed in one location: the setup.py package requirements. However, if the dependency is brought in by lightning rather than Catalyst directly, you would think the lightning package requirements already contain a scipy entry.

$(ASAN_COMMAND) $(PYTHON) -m pytest frontend/test/pytest $(PARALLELIZE) --cov=catalyst --tb=native --cov-report=$(COVERAGE_REPORT)
$(ASAN_COMMAND) $(PYTHON) -m pytest frontend/catalyst/oqc/test/ $(PARALLELIZE) --cov=catalyst --cov-append --tb=native --cov-report=$(COVERAGE_REPORT)
ifeq ($(TEST_BRAKET), NONE)
Expand Down
7 changes: 6 additions & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
`DIAGNOSTICS_RESULTS_PATH=/path/to/file.yml`.
[(#528)](https://github.com/PennyLaneAI/catalyst/pull/528)

* Catalyst now supports `qml.expval` and `qml.var` of `qml.Hermitian` observables
when finite shots are specified.
[(#451)](https://github.com/PennyLaneAI/catalyst/pull/451)

<h3>Improvements</h3>

* An updated quantum device specification format is now supported by Catalyst. The toml schema 2
Expand Down Expand Up @@ -666,7 +670,8 @@ Haochen Paul Wang.
This release contains contributions from (in alphabetical order):

Ali Asadi,
David Ittah.
David Ittah,
Shuli Shu.

# Release 0.4.0

Expand Down
55 changes: 37 additions & 18 deletions frontend/test/pytest/test_measurements_shots_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,26 @@ def circuit():
result = qjit(circuit)()
assert np.allclose(result, expected, atol=tol_stochastic, rtol=tol_stochastic)

def test_hermitian(self, backend):
def test_hermitian(self, backend, tol_stochastic):
"""Test expval Hermitian observables with shots."""
n_wires = 3
n_shots = 10000
dev = qml.device(backend, wires=n_wires, shots=n_shots)

@qjit
@qml.qnode(qml.device(backend, wires=3, shots=10000))
@qml.qnode(dev)
def circuit(x, y):
qml.RX(x, wires=0)
qml.RX(y, wires=1)
qml.CNOT(wires=[0, 1])
A = np.array(
[[complex(1.0, 0.0), complex(2.0, 0.0)], [complex(2.0, 0.0), complex(1.0, 0.0)]]
)
return qml.expval(qml.Hermitian(A, wires=2) + qml.PauliX(0) + qml.Hermitian(A, wires=1))
return qml.expval(qml.Hermitian(A, wires=2))

with pytest.raises(
RuntimeError,
match="Hermitian observables do not support shot measurement",
):
circuit(np.pi / 4, np.pi / 4)
expected = circuit(np.pi / 4, np.pi / 4)
result = qjit(circuit)(np.pi / 4, np.pi / 4)

assert np.allclose(result, expected, atol=tol_stochastic, rtol=tol_stochastic)

def test_paulix_pauliy(self, backend, tol_stochastic):
"""Test that a tensor product involving PauliX and PauliY works correctly"""
Expand Down Expand Up @@ -332,25 +333,26 @@ def circuit():
result = qjit(circuit)()
assert np.allclose(result, expected, atol=tol_stochastic, rtol=tol_stochastic)

def test_hermitian_shots(self, backend):
def test_hermitian_shots(self, backend, tol_stochastic):
"""Test var Hermitian observables with shots."""
n_wires = 3
n_shots = 10000
dev = qml.device(backend, wires=n_wires, shots=n_shots)

@qjit
@qml.qnode(qml.device(backend, wires=3, shots=10000))
@qml.qnode(dev)
def circuit(x, y):
qml.RX(x, wires=0)
qml.RX(y, wires=1)
qml.CNOT(wires=[0, 1])
A = np.array(
[[complex(1.0, 0.0), complex(2.0, 0.0)], [complex(2.0, 0.0), complex(1.0, 0.0)]]
)
return qml.var(qml.Hermitian(A, wires=2) + qml.PauliX(0) + qml.Hermitian(A, wires=1))
return qml.var(qml.Hermitian(A, wires=2))

with pytest.raises(
RuntimeError,
match="Hermitian observables do not support shot measurement",
):
circuit(np.pi / 4, np.pi / 4)
expected = circuit(np.pi / 4, np.pi / 4)
result = qjit(circuit)(np.pi / 4, np.pi / 4)

assert np.allclose(result, expected, atol=tol_stochastic, rtol=tol_stochastic)

def test_paulix_pauliy(self, backend, tol_stochastic):
"""Test that a tensor product involving PauliX and PauliY works correctly"""
Expand Down Expand Up @@ -472,6 +474,23 @@ def circuit(theta):
result = qjit(circuit)(0.432)
assert np.allclose(result, expected, atol=tol_stochastic, rtol=tol_stochastic)

# TODO: Support probs with observables
def test_probs_obs(self, backend):
"""Test probs with an observable"""

n_wires = 1
n_shots = 10000
dev = qml.device(backend, wires=n_wires, shots=n_shots)

matrix = 1 / np.sqrt(2) * np.array([[1, 1], [1, -1]])

@qml.qnode(dev)
def circuit(theta):
qml.RX(theta, wires=[0])
return qml.probs(op=qml.Hermitian(matrix, wires=0))

with pytest.raises(AssertionError):
qjit(circuit)(0.432)

class TestOtherMeasurements:
"""Test other measurement processes."""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pip>=22.3 # Due to a bug in `pip install -e .` vs read-only system-wide site-pac
numpy
pybind11>=2.8.0
PyYAML
scipy

# formatting/linting
black
Expand Down
Loading
Loading