Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vytautas-a committed Nov 20, 2023
1 parent 50d5ae6 commit 025a7d4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions qadence/analog/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ def _(
from qadence import block_to_tensor

w_block = wait(duration=block.duration, qubit_support=block.qubit_support)
i_terms = add_interaction(register, w_block, interaction=interaction)
p_terms = add_pattern(register, pattern)
i_terms = add_interaction(register, w_block, interaction=interaction, pattern=pattern)

generator = add(rot_generator(b) for b in block.blocks if isinstance(b, ConstantAnalogRotation))
generator = generator if i_terms == I(0) else generator + i_terms.generator + p_terms # type: ignore[attr-defined] # noqa: E501
generator = generator if i_terms == I(0) else generator + i_terms.generator # type: ignore[attr-defined] # noqa: E501

norm = torch.norm(block_to_tensor(generator)).item()
return HamEvo(generator / norm, norm * block.duration / 1000)
Expand Down
4 changes: 2 additions & 2 deletions qadence/analog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ConstantAnalogRotation,
)
from qadence.blocks.utils import add, kron
from qadence.operations import N, X, Y
from qadence.operations import I, N, X, Y, Z
from qadence.register import Register

# Ising coupling coefficient depending on the Rydberg level
Expand Down Expand Up @@ -148,5 +148,5 @@ def add_pattern(register: Register, pattern: Union[AddressingPattern, None]) ->
weights_det = {i: 0.0 for i in support}

p_drive_terms = (1 / 2) * max_amp * add(X(i) * weights_amp[i] for i in support)
p_detuning_terms = -max_det * add(N(i) * weights_det[i] for i in support)
p_detuning_terms = -max_det * add(0.5 * (I(i) - Z(i)) * weights_det[i] for i in support)
return p_drive_terms + p_detuning_terms # type: ignore[no-any-return]
3 changes: 1 addition & 2 deletions qadence/backends/pulser/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from numpy import pi
from pulser.channels.channels import Rydberg
from pulser.channels.eom import RydbergBeam, RydbergEOM
from pulser.devices._device_datacls import Device as PulserDevice
from pulser.devices._device_datacls import VirtualDevice

from qadence.types import StrEnum
Expand All @@ -24,7 +23,7 @@


# device with realistic specs with local channels and custom bandwith.
RealisticDevice = PulserDevice(
RealisticDevice = VirtualDevice(
name="RealisticDevice",
dimensions=2,
rydberg_level=60,
Expand Down
6 changes: 3 additions & 3 deletions qadence/backends/pulser/pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pulser.sequence.sequence import Sequence
from pulser.waveforms import CompositeWaveform, ConstantWaveform, RampWaveform

from qadence import Register
from qadence import Parameter, Register
from qadence.blocks import AbstractBlock, CompositeBlock
from qadence.blocks.analog import (
AnalogBlock,
Expand Down Expand Up @@ -58,8 +58,8 @@ def add_addressing_pattern(
else:
max_amp = 0.0
max_det = 0.0
weights_amp = {i: 0.0 for i in support}
weights_det = {i: 0.0 for i in support}
weights_amp = {i: Parameter(0.0) for i in support}
weights_det = {i: Parameter(0.0) for i in support}

for i in support:
# declare separate local channel for each qubit
Expand Down
4 changes: 2 additions & 2 deletions tests/analog/test_analog_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_mixing_digital_analog() -> None:
def test_custom_interaction_function() -> None:
circuit = QuantumCircuit(2, wait(duration=100))
emulated = add_interaction(circuit, interaction=lambda reg, pairs: I(0))
assert emulated.block == HamEvo(I(0), 100 / 1000)
assert emulated.block == HamEvo(kron(I(0), I(1)), 100 / 1000)

m = QuantumModel(circuit, configuration={"interaction": lambda reg, pairs: I(0)})
assert m._circuit.abstract.block == HamEvo(I(0), 100 / 1000)
assert m._circuit.abstract.block == HamEvo(kron(I(0), I(1)), 100 / 1000)

0 comments on commit 025a7d4

Please sign in to comment.