Skip to content

Light-sensitive robots with sensory delay

Light-sensitive robots in a circular well.

  • Class: LightSeekingRobotsSystem
  • Import: from skcomplex.systems.engineering.robotics import LightSeekingRobotsSystem
  • Field: engineering/robotics
  • Topics: robotics, active matter, delay, sde
  • References:
    • Mijalkov et al. 2016
    • Argun et al. 2021

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.engineering.robotics import LightSeekingRobotsSystem

trajectory = LightSeekingRobotsSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
n_robots 20
delay 5.0
V0 1.0
V_inf 0.1
I0 1.0
r0 1.0
tau 1.0
R 2.0
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time any
Space continuous
Laws noise, rate, update
Randomness stochastic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class LightSeekingRobotsSystem(BaseSystem):
    """Light-sensitive robots in a circular well.

    Their sensory delay decides whether they gather in the light. Each robot moves at
    `V_inf + (V0 - V_inf) exp(-I(t - delay))` in a direction that diffuses with time scale `tau`, in the Gaussian light
    `I = I0 exp(-(x^2 + y^2) / r0^2)` at the centre of a well of radius `R`. The robots start at the centre, in
    directions spread around the circle, and do not interact. A positive delay drives them out of the light: a robot
    crosses the light at the fast speed it measured in the dark and lingers outside at the slow speed it measured in the
    light, so robots with a delay spend less time in the light than robots without one.

    The system has the group `robots` of positions `x`, `y` and directions `phi`.

    Args:
        n_robots:
            The number of robots.

        delay:
            The sensory delay.

        V0:
            The speed in the dark.

        V_inf:
            The speed in strong light.

        I0:
            The intensity at the centre of the light.

        r0:
            The width of the light.

        tau:
            The time scale of rotational diffusion.

        R:
            The radius of the well.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.engineering.robotics import LightSeekingRobotsSystem
        >>> LightSeekingRobotsSystem(4).prepare().system_.elements[0].size
        4
    """

    field = 'engineering/robotics'
    topics = ('robotics', 'active matter', 'delay', 'sde')
    references = ('Mijalkov et al. 2016', 'Argun et al. 2021')
    until = 100.0
    dt = 0.5

    def __init__(
        self,
        n_robots: int = 20,
        *,
        delay: float = 5.0,
        V0: float = 1.0,
        V_inf: float = 0.1,
        I0: float = 1.0,
        r0: float = 1.0,
        tau: float = 1.0,
        R: float = 2.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_robots = n_robots
        self.delay = delay
        self.V0 = V0
        self.V_inf = V_inf
        self.I0 = I0
        self.r0 = r0
        self.tau = tau
        self.R = R

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the components of the system built from its model parameters."""
        super()._prepare(context)
        headings = np.linspace(0.0, 2 * np.pi, self.n_robots, endpoint=False)
        robots = LightSensitiveRobotElement(
            'robots',
            x=np.zeros(self.n_robots),
            y=np.zeros(self.n_robots),
            phi=headings,
            size=self.n_robots,
            space=ContinuousSpace(n_dim=2),
        )
        light = LightSensitivityInteraction(
            'light',
            target='robots',
            V0=self.V0,
            V_inf=self.V_inf,
            I0=self.I0,
            r0=self.r0,
            tau=self.tau,
            R=self.R,
            delay=self.delay,
        )
        self.system_ = System(self.label, elements=[robots], interactions=[light])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • LightSensitiveRobotElement, from Element

Interactions:

  • LightSensitivityInteraction, from Interaction
class LightSensitiveRobotElement(Element):
    """Robot at the position `x`, `y` that moves in the direction `phi`.

    `LightSensitivityInteraction` sets its speed from the light it measures.

    Args:
        label:
            The label of the robot or the group.

        x:
            The initial horizontal position.

        y:
            The initial vertical position.

        phi:
            The initial direction of motion.

        size:
            The number of robots, or `None` for one.

        space:
            The plane, a continuous space whose axes `x` and `y` make the position of a robot its place, or `None`.

    Examples:
        >>> from skcomplex.systems.engineering.robotics import LightSensitiveRobotElement
        >>> LightSensitiveRobotElement('robot', phi=1.0).phi
        1.0
    """

    def __init__(
        self,
        label: str,
        *,
        x: object = 0.0,
        y: object = 0.0,
        phi: Annotated[object, Period(2 * math.pi)] = 0.0,
        size: int | None = None,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, size=size, space=space)
        self.x = x
        self.y = y
        self.phi = phi

class LightSensitivityInteraction(Interaction):
    """Motion of a robot in a Gaussian light field that slows down in light.

    It reacts to the light it measured a delay ago. The robot moves at the speed
    `v = V_inf + (V0 - V_inf) exp(-I(t - delay))` in the direction `phi`, which diffuses with time scale `tau`,
    `dphi = sqrt(2 / tau) dW`. The light is `I(x, y) = I0 exp(-(x^2 + y^2) / r0^2)`, and a wall at radius `R` reflects
    the robot back into a circular well.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the robot or the group of robots.

        V0:
            The speed in the dark.

        V_inf:
            The speed in strong light.

        I0:
            The intensity at the centre of the light.

        r0:
            The width of the light.

        tau:
            The time scale of rotational diffusion.

        R:
            The radius of the well.

        delay:
            The sensory delay, 0 for a robot that reacts to the light it measures now.

    Examples:
        >>> from skcomplex.systems.engineering.robotics import LightSensitivityInteraction
        >>> LightSensitivityInteraction('light', target='robots', delay=5.0).delay
        5.0
    """

    law_classes = (RateLaw, NoiseLaw, UpdateLaw)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        V0: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        V_inf: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
        I0: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        r0: Annotated[float, RealSet.open(0, oo)] = 1.0,
        tau: Annotated[float, RealSet.open(0, oo)] = 1.0,
        R: Annotated[float, RealSet.open(0, oo)] = 2.0,
        delay: float = 0.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.V0 = V0
        self.V_inf = V_inf
        self.I0 = I0
        self.r0 = r0
        self.tau = tau
        self.R = R
        self.delay = delay

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the motion at the light-dependent speed, the rotational noise, and the reflecting wall.

        Args:
            context:
                The namespace of the robots, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s, t = context, context.t
        x, y, phi = s.target.x, s.target.y, s.target.phi
        sensed = (
            LightSensitivityInteraction._get_light(s, x(t=t - self.delay), y(t=t - self.delay))
            if self.delay
            else LightSensitivityInteraction._get_light(s, x, y)
        )
        speed = s.V_inf + (s.V0 - s.V_inf) * exp(-sensed)
        reach = where(sqrt(x**2 + y**2) > s.R, sqrt(x**2 + y**2), s.R)
        self.laws_: list[BaseLaw] = [
            RateLaw(x.diff(t), speed * cos(phi)),
            RateLaw(y.diff(t), speed * sin(phi)),
            NoiseLaw(phi, sqrt(2 / s.tau)),
            UpdateLaw(x, x * s.R / reach),
            UpdateLaw(y, y * s.R / reach),
        ]

    @staticmethod
    def _get_light(s: SimpleNamespace, x: Expression, y: Expression) -> Expression:
        """Return the Gaussian light intensity `I0 exp(-(x^2 + y^2) / r0^2)` at a point."""
        return s.I0 * exp(-(x**2 + y**2) / s.r0**2)