Skip to content

v0.3.0

Choose a tag to compare

@m-rots m-rots released this 01 Jun 22:57
· 8 commits to main since this release
e92b2cf
  • Violet now requires Python 3.13 or later.

  • Overriding the configuration used by Agent must now be performed through the generic parameter.

    - class MyAgent(Agent):
    -     config: MyConfig
    + class MyAgent(Agent[MyConfig]): ...
  • The in_proximity family of functions no longer return ProximityIter. Instead, vi.util now includes the count and first utility functions.

    - self.in_proximity_accuracy().count()
    + count(self.in_proximity_accuracy())
  • A bug in the in_proximity family of functions has been fixed. The generators now return the base Agent class as multiple classes of agents can be added to a simulation. Previously, these functions incorrectly assumed that only one class of agent could be added to a simulation and therefore, incorrectly, returned Self.

    To access the properties of your custom Agent, use generator comprehension and isinstance instead:

    class CovidAgent(Agent):
        state: State
        
        def infected_agents_in_proximity(self) -> int:
            return sum(
                agent.state == State.INFECTED
                for agent in self.in_proximity_performance()
                if isinstance(agent, CovidAgent)
            )
  • HeadlessSimulation and Simulation now require an instance of Config to be given.

    - Simulation()
    + Simulation(Config())
  • Built-in TOML support has been removed. vi.config no longer exports pyserde's from_toml, deserialize and serialize. Schema.from_file has been removed as well. TOML configuration is still possible by using an external package like pyserde.

    from dataclasses import dataclass
    from pathlib import Path
    
    from serde import serde
    from serde.toml import from_toml
    
    from vi import Config
    
    
    @dataclass
    @serde
    class MyConfig(Config): ...
    
    
    config = from_toml(MyConfig, Path("config.toml").read_text())
    print(config)
  • Creating a custom Schema now requires less boilerplate and uses the new type parameter syntax introduced in Python 3.12.

    from dataclasses import dataclass
    
    from vi.config import Mono, Poly, Schema
    
    
    @dataclass
    class MySchema[Int: Poly[int], Float: Poly[float]](Schema[Int, Float]):
        value: int | Int = 1
    
    
    Config = MySchema[Mono[int], Mono[float]]
    Matrix = MySchema[Poly[int], Poly[float]]
    
    for config in Matrix(value=[1, 2, 3]).to_configs(Config):
        print(config)

Full Changelog: v0.2.4...v0.3.0