Skip to content

Commit

Permalink
Setting up the file tests and VQA_function
Browse files Browse the repository at this point in the history
  • Loading branch information
hJaffaliColibritd committed Mar 15, 2024
1 parent 95b8189 commit 2191847
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 339 deletions.
2 changes: 1 addition & 1 deletion mpqp/tools/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def normalize(v: npt.NDArray[np.complex64]) -> npt.NDArray[np.complex64]:

@typechecked
def matrix_eq(lhs: Matrix, rhs: Matrix) -> bool:
r"""Checks whether two matrix are element-wise equal, within a tolerance.
r"""Checks whether two matrix (including vectors) are element-wise equal, within a tolerance.
For respectively each elements `a` and `b` of both inputs, we check this
specific condition: `|a - b| \leq (atol + rtol * |b|)`.
Expand Down
338 changes: 0 additions & 338 deletions tests/OA_attempt/OA-mpqp.py

This file was deleted.

31 changes: 31 additions & 0 deletions tests/execution/test_validity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
import pytest


from mpqp import QCircuit
from mpqp.gates import *
from mpqp.measures import ExpectationMeasure, Observable
from mpqp.execution import run, IBMDevice, AWSDevice, ATOSDevice
from mpqp.tools.maths import matrix_eq


def hae_3_qubit_circuit(t1, t2, t3, t4, t5, t6):
return QCircuit([Ry(t1, 0), Ry(t2, 1), Ry(t3, 2), CNOT(0,1), CNOT(1,2),
Ry(t4, 0), Ry(t5, 1), Ry(t6, 2), CNOT(0,1), CNOT(1,2)])


@pytest.mark.parametrize(
"parameters, expected_vector",
[
([0, 0, 0, 0, 0, 0, 0], np.array([1, 0, 0, 0, 0, 0, 0, 0])),
],
)
def test_state_vector_result_HEA_ansatz(parameters, expected_vector):

batch = run(hae_3_qubit_circuit(*parameters), [IBMDevice.AER_SIMULATOR_STATEVECTOR,
ATOSDevice.MYQLM_CLINALG,
ATOSDevice.MYQLM_PYLINALG,
])
#TODO: Julien , add cirq simulators, and statevector simulators here
for result in batch:
assert matrix_eq(result.amplitudes, expected_vector)

0 comments on commit 2191847

Please sign in to comment.