Skip to content

Commit

Permalink
Merge branch 'master' into emery_haldane_models
Browse files Browse the repository at this point in the history
  • Loading branch information
ddhawan11 authored Sep 20, 2024
2 parents 306f0e3 + 2aee2e1 commit 953f5d6
Show file tree
Hide file tree
Showing 147 changed files with 1,989 additions and 2,991 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/install_deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ inputs:
description: The version of Python to use in order to run unit tests
required: false
default: '3.10'
install_numpy_1:
description: Indicate if numpy 1 should be installed or not
required: false
type: boolean
default: false
install_jax:
description: Indicate if JAX should be installed or not
required: false
Expand Down Expand Up @@ -67,6 +72,11 @@ runs:
pip install -r requirements-ci.txt --upgrade
pip install -r requirements-dev.txt --upgrade
- name: Install numpy 1 version
shell: bash
if: inputs.install_numpy_1 == 'true'
run: pip install "numpy==1.26.4"

- name: Install PyTorch
shell: bash
if: inputs.install_pytorch == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/interface-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ jobs:
install_pennylane_lightning_master: true
pytest_coverage_flags: ${{ inputs.pytest_coverage_flags }}
pytest_markers: jax and not qcut and not finite-diff and not param-shift
pytest_additional_args: --splits 5 --group ${{ matrix.group }}
pytest_additional_args: --dist=loadscope --splits 5 --group ${{ matrix.group }}
pytest_durations_file_path: '.github/workflows/jax_tests_durations.json'
pytest_store_durations: ${{ inputs.pytest_store_durations }}
additional_pip_packages: pytest-split
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/numpy_1_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: NumPy 1 - Tests
on:

schedule:
# Runs daily at 6 AM UTC (1 AM Toronto in winter, 2 AM in summer)
- cron: '0 6 * * *'

# Allows to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
group: numpy-1-unit-tests-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
uses: ./.github/workflows/numpy_1_unit-tests.yml
with:
branch: ${{ github.ref }}
230 changes: 230 additions & 0 deletions .github/workflows/numpy_1_unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
# TODO: remove this workflow once compatibility with NumPy 1
# will no longer be tested.

name: NumPy 1 - Unit Tests - Interfaces
on:
workflow_call:
inputs:
branch:
description: The PennyLane branch to checkout and run unit tests for
required: true
type: string
pipeline_mode:
description: The pipeline mode can be unit-tests, benchmarks, or reference-benchmarks
required: false
type: string
default: 'unit-tests'
disable_new_opmath:
description: Whether to disable the new op_math or not when running the tests
required: false
type: string
default: "False"

jobs:
setup-ci-load:
runs-on: ubuntu-latest

steps:
- name: Setup Python Versions
id: python_versions

run: |
cat >python_versions.json <<-EOF
{
"default": ["3.10", "3.11", "3.12"],
"torch-tests": ["3.10", "3.12"],
"jax-tests": ["3.10", "3.12"],
"external-libraries-tests": ["3.10"],
"data-tests": ["3.10"]
}
EOF
jq . python_versions.json
echo "python_versions=$(jq -r tostring python_versions.json)" >> $GITHUB_OUTPUT
- name: Set NumPy Version
id: numpy_version
run: echo "NUMPY_VERSION=1.26" >> $GITHUB_ENV

- name: Setup Matrix Max Parallel
id: max_parallel
run: |
cat >matrix_max_parallel.json <<-EOF
{
"default": 1,
"core-tests": 5,
"jax-tests": 10,
"torch-tests": 2
}
EOF
jq . matrix_max_parallel.json
echo "matrix_max_parallel=$(jq -r tostring matrix_max_parallel.json)" >> $GITHUB_OUTPUT
outputs:
matrix-max-parallel: ${{ steps.max_parallel.outputs.matrix_max_parallel }}
python-version: ${{ steps.python_versions.outputs.python_versions }}

torch-tests:
needs:
- setup-ci-load
strategy:
max-parallel: >-
${{
fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).torch-tests
|| fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).default
}}
matrix:
python-version: >-
${{
fromJSON(needs.setup-ci-load.outputs.python-version).torch-tests
|| fromJSON(needs.setup-ci-load.outputs.python-version).default
}}
uses: ./.github/workflows/unit-test.yml
with:
job_name: torch-tests (${{ matrix.python-version }}, numpy-1.26)
branch: ${{ inputs.branch }}
coverage_artifact_name: core-interfaces-coverage-torch-${{ matrix.python-version }}-numpy-1.26
python_version: ${{ matrix.python-version }}
pipeline_mode: ${{ inputs.pipeline_mode }}
install_numpy_1: true
install_jax: false
install_tensorflow: false
install_pytorch: true
install_pennylane_lightning_master: true
pytest_markers: torch and not qcut and not finite-diff and not param-shift
requirements_file: ${{ github.event_name == 'schedule' && strategy.job-index == 0 && 'torch.txt' || '' }}
disable_new_opmath: ${{ inputs.disable_new_opmath }}


autograd-tests:
needs:
- setup-ci-load
strategy:
max-parallel: >-
${{
fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).autograd-tests
|| fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).default
}}
matrix:
python-version: >-
${{
fromJSON(needs.setup-ci-load.outputs.python-version).autograd-tests
|| fromJSON(needs.setup-ci-load.outputs.python-version).default
}}
uses: ./.github/workflows/unit-test.yml
with:
job_name: autograd-tests (${{ matrix.python-version }}, numpy-1.26)
branch: ${{ inputs.branch }}
coverage_artifact_name: core-interfaces-coverage-autograd-${{ matrix.python-version }}-numpy-1.26
python_version: ${{ matrix.python-version }}
pipeline_mode: ${{ inputs.pipeline_mode }}
install_numpy_1: true
install_jax: false
install_tensorflow: false
install_pytorch: false
install_pennylane_lightning_master: true
pytest_markers: autograd and not qcut and not finite-diff and not param-shift
disable_new_opmath: ${{ inputs.disable_new_opmath }}


jax-tests:
needs:
- setup-ci-load
strategy:
max-parallel: >-
${{
fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).jax-tests
|| fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).default
}}
matrix:
group: [1, 2, 3, 4, 5]
python-version: >-
${{
fromJSON(needs.setup-ci-load.outputs.python-version).jax-tests
|| fromJSON(needs.setup-ci-load.outputs.python-version).default
}}
uses: ./.github/workflows/unit-test.yml
with:
job_name: jax-tests (${{ matrix.group }}, ${{ matrix.python-version }}, numpy-1.26)
branch: ${{ inputs.branch }}
coverage_artifact_name: core-interfaces-coverage-jax-${{ matrix.python-version }}-${{ matrix.group }}-numpy-1.26
python_version: ${{ matrix.python-version }}
pipeline_mode: ${{ inputs.pipeline_mode }}
install_numpy_1: true
install_jax: true
install_tensorflow: false
install_pytorch: false
install_pennylane_lightning_master: true
pytest_markers: jax and not qcut and not finite-diff and not param-shift
pytest_additional_args: --dist=loadscope --splits 5 --group ${{ matrix.group }}
additional_pip_packages: pytest-split
requirements_file: ${{ github.event_name == 'schedule' && strategy.job-index == 0 && 'jax.txt' || '' }}
disable_new_opmath: ${{ inputs.disable_new_opmath }}


core-tests:
needs:
- setup-ci-load
strategy:
max-parallel: >-
${{
fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).core-tests
|| fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).default
}}
matrix:
group: [1, 2, 3, 4, 5]
python-version: >-
${{
fromJSON(needs.setup-ci-load.outputs.python-version).core-tests
|| fromJSON(needs.setup-ci-load.outputs.python-version).default
}}
uses: ./.github/workflows/unit-test.yml
with:
job_name: core-tests (${{ matrix.group }}, ${{ matrix.python-version }}, numpy-1.26)
branch: ${{ inputs.branch }}
coverage_artifact_name: core-interfaces-coverage-core-${{ matrix.python-version }}-${{ matrix.group }}-numpy-1.26
python_version: ${{ matrix.python-version }}
pipeline_mode: ${{ inputs.pipeline_mode }}
install_numpy_1: true
install_jax: false
install_tensorflow: false
install_pytorch: false
install_pennylane_lightning_master: true
pytest_markers: core and not qcut and not finite-diff and not param-shift
pytest_additional_args: --splits 5 --group ${{ matrix.group }}
additional_pip_packages: pytest-split
requirements_file: ${{ github.event_name == 'schedule' && strategy.job-index == 0 && 'core.txt' || '' }}
disable_new_opmath: ${{ inputs.disable_new_opmath }}


data-tests:
needs:
- setup-ci-load
strategy:
max-parallel: >-
${{
fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).data-tests
|| fromJSON(needs.setup-ci-load.outputs.matrix-max-parallel).default
}}
matrix:
python-version: >-
${{
fromJSON(needs.setup-ci-load.outputs.python-version).data-tests
|| fromJSON(needs.setup-ci-load.outputs.python-version).default
}}
uses: ./.github/workflows/unit-test.yml
with:
job_name: data-tests (${{ matrix.python-version }}, numpy-1.26)
branch: ${{ inputs.branch }}
coverage_artifact_name: data-coverage-${{ matrix.python-version }}-numpy-1.26
python_version: ${{ matrix.python-version }}
pipeline_mode: ${{ inputs.pipeline_mode }}
install_numpy_1: true
install_jax: false
install_tensorflow: false
install_pytorch: false
install_pennylane_lightning_master: true
pytest_markers: data
additional_pip_packages: h5py
disable_new_opmath: ${{ inputs.disable_new_opmath }}
6 changes: 6 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ on:
required: false
type: string
default: '3.10'
install_numpy_1:
description: Indicate if numpy 1 should be installed or not
required: false
type: boolean
default: false
pipeline_mode:
description: The pipeline mode can be unit-tests, benchmarks, or reference-benchmark
required: false
Expand Down Expand Up @@ -158,6 +163,7 @@ jobs:
uses: ./.github/workflows/install_deps
with:
python_version: ${{ inputs.python_version }}
install_numpy_1: ${{ inputs.install_numpy_1 }}
install_pytorch: ${{ inputs.install_pytorch }}
install_tensorflow: ${{ inputs.install_tensorflow }}
install_jax: ${{ inputs.install_jax }}
Expand Down
9 changes: 2 additions & 7 deletions doc/development/adding_operators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint
# as the class differs from the standard `__init__` call signature of
# (*data, wires=wires, **hyperparameters), the _unflatten method that
# must be defined as well
# _unflatten recreates a opeartion from the serialized data and metadata of ``Operator._flatten``
# _unflatten recreates a operation from the serialized data and metadata of ``Operator._flatten``
# copied_op = type(op)._unflatten(*op._flatten())
wires = metadata[0]
hyperparams = dict(metadata[1])
Expand Down Expand Up @@ -245,12 +245,7 @@ If the above operator omitted the ``_unflatten`` custom definition, it would rai
The new gate can be used with PennyLane devices. Device support for an operation can be checked via
``dev.stopping_condition(op)``. If ``True``, then the device supports the operation.

``DefaultQubitLegacy`` first checks if the operator has a matrix using the :attr:`~.Operator.has_matrix` property.
If the Operator doesn't have a matrix, the device then checks if the name of the Operator is explicitly specified in
:attr:`~DefaultQubitLegacy.operations` or :attr:`~DefaultQubitLegacy.observables`.

Other devices that do not inherit from ``DefaultQubitLegacy`` only check if the name is explicitly specified in the ``operations``
property.
``DefaultQubit`` first checks if the operator has a matrix using the :attr:`~.Operator.has_matrix` property.

- If the device registers support for an operation with the same name,
PennyLane leaves the gate implementation up to the device. The device
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ If you are having issues, please let us know by posting the issue on our GitHub

We encourage contributions — simply fork the PennyLane repository, and then make a
`pull request <https://help.github.com/articles/about-pull-requests/>`_ containing
your contribution. All contributers to PennyLane will be listed as authors on the releases.
your contribution. All contributors to PennyLane will be listed as authors on the releases.

To chat directly with the team designing and building PennyLane, as well as members of
our community — ranging from quantum machine learning researchers, to students, to those
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction/interfaces/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ the following QNode that accepts two arguments ``data`` and ``weights``:
qml.CNOT(wires=[0, 2])
return qml.expval(qml.PauliZ(0))
rng = np.random.default_rng(seed=42) # make the results reproducable
rng = np.random.default_rng(seed=42) # make the results reproducible
data = rng.random([2 ** 3], requires_grad=False)
weights = np.array([0.1, 0.2, 0.3], requires_grad=True)
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction/measurements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ circuit:

.. code-block:: python
# fix seed to make results reproducable
# fix seed to make results reproducible
np.random.seed(1)
dev = qml.device("default.qubit", wires=1)
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ The shape can for example be used to construct random weights at the beginning o
return qml.expval(qml.PauliZ(0))
shape = BasicEntanglerLayers.shape(n_layers=2, n_wires=n_wires)
np.random.seed(42) # to make the result reproducable
np.random.seed(42) # to make the result reproducible
weights = np.random.random(size=shape)
>>> circuit(weights)
Expand Down
Loading

0 comments on commit 953f5d6

Please sign in to comment.