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

Support arbitrary controlled operations in lightning.qubit #516

Merged
merged 116 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
cd70d8d
Add failing tests.
vincentmr Oct 5, 2023
daf2699
Add revWireParityN.
vincentmr Oct 5, 2023
b9453dc
Fix applyMultiQubitOp implementation.
vincentmr Oct 5, 2023
b1727e4
Auto update version
github-actions[bot] Oct 5, 2023
db97744
Update changelog
vincentmr Oct 5, 2023
2c758b5
Refactor revWireParity overloads.
vincentmr Oct 5, 2023
279ba57
WIP fix Kokkos too.
vincentmr Oct 5, 2023
1fae578
Fix bug in multiQubitOpFunctor
vincentmr Oct 5, 2023
696fd71
Refactor unitary/hermitian tests and fix L-Kokkos multiQubit kernels.
vincentmr Oct 10, 2023
e90e6f1
Fix L-Qubit BitUtil.
vincentmr Oct 10, 2023
f103dc8
Include algorithm header in BitUtil (sort).
vincentmr Oct 10, 2023
8e3deb7
Fix tidy issue. Fix failing test.
vincentmr Oct 10, 2023
dcf9ad6
Make wires2Parity inline.
vincentmr Oct 10, 2023
9849a06
Update changelog.
vincentmr Oct 10, 2023
b1978a6
Update pennylane_lightning/core/src/utils/BitUtil.hpp
vincentmr Oct 10, 2023
58d0435
Init implementation for ControlledQubitUnitary
vincentmr Oct 10, 2023
b81c3d9
WIP
vincentmr Oct 11, 2023
d8a9c67
WIP
vincentmr Oct 11, 2023
def7dc8
Merge remote-tracking branch 'origin/master' into sc-39665-support-ar…
vincentmr Oct 11, 2023
c634e83
Move applyNQubitOp to LM kernels.
vincentmr Oct 11, 2023
e202e5d
Register NQubitOp and add inverse branch in applyNQubitOp.
vincentmr Oct 11, 2023
5dbc8cb
Auto update version
github-actions[bot] Oct 11, 2023
6475607
Update changelog.
vincentmr Oct 11, 2023
7c1c82e
Add test to improve controlled_matrix coverage.
vincentmr Oct 12, 2023
cdfa3a1
Fix tidy warning.
vincentmr Oct 12, 2023
309d2a6
Add doc [skip ci].
vincentmr Oct 12, 2023
4d3fa0d
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Oct 12, 2023
20fccd3
Auto update version
github-actions[bot] Oct 12, 2023
d0ba869
trigger CI
vincentmr Oct 12, 2023
421a814
WIP
vincentmr Oct 12, 2023
f527c58
WIP
vincentmr Oct 12, 2023
2270f9b
Fix NCRZ kernel registration and add tests.
vincentmr Oct 14, 2023
8a1eafc
Add NCRY.
vincentmr Oct 17, 2023
c7bb834
Add NCRX.
vincentmr Oct 17, 2023
c89176c
Create generic entry point for n-controlled kernels.
vincentmr Oct 17, 2023
097301e
Add NC[X-Z]
vincentmr Oct 17, 2023
482e7c5
Special treatment for MultiControlledX.
vincentmr Oct 17, 2023
b28ffdd
Add Hadamard, S, T, PhaseShift n-controlled gates.
vincentmr Oct 18, 2023
5af26be
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Oct 18, 2023
404ea61
Auto update version
github-actions[bot] Oct 18, 2023
6f34dce
Fix compiler warnings.
vincentmr Oct 18, 2023
7465bad
Address some of Lee's comments about naming and PL_ABORT.
vincentmr Oct 19, 2023
a2bd8aa
Merge branch 'support-arbitrary-controlled-operations' into sc-39665-…
vincentmr Oct 19, 2023
e7b5512
Merge remote-tracking branch 'origin/master' into sc-39665-support-ar…
vincentmr Nov 1, 2023
2b0f7d8
Call NC kernels from non-NC ones.
vincentmr Nov 1, 2023
f0a0862
Further reduce LM kernel code.
vincentmr Nov 2, 2023
f366888
Template applyNC on has_controls.
vincentmr Nov 2, 2023
faa51f1
Fix nw_tot if not has_controls
vincentmr Nov 2, 2023
9273fa4
Branch template top level.
vincentmr Nov 2, 2023
8868bed
Auto update version
github-actions[bot] Nov 2, 2023
4e8059e
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Nov 2, 2023
aab2585
Ncontr add gens (#555)
vincentmr Nov 9, 2023
681568d
Remove whitelines [skip ci]
vincentmr Nov 9, 2023
fc678db
Fix codefactor warning.
vincentmr Nov 9, 2023
14a473f
Merge remote-tracking branch 'origin/master' into sc-39665-support-ar…
vincentmr Nov 10, 2023
b49e73e
Auto update version
github-actions[bot] Nov 10, 2023
0e1f6d8
Add tests for n-controlled kernels.
vincentmr Nov 10, 2023
34fc4a9
Auto update version
github-actions[bot] Nov 10, 2023
eb0f5fd
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Nov 11, 2023
6db1dad
Fix tidy check.
vincentmr Nov 13, 2023
9e5a27e
Add C++ tests for controlled gates.
vincentmr Nov 13, 2023
1e78ba8
Remove whitespace.
vincentmr Nov 13, 2023
ba2b31f
Fix clang-tidy warning.
vincentmr Nov 13, 2023
c8b427f
Fix ctrl adjoint diff c++ test.
vincentmr Nov 13, 2023
c0a914b
Add tests for n-controlled unitaries.
vincentmr Nov 13, 2023
9b13ec1
Capture more n-controlled ops in L-Qubit.
vincentmr Nov 13, 2023
ed18410
Fix GPU workflow names.
vincentmr Nov 13, 2023
74d0e57
Move controlled ops to private method.
vincentmr Nov 13, 2023
a2e765d
Add coverage and fix gpu trigger.
vincentmr Nov 13, 2023
eb88fc2
Fix codecov uploads.
vincentmr Nov 13, 2023
f423f93
Update .github/CHANGELOG.md [skip ci]
vincentmr Nov 15, 2023
32eee52
Update pennylane_lightning/core/src/simulators/lightning_qubit/StateV…
vincentmr Nov 15, 2023
3481097
Update pennylane_lightning/core/src/simulators/lightning_qubit/StateV…
vincentmr Nov 15, 2023
a7835cc
Update pennylane_lightning/core/src/simulators/lightning_qubit/StateV…
vincentmr Nov 15, 2023
df0a9db
Update pennylane_lightning/core/_serialize.py
vincentmr Nov 15, 2023
e7285ca
Reorder controlled routine gate < generator < matrix.
vincentmr Nov 15, 2023
00ca5e0
Fix typos.
vincentmr Nov 15, 2023
6c58089
Merge remote-tracking branch 'origin/master' into sc-39665-support-ar…
vincentmr Nov 15, 2023
3a3a1ad
Auto update version
github-actions[bot] Nov 15, 2023
6691951
trigger ci
vincentmr Nov 15, 2023
2e2e2ab
Serialize unfound ops as controlled qubit unitaries.
vincentmr Nov 15, 2023
addb8ea
Update pennylane_lightning/core/src/simulators/lightning_qubit/algori…
vincentmr Nov 16, 2023
4d7b00b
Update pennylane_lightning/core/src/simulators/lightning_qubit/algori…
vincentmr Nov 16, 2023
5938ed6
Fix wrong LCOV guards.
vincentmr Nov 16, 2023
848ef67
Update pennylane_lightning/core/src/algorithms/JacobianData.hpp [skip…
vincentmr Nov 27, 2023
e8d3b2b
Update pennylane_lightning/core/src/algorithms/JacobianData.hpp [skip…
vincentmr Nov 27, 2023
fdf0509
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Nov 27, 2023
2c3ed2d
Auto update version
github-actions[bot] Nov 27, 2023
26b02ca
Address Shuli's comments.
vincentmr Nov 27, 2023
aa1757a
Address Lee's comments.
vincentmr Nov 28, 2023
c0a5da4
WIP
vincentmr Nov 27, 2023
44650ea
Add n-controlled DoubleExcitation gate.
vincentmr Nov 27, 2023
857f47d
Add double excitation gates + cpp tests.
vincentmr Nov 27, 2023
635138b
Add python tests.
vincentmr Nov 27, 2023
71b0347
Add adjoint diff support for double excitation gates.
vincentmr Nov 27, 2023
a4c79d2
Use FD to compute jac on adjoint tests.
vincentmr Nov 28, 2023
36b54a6
Fix tidy warning.
vincentmr Nov 28, 2023
3006a75
Update pennylane_lightning/core/src/simulators/lightning_kokkos/State…
vincentmr Nov 29, 2023
87579aa
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Nov 29, 2023
9f31fa6
Auto update version
github-actions[bot] Nov 29, 2023
cb915e4
Refactor applyNCMultiQubitOp and add doc in GateImplLM.hpp.
vincentmr Nov 28, 2023
5efa3c2
Add n-controlled 1- and 2-qubit unitaries.
vincentmr Nov 28, 2023
ede4516
Refactor Constant.hpp according to Amintor's suggestions.
vincentmr Nov 29, 2023
9c9e42a
Add single/twoqubit n-controlled ops.
vincentmr Nov 29, 2023
8d999c6
Move lightning_ops to conftest.
vincentmr Nov 29, 2023
0a4902d
Fix noarch import.
vincentmr Nov 29, 2023
af009e6
Fix tidy warning
vincentmr Nov 29, 2023
41e5094
Fix tidy warning.
vincentmr Nov 29, 2023
eb970a2
Small optim on parity2indices.
vincentmr Nov 29, 2023
1dd8125
Handle generic control_values in controlled ops at the Python layer.
vincentmr Nov 30, 2023
70e44e9
Merge branch 'master' into sc-39665-support-arbitrary-controlled-oper…
vincentmr Dec 7, 2023
f93fc26
Auto update version
github-actions[bot] Dec 7, 2023
de93669
trigger ci
vincentmr Dec 7, 2023
f65803c
Apply 1-qubit 1-controlled gates as non-controlled 2-qubit gates.
vincentmr Dec 7, 2023
393f246
Fix maybe_unused.
vincentmr Dec 7, 2023
7ef3bb7
Remove comments.
vincentmr Dec 7, 2023
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
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### New features since last release

* Add `LM` kernels to apply arbitrary controlled operations efficiently.
[(#516)](https://github.com/PennyLaneAI/pennylane-lightning/pull/516)

* Add shots support for expectation value calculation for given observables (`NamedObs`, `TensorProd` and `Hamiltonian`) based on Pauli words, `Identity` and `Hadamard` in the C++ layer by adding `measure_with_samples` to the measurement interface. All Lightning backends support this support feature.
[(#556)](https://github.com/PennyLaneAI/pennylane-lightning/pull/556)

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests_gpu_cu11.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: Testing::Linux::x86_64::LGPU
on:
workflow_run:
workflows: ["Testing::LKokkos::CUDA"]
types:
- completed
workflow_call:
inputs:
lightning-version:
Expand All @@ -14,6 +10,10 @@ on:
type: string
required: true
description: The version of PennyLane to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
pull_request:
push:
branches:
- master

env:
CI_CUDA_ARCH: 86
Expand Down
28 changes: 25 additions & 3 deletions pennylane_lightning/core/_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Rot,
Hamiltonian,
SparseHamiltonian,
QubitUnitary,
)
from pennylane.operation import Tensor
from pennylane.tape import QuantumTape
Expand Down Expand Up @@ -311,11 +312,32 @@ def serialize_ops(
"""
names = []
params = []
controlled_wires = []
wires = []
mats = []

uses_stateprep = False

def get_wires(operation, single_op):
if operation.name[0:2] == "C(" or (
operation.name == "MultiControlledX"
and all(char == "1" for char in operation.hyperparameters["control_values"])
):
name = "PauliX" if operation.name == "MultiControlledX" else operation.base.name
controlled_wires_list = operation.control_wires
if operation.name == "MultiControlledX":
wires_list = list(set(operation.wires) - set(controlled_wires_list))
else:
wires_list = operation.target_wires
if not hasattr(self.sv_type, name):
single_op = QubitUnitary(matrix(single_op.base), single_op.base.wires)
name = single_op.name
else:
name = single_op.name
wires_list = single_op.wires.tolist()
controlled_wires_list = []
return single_op, name, wires_list, controlled_wires_list

for operation in tape.operations:
if isinstance(operation, (BasisState, StatePrep)):
uses_stateprep = True
Expand All @@ -326,7 +348,7 @@ def serialize_ops(
op_list = [operation]

for single_op in op_list:
name = single_op.name
single_op, name, wires_list, controlled_wires_list = get_wires(operation, single_op)
names.append(name)
# QubitUnitary is a special case, it has a parameter which is not differentiable.
# We thus pass a dummy 0.0 parameter which will not be referenced
Expand All @@ -340,8 +362,8 @@ def serialize_ops(
params.append(single_op.parameters)
mats.append([])

wires_list = single_op.wires.tolist()
controlled_wires.append([wires_map[w] for w in controlled_wires_list])
wires.append([wires_map[w] for w in wires_list])

inverses = [False] * len(names)
return (names, params, wires, inverses, mats), uses_stateprep
return (names, params, wires, inverses, mats, controlled_wires), uses_stateprep
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.34.0-dev10"
__version__ = "0.34.0-dev11"
57 changes: 46 additions & 11 deletions pennylane_lightning/core/src/algorithms/AdjointJacobianBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* method.
*/
#pragma once

#include <span>

#include "JacobianData.hpp"
Expand Down Expand Up @@ -56,11 +55,20 @@ template <class StateVectorT, class Derived> class AdjointJacobianBase {
bool adj = false) {
for (size_t op_idx = 0; op_idx < operations.getOpsName().size();
op_idx++) {
state.applyOperation(operations.getOpsName()[op_idx],
operations.getOpsWires()[op_idx],
operations.getOpsInverses()[op_idx] ^ adj,
operations.getOpsParams()[op_idx],
operations.getOpsMatrices()[op_idx]);
if (operations.getOpsControlledWires()[op_idx].empty()) {
state.applyOperation(operations.getOpsName()[op_idx],
operations.getOpsWires()[op_idx],
operations.getOpsInverses()[op_idx] ^ adj,
operations.getOpsParams()[op_idx],
operations.getOpsMatrices()[op_idx]);
} else {
state.applyOperation(operations.getOpsName()[op_idx],
operations.getOpsControlledWires()[op_idx],
operations.getOpsWires()[op_idx],
operations.getOpsInverses()[op_idx] ^ adj,
operations.getOpsParams()[op_idx],
operations.getOpsMatrices()[op_idx]);
}
}
}

Expand All @@ -77,11 +85,20 @@ template <class StateVectorT, class Derived> class AdjointJacobianBase {
inline void applyOperationAdj(UpdatedStateVectorT &state,
const OpsData<StateVectorT> &operations,
size_t op_idx) {
state.applyOperation(operations.getOpsName()[op_idx],
operations.getOpsWires()[op_idx],
!operations.getOpsInverses()[op_idx],
operations.getOpsParams()[op_idx],
operations.getOpsMatrices()[op_idx]);
if (operations.getOpsControlledWires()[op_idx].empty()) {
state.applyOperation(operations.getOpsName()[op_idx],
operations.getOpsWires()[op_idx],
!operations.getOpsInverses()[op_idx],
operations.getOpsParams()[op_idx],
operations.getOpsMatrices()[op_idx]);
} else {
state.applyOperation(operations.getOpsName()[op_idx],
operations.getOpsControlledWires()[op_idx],
operations.getOpsWires()[op_idx],
!operations.getOpsInverses()[op_idx],
operations.getOpsParams()[op_idx],
operations.getOpsMatrices()[op_idx]);
}
}

/**
Expand Down Expand Up @@ -117,6 +134,24 @@ template <class StateVectorT, class Derived> class AdjointJacobianBase {
return sv.applyGenerator(op_name, wires, adj);
}

/**
* @brief Applies the gate generator for a given parametric gate. Returns
* the associated scaling coefficient.
*
* @param sv Statevector data to operate upon.
* @param op_name Name of parametric gate.
* @param controlled_wires Control wires.
* @param wires Wires to operate upon.
* @param adj Indicate whether to take the adjoint of the operation.
* @return PrecisionT Generator scaling coefficient.
*/
inline auto applyGenerator(StateVectorT &sv, const std::string &op_name,
const std::vector<size_t> &controlled_wires,
const std::vector<size_t> &wires, const bool adj)
-> PrecisionT {
return sv.applyGenerator(op_name, controlled_wires, wires, adj);
}

/**
* @brief Apply a given `%Observable<StateVectorT>` object to
* `%StateVectorT`.
Expand Down
54 changes: 46 additions & 8 deletions pennylane_lightning/core/src/algorithms/JacobianData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,39 @@ template <class StateVectorT> class OpsData {
const std::vector<std::vector<size_t>> ops_wires_;
const std::vector<bool> ops_inverses_;
const std::vector<std::vector<ComplexT>> ops_matrices_;
const std::vector<std::vector<size_t>> ops_controlled_wires_;

public:
/**
* @brief Construct an OpsData object, representing the serialized
* operations to apply upon the `%StateVector`.
*
* @param ops_name Name of each operation to apply.
* @param ops_params Parameters for a given operation ({} if optional).
* @param ops_wires Wires upon which to apply operation.
* @param ops_inverses Value to represent whether given operation is
* adjoint.
* @param ops_matrices Numerical representation of given matrix if not
* supported.
* @param ops_controlled_wires Control wires
*/
OpsData(std::vector<std::string> ops_name,
const std::vector<std::vector<PrecisionT>> &ops_params,
std::vector<std::vector<size_t>> ops_wires,
std::vector<bool> ops_inverses,
std::vector<std::vector<ComplexT>> ops_matrices,
std::vector<std::vector<size_t>> ops_controlled_wires)
: num_par_ops_{0}, ops_name_{std::move(ops_name)},
ops_params_{ops_params}, ops_wires_{std::move(ops_wires)},
ops_inverses_{std::move(ops_inverses)},
ops_matrices_{std::move(ops_matrices)},
ops_controlled_wires_{std::move(ops_controlled_wires)} {
for (const auto &p : ops_params) {
num_par_ops_ += static_cast<size_t>(!p.empty());
}
num_nonpar_ops_ = ops_params.size() - num_par_ops_;
};

/**
* @brief Construct an OpsData object, representing the serialized
* operations to apply upon the `%StateVector`.
Expand All @@ -71,11 +102,10 @@ template <class StateVectorT> class OpsData {
: num_par_ops_{0}, ops_name_{std::move(ops_name)},
ops_params_{ops_params}, ops_wires_{std::move(ops_wires)},
ops_inverses_{std::move(ops_inverses)},
ops_matrices_{std::move(ops_matrices)} {
ops_matrices_{std::move(ops_matrices)},
ops_controlled_wires_(ops_name.size()) {
for (const auto &p : ops_params) {
if (!p.empty()) {
num_par_ops_++;
}
num_par_ops_ += static_cast<size_t>(!p.empty());
}
num_nonpar_ops_ = ops_params.size() - num_par_ops_;
};
Expand All @@ -97,11 +127,10 @@ template <class StateVectorT> class OpsData {
: num_par_ops_{0}, ops_name_{ops_name}, ops_params_{ops_params},
ops_wires_{std::move(ops_wires)},
ops_inverses_{std::move(ops_inverses)},
ops_matrices_(ops_name.size()) {
ops_matrices_(ops_name.size()),
ops_controlled_wires_(ops_name.size()) {
for (const auto &p : ops_params) {
if (p.size() > 0) {
num_par_ops_++;
}
num_par_ops_ += static_cast<size_t>(!p.empty());
}
num_nonpar_ops_ = ops_params.size() - num_par_ops_;
};
Expand Down Expand Up @@ -140,6 +169,15 @@ template <class StateVectorT> class OpsData {
-> const std::vector<std::vector<size_t>> & {
return ops_wires_;
}
/**
* @brief Get the controlled wires for each operation.
*
* @return const std::vector<std::vector<size_t>>&
*/
[[nodiscard]] auto getOpsControlledWires() const
-> const std::vector<std::vector<size_t>> & {
return ops_controlled_wires_;
}
/**
* @brief Get the adjoint flag for each operation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using namespace Pennylane::Util;

#ifdef _ENABLE_PLQUBIT
constexpr bool BACKEND_FOUND = true;
constexpr bool SUPPORTS_CTRL = true;

#include "AdjointJacobianLQubit.hpp"
#include "ObservablesLQubit.hpp"
Expand All @@ -40,6 +41,7 @@ using namespace Pennylane::LightningQubit::Observables;

#elif _ENABLE_PLKOKKOS == 1
constexpr bool BACKEND_FOUND = true;
constexpr bool SUPPORTS_CTRL = false;

#include "AdjointJacobianKokkos.hpp"
#include "ObservablesKokkos.hpp"
Expand All @@ -55,6 +57,7 @@ using namespace Pennylane::LightningKokkos::Observables;

#elif _ENABLE_PLGPU == 1
constexpr bool BACKEND_FOUND = true;
constexpr bool SUPPORTS_CTRL = false;
#include "AdjointJacobianGPU.hpp"
#include "ObservablesGPU.hpp"
#include "TestHelpersStateVectors.hpp"
Expand All @@ -69,6 +72,7 @@ using namespace Pennylane::LightningGPU::Observables;

#else
constexpr bool BACKEND_FOUND = false;
constexpr bool SUPPORTS_CTRL = false;
using TestStateVectorBackends = Pennylane::Util::TypeList<void>;

template <class StateVector> struct StateVectorToName {};
Expand Down Expand Up @@ -134,6 +138,44 @@ template <typename TypeList> void testAdjointJacobian() {
}
}

DYNAMIC_SECTION("Op=PhaseShift, Obs=Y - "
<< StateVectorToName<StateVectorT>::name) {
if (SUPPORTS_CTRL) {
const std::vector<size_t> tp{0};
const size_t num_qubits = GENERATE(2, 3, 4);

const size_t num_params = 3;
const size_t num_obs = 1;
const auto obs = std::make_shared<NamedObs<StateVectorT>>(
"PauliY", std::vector<size_t>{num_qubits - 1});
std::vector<PrecisionT> jacobian(num_obs * tp.size(), 0);

for (const auto &p : param) {
std::vector<std::vector<size_t>> controls{
std::vector<size_t>(num_qubits - 1)};
std::iota(controls[0].begin(), controls[0].end(), 0);
auto ops = OpsData<StateVectorT>({"PhaseShift"}, {{p}},
{{num_qubits - 1}},
{false}, {{}}, controls);

std::vector<ComplexT> cdata(1U << num_qubits);
cdata[cdata.size() - 2] =
Pennylane::Util::INVSQRT2<PrecisionT>();
cdata[cdata.size() - 1] =
Pennylane::Util::INVSQRT2<PrecisionT>();

StateVectorT psi(cdata.data(), cdata.size());
JacobianData<StateVectorT> tape{
num_params, psi.getLength(), psi.getData(), {obs}, ops,
tp};
adj.adjointJacobian(std::span{jacobian}, tape, psi, true);

CAPTURE(jacobian);
CHECK(cos(p) == Approx(jacobian[0]));
}
}
}

DYNAMIC_SECTION("Op=RX, Obs=Z - "
<< StateVectorToName<StateVectorT>::name) {
const std::vector<size_t> tp{0};
Expand Down Expand Up @@ -189,6 +231,7 @@ template <typename TypeList> void testAdjointJacobian() {
CHECK(cos(p) == Approx(jacobian[0]).margin(1e-7));
}
}

DYNAMIC_SECTION("Op=RX, Obs=[Z,Z] - "
<< StateVectorToName<StateVectorT>::name) {
std::vector<size_t> tp{0};
Expand Down Expand Up @@ -366,7 +409,9 @@ template <typename TypeList> void testAdjointJacobian() {
{{0}, {0}, {0}, {0, 1}, {1, 2}, {1}, {1}, {1}},
{false, false, false, false, false, false, false, false},
std::vector<std::vector<ComplexT>>{
{}, {}, {}, cnot, {}, {}, {}, {}});
{}, {}, {}, cnot, {}, {}, {}, {}},
std::vector<std::vector<size_t>>{
{}, {}, {}, {}, {}, {}, {}, {}});

JacobianData<StateVectorT> tape{
num_params, psi.getLength(), psi.getData(), {obs}, ops, tp};
Expand Down Expand Up @@ -436,7 +481,7 @@ template <typename TypeList> void testAdjointJacobian() {
}
}

DYNAMIC_SECTION("Mixed Ops, Obs and TParams- "
DYNAMIC_SECTION("Mixed Ops, Obs and TParams - "
<< StateVectorToName<StateVectorT>::name) {
std::vector<PrecisionT> param{-M_PI / 7, M_PI / 5, 2 * M_PI / 3};
const std::vector<size_t> t_params{1, 2, 3};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ template <typename TypeList> void testAdjointJacobian() {
{{0}, {0}, {0}, {0, 1}, {1, 2}, {1}, {1}, {1}},
{false, false, false, false, false, false, false, false},
std::vector<std::vector<ComplexT>>{
{}, {}, {}, cnot, {}, {}, {}, {}});
{}, {}, {}, cnot, {}, {}, {}, {}},
std::vector<std::vector<size_t>>{
{}, {}, {}, {}, {}, {}, {}, {}});

JacobianDataMPI<StateVectorT> tape{num_params, psi, {obs}, ops, tp};

Expand Down
Loading
Loading