Skip to content

Commit

Permalink
update unit-test-benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
AmintorDusko committed Nov 8, 2023
1 parent b19e862 commit 36e8fbd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
32 changes: 17 additions & 15 deletions .github/workflows/unit-test-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,87 +97,89 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ github.workspace}}/benchmark_reference
key: ${{ inputs.benchmarks_name }}
key: ${{ inputs.benchmarks_name }}-${{ inputs.branch }}

- name: Check if the job will continue
id: continue
env:
reference_benchmarks: ${{ inputs.branch != github.ref && (steps.benchmark-cache.outputs.cache-hit != 'true') }}
local_benchmarks: ${{ inputs.branch == github.ref }}
run: |
echo "check=$( ${{ (env.reference_benchmarks == 'true') || (env.local_benchmarks == 'true') }})" >> $GITHUB_OUTPUT
echo "reference_benchmarks=$( echo ${{ (env.reference_benchmarks) }} )" >> $GITHUB_OUTPUT
echo "local_benchmarks=$( echo ${{ (env.local_benchmarks) }} )" >> $GITHUB_OUTPUT
echo "confirm=$( echo ${{ (env.reference_benchmarks == 'true') || (env.local_benchmarks == 'true') }} )" >> $GITHUB_OUTPUT
- name: Checkout
if: ${{ steps.continue.outputs.check == 'true' }}
if: ${{ steps.continue.outputs.confirm == 'true' }}
uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}
fetch-depth: ${{ inputs.checkout_fetch_depth }}

- name: Setup Python
if: ${{ steps.continue.outputs.check == 'true' }}
if: ${{ steps.continue.outputs.confirm == 'true' }}
uses: actions/setup-python@v4
with:
python-version: '${{ inputs.python_version }}'

- name: Upgrade PIP
if: ${{ steps.continue.outputs.check == 'true' }}
if: ${{ steps.continue.outputs.confirm == 'true' }}
run: pip install --upgrade pip && pip install wheel --upgrade

- name: Install PennyLane dependencies
if: ${{ steps.continue.outputs.check == 'true' }}
if: ${{ steps.continue.outputs.confirm == 'true' }}
run: |
pip install -r requirements-ci.txt --upgrade
pip install -r requirements-dev.txt --upgrade
- name: Install PyTorch
if: ${{ (inputs.install_pytorch == 'true') && (steps.continue.outputs.check == 'true') }}
if: ${{ (inputs.install_pytorch == true) && (steps.continue.outputs.confirm == 'true') }}
env:
TORCH_VERSION: ${{ inputs.pytorch_version != '' && format('=={0}', inputs.pytorch_version) || '' }}
run: pip install "torch${{ env.TORCH_VERSION }}" -f https://download.pytorch.org/whl/torch_stable.html

- name: Install TensorFlow
if: ${{ (inputs.install_tensorflow == 'true') && (steps.continue.outputs.check == 'true') }}
if: ${{ (inputs.install_tensorflow == true) && (steps.continue.outputs.confirm == 'true') }}
env:
TF_VERSION: ${{ inputs.tensorflow_version != '' && format('~={0}', inputs.tensorflow_version) || '' }}
run: pip install "tensorflow${{ env.TF_VERSION }}" "keras${{ env.TF_VERSION }}"

- name: Install JAX
if: ${{ (inputs.install_jax == 'true') && (steps.continue.outputs.check == 'true') }}
if: ${{ (inputs.install_jax == true) && (steps.continue.outputs.confirm == 'true') }}
env:
JAX_VERSION: ${{ inputs.jax_version != '' && format('=={0}', inputs.jax_version) || '' }}
run: pip install "jax${{ env.JAX_VERSION}}" "jaxlib${{ env.JAX_VERSION }}"

- name: Install additional PIP packages
if: ${{ (inputs.additional_pip_packages != '') && (steps.continue.outputs.check == 'true') }}
if: ${{ (inputs.additional_pip_packages != '') && (steps.continue.outputs.confirm == 'true') }}
run: pip install ${{ inputs.additional_pip_packages }}

- name: Install PennyLane
if: ${{ steps.continue.outputs.check == 'true' }}
if: ${{ steps.continue.outputs.confirm == 'true' }}
run: |
python setup.py bdist_wheel
pip install dist/PennyLane*.whl
- name: Install PennyLane-Lightning master
if: ${{ (inputs.install_pennylane_lightning_master == 'true') && (steps.continue.outputs.check == 'true') }}
if: ${{ (inputs.install_pennylane_lightning_master == true) && (steps.continue.outputs.confirm == 'true') }}
run: pip install -i https://test.pypi.org/simple/ PennyLane-Lightning --pre --upgrade

- name: Run PennyLane Benchmarks
if: ${{ steps.continue.outputs.check == 'true' }}
if: ${{ steps.continue.outputs.confirm == 'true' }}
env:
PYTEST_MARKER: ${{ inputs.pytest_markers != '' && format('-m "{0}"', inputs.pytest_markers) || '' }}
# Calling PyTest by invoking Python first as that adds the current directory to sys.path
run: python -m pytest ${{ inputs.pytest_test_directory }} ${{ inputs.pytest_benchmark_flags }} ${{ inputs.pytest_additional_args }} ${{ env.PYTEST_MARKER }}

# If this is a PR benchmark, upload the data as an artifact.
- name: Upload PR pytest benchmark file
if: ${{ steps.continue.outputs.local_benchmarks == 'true' }}
if: ${{ steps.continue.outputs.local_benchmarks == 'true'}}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.benchmarks_name }}
path: benchmarks.json

# If this is a reference benchmark and we don't hit the cache, move file to the cached directory.
- name: Upload reference pytest benchmark file
if: ${{ steps.continue.outputs.reference_benchmarks == 'true' }}
if: ${{ steps.continue.outputs.reference_benchmarks == 'true'}}
run: mkdir -p ${{ github.workspace}}/benchmark_reference && cp benchmarks.json "$_"
1 change: 1 addition & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* `Observable.return_type` is deprecated. Instead, you should inspect the type
of the surrounding measurement process.
[(#4762)](https://github.com/PennyLaneAI/pennylane/pull/4762)
[(#4798)](https://github.com/PennyLaneAI/pennylane/pull/4798)

<h3>Documentation 📝</h3>

Expand Down
10 changes: 10 additions & 0 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,16 @@ def return_type(self):
)
return self._return_type

@return_type.setter
def return_type(self, value):
"""Change the return type of an Observable. Note that this property is deprecated."""
warnings.warn(
"`Observable.return_type` is deprecated. Instead, you should "
"create a measurement process containing this Observable.",
UserWarning,
)
self._return_type = value

def __matmul__(self, other):
if active_new_opmath():
return super().__matmul__(other=other)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,11 @@ class DummyObserv(qml.operation.Observable):
with pytest.warns(UserWarning, match="`Observable.return_type` is deprecated. Instead"):
assert DummyObserv(0, wires=[1]).return_type is None

obs = DummyObserv(0, wires=[1])
with pytest.warns(UserWarning, match="`Observable.return_type` is deprecated. Instead"):
# pylint:disable=attribute-defined-outside-init
obs.return_type = qml.measurements.Sample

def test_construction_with_wires_pos_arg(self):
"""Test that the wires can be given as a positional argument"""

Expand Down

0 comments on commit 36e8fbd

Please sign in to comment.