Skip to content

Commit

Permalink
add rot test
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmoutinho committed Nov 2, 2023
1 parent 80d0ba5 commit b947504
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tests/analog/test_analog_rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@
from qadence.blocks import AbstractBlock
from qadence.circuit import QuantumCircuit
from qadence.models import QuantumModel
from qadence.operations import AnalogRX, AnalogRY, AnalogRZ
from qadence.operations import AnalogRX, AnalogRY, AnalogRZ, AnalogRot
from qadence.parameters import FeatureParameter
from qadence.states import equivalent_state, random_state
from qadence.types import DiffMode


@pytest.mark.flaky(max_runs=2)
@pytest.mark.flaky(max_runs=5)
@pytest.mark.parametrize("n_qubits", [2, 3, 4])
@pytest.mark.parametrize("spacing", [4.0, 8.0, 15.0])
@pytest.mark.parametrize("rot_op", [AnalogRX, AnalogRY, AnalogRZ])
@pytest.mark.parametrize("rot_op", [AnalogRX, AnalogRY, AnalogRZ, AnalogRot])
def test_analog_rxyz_run(n_qubits: int, spacing: float, rot_op: AbstractBlock) -> None:
init_state = random_state(n_qubits)
batch_size = 5

phi = FeatureParameter("phi")

block = rot_op(phi) # type: ignore [operator]
if rot_op != AnalogRot:
phi = FeatureParameter("phi")
block = rot_op(phi) # type: ignore [operator]
values = {"phi": 1.0 + torch.rand(batch_size)}
else:
t = 5.0
omega = 1.0 + torch.rand(1)
delta = 1.0 + torch.rand(1)
phase = 1.0 + torch.rand(1)
block = rot_op(t, omega, delta, phase) # type: ignore [operator]
values = {}

register = Register.line(n_qubits)
circuit = QuantumCircuit(register, block)
Expand All @@ -41,9 +50,6 @@ def test_analog_rxyz_run(n_qubits: int, spacing: float, rot_op: AbstractBlock) -
configuration=conf,
)

batch_size = 5
values = {"phi": 1.0 + torch.rand(batch_size)}

wf_pyq = model_pyqtorch.run(values=values, state=init_state)
wf_pulser = model_pulser.run(values=values, state=init_state)

Expand Down

0 comments on commit b947504

Please sign in to comment.