Machine - Snailz Docs

Skip to content

# Machine

Laboratory machinery.

## `Machine`

Bases: `BaseModel`

A piece of experimental machinery.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`machine_id` | `str` | machine ID | required
`name` | `str` | machine name | required

Source code in `src/snailz/machine.py`

    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    class Machine(BaseModel):
        """A piece of experimental machinery."""

        id_stem: ClassVar[str] = "M"
        id_digits: ClassVar[int] = 4

        machine_id: str = Field(
            description="machine ID", json_schema_extra={"primary_key": True}
        )
        name: str = Field(description="machine name")

        @staticmethod
        def make(params):
            """Generate a list of machines."""

            assert params.num_machines <= len(PREFIX) * len(SUFFIX), (
                f"cannot generate {params.num_machines} machine names"
            )
            utils.ensure_id_generator(Machine)
            pairs = [(p, s) for p in PREFIX for s in SUFFIX]
            return [
                Machine(machine_id=next(Machine._id_gen), name=f"{p} {s}")
                for i, (p, s) in enumerate(random.sample(pairs, k=params.num_machines))
            ]

### `make(params)` `staticmethod`

Generate a list of machines.

Source code in `src/snailz/machine.py`

    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    @staticmethod
    def make(params):
        """Generate a list of machines."""

        assert params.num_machines <= len(PREFIX) * len(SUFFIX), (
            f"cannot generate {params.num_machines} machine names"
        )
        utils.ensure_id_generator(Machine)
        pairs = [(p, s) for p in PREFIX for s in SUFFIX]
        return [
            Machine(machine_id=next(Machine._id_gen), name=f"{p} {s}")
            for i, (p, s) in enumerate(random.sample(pairs, k=params.num_machines))
        ]