diff --git a/pulser-core/pulser/register/register.py b/pulser-core/pulser/register/register.py index 7798c8b7..4d53d043 100644 --- a/pulser-core/pulser/register/register.py +++ b/pulser-core/pulser/register/register.py @@ -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 @@ -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, diff --git a/tests/test_register.py b/tests/test_register.py index 02c9bd72..5cbacf0a 100644 --- a/tests/test_register.py +++ b/tests/test_register.py @@ -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)