Extend the Python language with new syntax.
# codec: lab
from pydantic import BaseModel
class MyExperiment(BaseModel):
'''Training a neural network to do a thing.'''
# identifier after @ indicates a YAML file
network: Network@spk-vih[
# modifications to the YAML contents
shape[1] = 500
layers[1].populations.e.kind = adaptive-LIF
]
loss: Loss@mse
optimizer: Optimizer@adam
dataset: Dataset@default
→
# codec: lab
from pydantic import BaseModel
class MyExperiment(BaseModel):
'''Training a neural network to do a thing.'''
network: Network
loss: Loss
optimizer: Optimizer
dataset: Dataset
@classmethod
def __load(cls) -> Self:
network = yaml.load_safe("spk-vih.yaml")
network.shape[1] = 500
network.layers[1].populations.e.kind = "adaptive-LIF"
loss = yaml.load_safe("mse.yaml")
optimizer = yaml.load_safe("adam.yaml")
dataset = yaml.load_safe("default.yaml")
return cls.model_validate(
network=network,
loss=loss,
optimizer=optimizer,
dataset=dataset
)