Skip to content

Commit

Permalink
Merge branch 'master' into lightning_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mlxd committed Nov 25, 2022
2 parents ff880a7 + 6ae083f commit 99bbc3d
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 19 deletions.
8 changes: 7 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
* Improve Lightning package structure for external use as a C++ library.
[(#369)](https://github.com/PennyLaneAI/pennylane-lightning/pull/369)

* Improve the stopping condition method.
[(#386)](https://github.com/PennyLaneAI/pennylane-lightning/pull/386)

### Documentation

### Bug fixes

- Pin CMake to 3.24.x in wheel-builder to avoid Python not found error in CMake 3.25, when building wheels for PennyLane-Lightning-GPU.
[(#387)](https://github.com/PennyLaneAI/pennylane-lightning/pull/387)

### Contributors

This release contains contributions from (in alphabetical order):

Lee J. O'Riordan
Amintor Dusko, Lee J. O'Riordan

---

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
cat /etc/yum.conf | sed "s/\[main\]/\[main\]\ntimeout=5/g" > /etc/yum.conf
pip install ninja cmake
pip install ninja cmake~=3.24.0
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_ppc64le.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
cat /etc/yum.conf | sed "s/\[main\]/\[main\]\ntimeout=5/g" > /etc/yum.conf
pip install ninja cmake
pip install ninja cmake~=3.24.0
CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux2014

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
cat /etc/yum.conf | sed "s/\[main\]/\[main\]\ntimeout=5/g" > /etc/yum.conf
pip install ninja cmake
pip install ninja cmake~=3.24.0
yum clean all -y
yum install centos-release-scl-rh -y
yum install devtoolset-11-gcc-c++ -y
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11 ninja cmake
pip install pybind11 ninja cmake~=3.24.0
# Testing of built wheels
CIBW_TEST_REQUIRES: numpy~=1.21 scipy pytest pytest-cov pytest-mock flaky
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_macos_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11 ninja cmake
pip install pybind11 ninja cmake~=3.24.0
# Testing of built wheels
CIBW_TEST_REQUIRES: numpy~=1.21 scipy pytest pytest-cov pytest-mock flaky
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_win_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11 cmake
pip install pybind11 cmake~=3.24.0
# Testing of built wheels
CIBW_TEST_REQUIRES: numpy~=1.21 scipy pytest pytest-cov pytest-mock flaky
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"""


__version__ = "0.28.0-dev2"
__version__ = "0.28.0-dev4"
14 changes: 7 additions & 7 deletions pennylane_lightning/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ def stopping_condition(self):
and observable) and returns ``True`` if supported by the device."""

def accepts_obj(obj):
if obj.name == "QFT" and len(obj.wires) >= 10:
return False
if obj.name == "GroverOperator" and len(obj.wires) >= 13:
return False
if getattr(obj, "has_matrix", False):
return not (qml.operation.is_trainable(obj))
return obj.name in self.observables.union(self.operations)
if obj.name == "QFT" and len(obj.wires) < 10:
return True
if obj.name == "GroverOperator" and len(obj.wires) < 13:
return True
return (not isinstance(obj, qml.tape.QuantumTape)) and getattr(
self, "supports_operation", lambda name: False
)(obj.name)

return qml.BooleanFn(accepts_obj)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def circuit_ansatz(params, wires):


@pytest.mark.skipif(not lq._CPP_BINARY_AVAILABLE, reason="Lightning binary required")
def test__tape_qchem(tol):
def test_tape_qchem(tol):
"""Tests the circuit Ansatz with a QChem Hamiltonian produces correct results"""

H, qubits = qml.qchem.molecular_hamiltonian(
Expand All @@ -866,10 +866,10 @@ def circuit(params):
circuit_ansatz(params, wires=range(4))
return qml.expval(H)

params = np.arange(30) * 0.111
params = np.linspace(0, 29, 30) * 0.111

dev_lq = qml.device("lightning.qubit", wires=4)
dev_dq = qml.device("default.qubit", wires=4)
dev_lq = qml.device("lightning.qubit", wires=qubits)
dev_dq = qml.device("default.qubit", wires=qubits)

circuit_lq = qml.QNode(circuit, dev_lq, diff_method="adjoint")
circuit_dq = qml.QNode(circuit, dev_dq, diff_method="parameter-shift")
Expand Down
83 changes: 83 additions & 0 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2022 Xanadu Quantum Technologies Inc.

# 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.
"""
Integration tests for the ``execute`` method of LightningQubit.
"""
import pytest

import pennylane as qml
from pennylane import numpy as np


@pytest.mark.parametrize("diff_method", ("param_shift", "finite_diff"))
class TestQChem:
"""Test tapes returning the expectation values of a Hamiltonian, with a qchem workflow."""

def test_VQE_gradients(self, diff_method, tol):
"""Test if the VQE procedure returns the expected gradients."""

symbols = ["H", "H"]

geometry = np.array(
[[-0.676411907, 0.000000000, 0.000000000], [0.676411907, 0.000000000, 0.000000000]],
requires_grad=False,
)

mol = qml.qchem.Molecule(symbols, geometry, basis_name="STO-3G")

H, qubits = qml.qchem.molecular_hamiltonian(
symbols,
geometry,
basis="STO-3G",
)

singles, doubles = qml.qchem.excitations(mol.n_electrons, len(H.wires))

excitations = singles + doubles

num_params = len(singles + doubles)
params = np.zeros(num_params, requires_grad=True)

hf_state = qml.qchem.hf_state(mol.n_electrons, qubits)

with qml.tape.QuantumTape() as tape:
qml.BasisState(hf_state, wires=range(qubits))

for i, excitation in enumerate(excitations):
if len(excitation) == 4:
qml.DoubleExcitation(params[i], wires=excitation)
elif len(excitation) == 2:
qml.SingleExcitation(params[i], wires=excitation)

qml.expval(H)

num_params = len(excitations)
tape.trainable_params = np.linspace(1, num_params, num_params, dtype=int).tolist()

gradient_tapes, fn_grad = getattr(qml.gradients, diff_method)(tape)

dev_l = qml.device("lightning.qubit", wires=qubits)
dev_d = qml.device("default.qubit", wires=qubits)

def dev_l_execute(t):
dev = qml.device("lightning.qubit", wires=qubits)
return dev.execute(t)

grad_dev_l = fn_grad([dev_l_execute(t) for t in gradient_tapes])
grad_qml_l = fn_grad(qml.execute(gradient_tapes, dev_l))

grad_qml_d = fn_grad(qml.execute(gradient_tapes, dev_d))

assert np.allclose(grad_dev_l, grad_qml_l, tol)
assert np.allclose(grad_dev_l, grad_qml_d, tol)

0 comments on commit 99bbc3d

Please sign in to comment.