Skip to content

Commit

Permalink
Fail for registers with differentiable coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri committed Oct 31, 2024
1 parent 4d6d2ad commit 302d0df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pulser-core/pulser/register/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ def with_automatic_layout(
Raises:
RuntimeError: If the automatic layout generation fails to meet
the device constraints.
NotImplementedError: When the register has differentiable
quantities (ie torch Tensors with requires_grad=True).
Returns:
Register: A new register instance with identical qubit IDs and
Expand All @@ -353,6 +355,15 @@ def with_automatic_layout(
raise TypeError(
f"'device' must be of type Device, not {type(device)}."
)
if (
self._coords_arr.is_tensor
and self._coords_arr.as_tensor().requires_grad
):
raise NotImplementedError(
"'Register.with_automatic_layout()' does not support "
"registers with differentiable coordinates."
)

trap_coords = generate_trap_coordinates(
self.sorted_coords,
min_trap_dist=device.min_atom_distance,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,14 @@ def test_automatic_layout(optimal_filling):
big_reg.with_automatic_layout(device).layout.number_of_traps
>= min_traps
)


def test_automatic_layout_diff():
torch = pytest.importorskip("torch")
with pytest.raises(
NotImplementedError,
match="does not support registers with differentiable coordinates",
):
Register.square(
2, spacing=torch.tensor(10.0, requires_grad=True)
).with_automatic_layout(AnalogDevice)

0 comments on commit 302d0df

Please sign in to comment.