| AttentionPooling |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("28315f3d1207778b") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import math
import torch
import torch.nn as nn
class AttentionPooling(nn.Module):
"""Learned-query attention pooling with masking."""
def __init__(self, d_model: int, num_queries: int=1):
super().__init__()
self.query = nn.Parameter(torch.randn(num_queries, d_model) * 0.02)
def forward(self, tokens: torch.Tensor, token_mask: torch.Tensor) -> torch.Tensor:
scores = torch.einsum('qd,btd->bqt', self.query, tokens) / math.sqrt(tokens.shape[-1])
scores = scores.masked_fill(token_mask.unsqueeze(1), -1000000000.0)
attn = torch.softmax(scores, dim=-1)
valid = (~token_mask).unsqueeze(1)
attn = attn * valid.float()
attn = attn / attn.sum(dim=-1, keepdim=True).clamp(min=1e-06)
pooled = torch.einsum('bqt,btd->bqd', attn, tokens)
return pooled.mean(dim=1)
INIT_ARGS = {
'd_model': 4,
'num_queries': 2,
}
ARGS = {
'tokens': torch.randn(2, 3, 4),
'token_mask': torch.tensor([[False, False, True], [False, True, True]]),
}
if __name__ == '__main__':
model = AttentionPooling(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output: {output}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| GRULatentDynamics |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("6f3fef70feb278a9") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned DynamicsOutput. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
from dataclasses import dataclass
@dataclass
class DynamicsOutput:
latent_states: torch.Tensor
prior_mu: torch.Tensor | None = None
prior_logvar: torch.Tensor | None = None
posterior_mu: torch.Tensor | None = None
posterior_logvar: torch.Tensor | None = None
class GRULatentDynamics(nn.Module):
"""GRU-based deterministic latent dynamics."""
def __init__(self, latent_dim: int, future_dim: int, spatial_dim: int, horizon_dim: int, hidden_dim: int, dropout: float, use_residual_update: bool):
super().__init__()
in_dim = future_dim + spatial_dim + horizon_dim
self.input_proj = nn.Sequential(nn.Linear(in_dim, hidden_dim), nn.ReLU(), nn.Dropout(dropout), nn.Linear(hidden_dim, hidden_dim), nn.ReLU())
self.cell = nn.GRUCell(hidden_dim, latent_dim)
self.use_residual_update = bool(use_residual_update)
self.residual_update = nn.Linear(latent_dim, latent_dim) if self.use_residual_update else None
def forward(self, z0: torch.Tensor, future_tokens: torch.Tensor, spatial_emb: torch.Tensor | None, horizon_emb: torch.Tensor | None, future_pad_mask: torch.Tensor, **_: torch.Tensor) -> DynamicsOutput:
bsz, seq_len, _ = future_tokens.shape
z_prev = z0
states = []
for t in range(seq_len):
parts = [future_tokens[:, t]]
if spatial_emb is not None:
parts.append(spatial_emb)
if horizon_emb is not None:
parts.append(horizon_emb[:, t])
u_t = self.input_proj(torch.cat(parts, dim=-1))
z_next = self.cell(u_t, z_prev)
if self.use_residual_update:
z_next = z_prev + self.residual_update(z_next)
valid = (~future_pad_mask[:, t]).unsqueeze(-1)
z_next = torch.where(valid, z_next, z_prev)
states.append(z_next)
z_prev = z_next
return DynamicsOutput(latent_states=torch.stack(states, dim=1))
INIT_ARGS = {
"latent_dim": 5,
"future_dim": 4,
"spatial_dim": 3,
"horizon_dim": 2,
"hidden_dim": 8,
"dropout": 0.1,
"use_residual_update": True,
}
ARGS = {
"z0": torch.randn(2, 5),
"future_tokens": torch.randn(2, 3, 4),
"spatial_emb": torch.randn(2, 3),
"horizon_emb": torch.randn(2, 3, 2),
"future_pad_mask": torch.tensor([[False, False, False], [False, False, True]]),
}
model = GRULatentDynamics(**INIT_ARGS)
output = model(**ARGS)
print(f"Output latent_states shape: {output.latent_states.shape}")
print(f"Expected shape: (2, 3, 5)")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type DynamicsOutput — a DynamicsOutput output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DynamicsOutput output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| HistoryEncoder |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("594a9f05cfcb0a9c") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import math
import torch
import torch.nn as nn
class PositionalEncoding(nn.Module):
def __init__(self, d_model: int, dropout: float=0.1, max_len: int=5000):
super().__init__()
self.dropout = nn.Dropout(p=dropout)
position = torch.arange(max_len).unsqueeze(1)
div_term = torch.exp(torch.arange(0, d_model, 2) * (-math.log(10000.0) / d_model))
pe = torch.zeros(max_len, d_model)
pe[:, 0::2] = torch.sin(position * div_term)
pe[:, 1::2] = torch.cos(position * div_term)
self.register_buffer('pe', pe.unsqueeze(0), persistent=False)
def forward(self, x):
x = x + self.pe[:, :x.size(1)]
return self.dropout(x)
class HistoryEncoder(nn.Module):
"""Transformer history encoder.
Inputs:
- history: [B, T_hist, C_in]
- history_mask: [B, T_hist, C_in]
- history_pad_mask: [B, T_hist]
Outputs:
- hist_tokens: [B, T_hist, D]
- hist_token_mask: [B, T_hist] (True means invalid token)
"""
def __init__(self, input_dim: int, d_model: int, num_layers: int, num_heads: int, dim_feedforward: int, dropout: float):
super().__init__()
self.input_dim = int(input_dim)
self.d_model = int(d_model)
self.input_proj = nn.Linear(input_dim, d_model)
enc_layer = nn.TransformerEncoderLayer(d_model=d_model, nhead=num_heads, dim_feedforward=dim_feedforward, dropout=dropout, batch_first=True, norm_first=True, activation='relu')
self.encoder = nn.TransformerEncoder(enc_layer, num_layers=num_layers)
self.pos = PositionalEncoding(d_model=d_model, dropout=dropout)
@staticmethod
def _clean_sequence(sequence: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
return torch.where(mask, torch.zeros_like(sequence), sequence)
def forward(self, history: torch.Tensor, history_mask: torch.Tensor, history_pad_mask: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
token_mask = history_pad_mask | history_mask.all(dim=-1)
clean = self._clean_sequence(history, history_mask)
emb = self.pos(self.input_proj(clean))
tokens = self.encoder(emb, src_key_padding_mask=token_mask)
return (tokens, token_mask)
INIT_ARGS = {
'input_dim': 4,
'd_model': 8,
'num_layers': 2,
'num_heads': 2,
'dim_feedforward': 16,
'dropout': 0.1,
}
ARGS = {
'history': torch.randn(2, 3, 4),
'history_mask': torch.zeros(2, 3, 4, dtype=torch.bool),
'history_pad_mask': torch.zeros(2, 3, dtype=torch.bool),
}
if __name__ == '__main__':
model = HistoryEncoder(**INIT_ARGS)
tokens, token_mask = model(**ARGS)
print(f"tokens shape: {tokens.shape}")
print(f"token_mask shape: {token_mask.shape}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type tuple — a tuple output has no array shape of its own; none is stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| HorizonEmbedding |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("ddb5ec0b255fbe19") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
import math
# Import the class and helper function
def _resolve_horizon_values(batch_size: int, seq_len: int, device: torch.device, horizons: torch.Tensor | None) -> torch.Tensor:
if horizons is None:
values = torch.arange(1, seq_len + 1, device=device, dtype=torch.float32).unsqueeze(0).repeat(batch_size, 1)
return values
if horizons.dim() == 1:
if horizons.shape[0] != seq_len:
raise ValueError('1D horizons must match sequence length')
return horizons.to(device=device, dtype=torch.float32).unsqueeze(0).repeat(batch_size, 1)
if horizons.dim() == 2:
if horizons.shape[1] != seq_len:
raise ValueError('2D horizons must match sequence length')
if horizons.shape[0] == 1 and batch_size > 1:
return horizons.to(device=device, dtype=torch.float32).repeat(batch_size, 1)
if horizons.shape[0] != batch_size:
raise ValueError('2D horizons must match batch size')
return horizons.to(device=device, dtype=torch.float32)
raise ValueError('horizons must be None, [L], or [B,L]')
class HorizonEmbedding(nn.Module):
"""Horizon/lead-time embeddings."""
def __init__(self, emb_dim: int, embedding_type: str='learned', max_horizon: int=512):
super().__init__()
self.emb_dim = int(emb_dim)
self.embedding_type = embedding_type
self.max_horizon = int(max_horizon)
if embedding_type == 'learned':
self.learned = nn.Embedding(self.max_horizon, self.emb_dim)
self.mlp = None
elif embedding_type == 'mlp':
self.learned = None
self.mlp = nn.Sequential(nn.Linear(1, emb_dim), nn.ReLU(), nn.Linear(emb_dim, emb_dim))
elif embedding_type == 'sinusoidal':
self.learned = None
self.mlp = None
else:
raise ValueError(f'Unsupported horizon_embedding_type: {embedding_type}')
def _sinusoidal(self, values: torch.Tensor) -> torch.Tensor:
bsz, seq_len = values.shape
half = self.emb_dim // 2
if half == 0:
return values.unsqueeze(-1)
div = torch.exp(torch.arange(0, half, device=values.device, dtype=torch.float32) * (-math.log(10000.0) / max(1, half)))
phase = values.unsqueeze(-1) * div
emb = torch.cat([torch.sin(phase), torch.cos(phase)], dim=-1)
if emb.shape[-1] < self.emb_dim:
pad = torch.zeros(bsz, seq_len, self.emb_dim - emb.shape[-1], device=values.device)
emb = torch.cat([emb, pad], dim=-1)
return emb
def forward(self, batch_size: int, seq_len: int, device: torch.device, horizons: torch.Tensor | None) -> torch.Tensor:
values = _resolve_horizon_values(batch_size, seq_len, device, horizons)
if self.embedding_type == 'learned':
idx = values.round().long().clamp(min=1) - 1
idx = idx.clamp(max=self.max_horizon - 1)
return self.learned(idx)
if self.embedding_type == 'mlp':
return self.mlp(values.unsqueeze(-1))
return self._sinusoidal(values)
# Test with learned embedding type
INIT_ARGS = {
'emb_dim': 4,
'embedding_type': 'learned',
'max_horizon': 512
}
ARGS = {
'batch_size': 2,
'seq_len': 3,
'device': torch.device('cpu'),
'horizons': None
}
# Construct and call
model = HorizonEmbedding(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output:\n{output}")
# Test with mlp embedding type
INIT_ARGS_MLP = {
'emb_dim': 4,
'embedding_type': 'mlp',
'max_horizon': 512
}
model_mlp = HorizonEmbedding(**INIT_ARGS_MLP)
output_mlp = model_mlp(**ARGS)
print(f"\nMLP Output shape: {output_mlp.shape}")
print(f"MLP Output:\n{output_mlp}")
# Test with sinusoidal embedding type
INIT_ARGS_SIN = {
'emb_dim': 4,
'embedding_type': 'sinusoidal',
'max_horizon': 512
}
model_sin = HorizonEmbedding(**INIT_ARGS_SIN)
output_sin = model_sin(**ARGS)
print(f"\nSinusoidal Output shape: {output_sin.shape}")
print(f"Sinusoidal Output:\n{output_sin}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 3, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| PositionalEncoding |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("664fac7eeb82b406") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import math
import torch
import torch.nn as nn
class PositionalEncoding(nn.Module):
def __init__(self, d_model: int, dropout: float=0.1, max_len: int=5000):
super().__init__()
self.dropout = nn.Dropout(p=dropout)
position = torch.arange(max_len).unsqueeze(1)
div_term = torch.exp(torch.arange(0, d_model, 2) * (-math.log(10000.0) / d_model))
pe = torch.zeros(max_len, d_model)
pe[:, 0::2] = torch.sin(position * div_term)
pe[:, 1::2] = torch.cos(position * div_term)
self.register_buffer('pe', pe.unsqueeze(0), persistent=False)
def forward(self, x):
x = x + self.pe[:, :x.size(1)]
return self.dropout(x)
INIT_ARGS = {
'd_model': 4,
'dropout': 0.1,
'max_len': 5000
}
ARGS = {
'x': torch.randn(2, 3, 4)
}
if __name__ == '__main__':
model = PositionalEncoding(**INIT_ARGS)
output = model(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {output.shape}")
print(f"Output:\n{output}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| QuantileDecoder |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("f300768dbd3888b3") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 4, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
import torch.nn.functional as F
def build_mlp(input_dim: int, hidden_dim: int, output_dim: int, num_layers: int, dropout: float) -> nn.Sequential:
"""Build a small feed-forward network."""
if num_layers < 1:
raise ValueError('num_layers must be >= 1')
layers: list[nn.Module] = []
if num_layers == 1:
layers.append(nn.Linear(input_dim, output_dim))
return nn.Sequential(*layers)
layers.extend([nn.Linear(input_dim, hidden_dim), nn.ReLU(), nn.Dropout(dropout)])
for _ in range(num_layers - 2):
layers.extend([nn.Linear(hidden_dim, hidden_dim), nn.ReLU(), nn.Dropout(dropout)])
layers.append(nn.Linear(hidden_dim, output_dim))
return nn.Sequential(*layers)
class QuantileDecoder(nn.Module):
"""Decode latent states into ordered/unordered target quantiles."""
def __init__(self, latent_dim: int, target_dim: int, num_quantiles: int, hidden_dim: int, num_layers: int, dropout: float, use_horizon_conditioned_decoder: bool, horizon_dim: int, spatial_dim: int, enforce_quantile_ordering: bool):
super().__init__()
self.target_dim = int(target_dim)
self.num_quantiles = int(num_quantiles)
self.use_horizon_conditioned_decoder = bool(use_horizon_conditioned_decoder)
self.enforce_quantile_ordering = bool(enforce_quantile_ordering)
in_dim = latent_dim
if self.use_horizon_conditioned_decoder:
in_dim += horizon_dim
if spatial_dim > 0:
in_dim += spatial_dim
self.net = build_mlp(input_dim=in_dim, hidden_dim=hidden_dim, output_dim=self.target_dim * self.num_quantiles, num_layers=num_layers, dropout=dropout)
def forward(self, latent_states: torch.Tensor, horizon_emb: torch.Tensor | None, spatial_emb: torch.Tensor | None) -> torch.Tensor:
bsz, seq_len, _ = latent_states.shape
parts = [latent_states]
if self.use_horizon_conditioned_decoder and horizon_emb is not None:
parts.append(horizon_emb)
if spatial_emb is not None:
parts.append(spatial_emb.unsqueeze(1).expand(-1, seq_len, -1))
x = torch.cat(parts, dim=-1)
raw = self.net(x).view(bsz, seq_len, self.target_dim, self.num_quantiles)
if not self.enforce_quantile_ordering or self.num_quantiles <= 1:
return raw
q0 = raw[..., :1]
increments = F.softplus(raw[..., 1:])
ordered = [q0]
current = q0
for idx in range(increments.shape[-1]):
current = current + increments[..., idx:idx + 1]
ordered.append(current)
return torch.cat(ordered, dim=-1)
INIT_ARGS = {
'latent_dim': 4,
'target_dim': 3,
'num_quantiles': 5,
'hidden_dim': 8,
'num_layers': 2,
'dropout': 0.1,
'use_horizon_conditioned_decoder': True,
'horizon_dim': 6,
'spatial_dim': 7,
'enforce_quantile_ordering': True,
}
ARGS = {
'latent_states': torch.randn(2, 3, 4),
'horizon_emb': torch.randn(2, 3, 6),
'spatial_emb': torch.randn(2, 7),
}
if __name__ == '__main__':
decoder = QuantileDecoder(**INIT_ARGS)
output = decoder(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Expected shape: (2, 3, 3, 5)")
assert output.shape == (2, 3, 3, 5), f"Shape mismatch: {output.shape}"
print("Test passed!")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 4, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| ResidualMLPDynamics |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("7b0bbf6eb4afaac5") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned DynamicsOutput. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
from dataclasses import dataclass
@dataclass
class DynamicsOutput:
latent_states: torch.Tensor
prior_mu: torch.Tensor | None = None
prior_logvar: torch.Tensor | None = None
posterior_mu: torch.Tensor | None = None
posterior_logvar: torch.Tensor | None = None
def build_mlp(input_dim: int, hidden_dim: int, output_dim: int, num_layers: int, dropout: float) -> nn.Sequential:
"""Build a small feed-forward network."""
if num_layers < 1:
raise ValueError('num_layers must be >= 1')
layers: list[nn.Module] = []
if num_layers == 1:
layers.append(nn.Linear(input_dim, output_dim))
return nn.Sequential(*layers)
layers.extend([nn.Linear(input_dim, hidden_dim), nn.ReLU(), nn.Dropout(dropout)])
for _ in range(num_layers - 2):
layers.extend([nn.Linear(hidden_dim, hidden_dim), nn.ReLU(), nn.Dropout(dropout)])
layers.append(nn.Linear(hidden_dim, output_dim))
return nn.Sequential(*layers)
class ResidualMLPDynamics(nn.Module):
"""Deterministic residual MLP latent dynamics."""
def __init__(self, latent_dim: int, future_dim: int, spatial_dim: int, horizon_dim: int, hidden_dim: int, num_layers: int, dropout: float):
super().__init__()
in_dim = latent_dim + future_dim + spatial_dim + horizon_dim
self.delta_net = build_mlp(input_dim=in_dim, hidden_dim=hidden_dim, output_dim=latent_dim, num_layers=num_layers, dropout=dropout)
def forward(self, z0: torch.Tensor, future_tokens: torch.Tensor, spatial_emb: torch.Tensor | None, horizon_emb: torch.Tensor | None, future_pad_mask: torch.Tensor, **_: torch.Tensor) -> DynamicsOutput:
bsz, seq_len, _ = future_tokens.shape
z_prev = z0
states = []
for t in range(seq_len):
parts = [z_prev, future_tokens[:, t]]
if spatial_emb is not None:
parts.append(spatial_emb)
if horizon_emb is not None:
parts.append(horizon_emb[:, t])
delta = self.delta_net(torch.cat(parts, dim=-1))
z_next = z_prev + delta
valid = (~future_pad_mask[:, t]).unsqueeze(-1)
z_next = torch.where(valid, z_next, z_prev)
states.append(z_next)
z_prev = z_next
return DynamicsOutput(latent_states=torch.stack(states, dim=1))
INIT_ARGS = {
'latent_dim': 4,
'future_dim': 3,
'spatial_dim': 5,
'horizon_dim': 6,
'hidden_dim': 8,
'num_layers': 2,
'dropout': 0.1,
}
ARGS = {
'z0': torch.randn(2, 4),
'future_tokens': torch.randn(2, 3, 3),
'spatial_emb': torch.randn(2, 5),
'horizon_emb': torch.randn(2, 3, 6),
'future_pad_mask': torch.tensor([[False, False, False], [False, False, True]]),
}
if __name__ == '__main__':
model = ResidualMLPDynamics(**INIT_ARGS)
output = model(**ARGS)
print(f"Output latent_states shape: {output.latent_states.shape}")
print(f"Expected shape: (2, 3, 4)")
assert output.latent_states.shape == (2, 3, 4), f"Shape mismatch: {output.latent_states.shape}"
print("Success!")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type DynamicsOutput — a DynamicsOutput output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DynamicsOutput output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| RiskHead |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("7eabdba4bf764303") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 2, dtype family float, shape (2, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
class RiskHead(nn.Module):
"""Optional risk head for stress probability logits."""
def __init__(self, latent_dim: int, output_dim: int, hidden_dim: int, dropout: float):
super().__init__()
self.net = nn.Sequential(nn.Linear(latent_dim, hidden_dim), nn.ReLU(), nn.Dropout(dropout), nn.Linear(hidden_dim, output_dim))
def forward(self, latent_states: torch.Tensor) -> torch.Tensor:
return self.net(latent_states)
INIT_ARGS = {
"latent_dim": 4,
"output_dim": 3,
"hidden_dim": 8,
"dropout": 0.1,
}
ARGS = {
"latent_states": torch.randn(2, 4),
}
if __name__ == "__main__":
risk_head = RiskHead(**INIT_ARGS)
output = risk_head(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output: {output}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 2, dtype family float, shape (2, 3) — shape (2, 3) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| StateSummarizer |
Ran ran on a synthesized input |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("3dcef890f8fbf2cb") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
# INIT_ARGS for StateSummarizer.__init__
INIT_ARGS = {
'd_model': 8,
'latent_dim': 6,
'summarizer_type': 'posterior_attention_pooling',
'sample_initial_state': True
}
# ARGS for StateSummarizer.forward
batch_size = 2
seq_len = 5
d_model = 8
tokens = torch.randn(batch_size, seq_len, d_model)
token_mask = torch.tensor([
[False, False, False, True, True],
[False, False, False, False, True]
])
training = True
ARGS = {
'tokens': tokens,
'token_mask': token_mask,
'training': training
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| _normal_sample |
Ran ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("609519da4afc620c") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
torch.manual_seed(0)
# Create small tensors for mu and logvar
# mu: mean of the distribution, shape (2, 4) for batch_size=2, dim=4
mu = torch.randn(2, 4)
# logvar: log variance of the distribution, shape (2, 4)
logvar = torch.randn(2, 4)
# sample: boolean flag to control whether to sample or just return mu
sample = True
ARGS = {
"mu": mu,
"logvar": logvar,
"sample": sample,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| _resolve_horizon_values |
Ran ran, honoured the contract we drafted |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("357d84a515696305") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
torch.manual_seed(0)
batch_size = 2
seq_len = 4
device = torch.device('cpu')
# Test case 1: horizons is None
ARGS = {
'batch_size': batch_size,
'seq_len': seq_len,
'device': device,
'horizons': None,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| build_mlp |
Ran ran; our contract draft was wrong, not the code |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("c4de836a22000029") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Sequential. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
torch.manual_seed(0)
ARGS = {
"input_dim": 10,
"hidden_dim": 16,
"output_dim": 4,
"num_layers": 3,
"dropout": 0.2,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| DynamicsOutput |
Not yet run unverified (harvested, no recorded run) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("a24906696b4c4fa0") How it ran |
| FutureEncoder |
Not yet run unverified (harvested, no recorded run) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("f76eb74950dc308c") How it ran |
| RSSMLatentDynamics |
Not yet run unverified (harvested, no recorded run) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("4833deaf30f5d8aa") How it ran |
| SpatialEncoder |
Not yet run unverified (harvested, no recorded run) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("5f20f3138001a611") How it ran |
| TransformerLatentDynamics |
Not yet run unverified (harvested, no recorded run) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("f82971d8285226cc") How it ran |
| VegetationWorldModel |
Not yet run unverified (harvested, no recorded run) |
arco-group/vegsim/src/models/world_model.py code served (permissive licence) · get_code("e728d2561ebf5e13") How it ran |