Generating a Validation Dataset through Melissa¶
If you already have a validation dataset, you can simply load it during training. However, if you want to generate a validation dataset by sampling parameters through Melissa and launching the solvers offline without any network data reception overhead, you can utilize the OfflineServer.
The OfflineServer is specifically designed to handle parameter sampling and orchestrate the submission of client solver jobs completely decoupled from the training receiver loop.
The Offline Server Structure¶
Since there is no online data reception or model update phase involved, your validation server class only needs to inherit from OfflineServer and configure the parameter space inside the __init__ constructor.
The following example showcases how to create an offline server script (examples/heat-pde/offline/heatpde_offline_server.py) to generate validation data:
import os
import logging
from typing import Dict, Any
from melissa.server.offline_server import OfflineServer
from melissa.server.parameters import ParameterSamplerType
logger = logging.getLogger("melissa")
class HeatPDEOfflineServer(OfflineServer):
"""Server for offline parameter generation and job submission."""
def __init__(self, config_dict: dict[str, Any]):
super().__init__(config_dict)
# Ensure the directory structure exists for the clients
os.makedirs("trajectories", exist_ok=True)
study_options = self.config_dict["study_options"]
Tmin, Tmax = study_options["parameter_range"]
# Halton sequence for validation coverage
self.set_parameter_sampler(
sampler_t=ParameterSamplerType.HALTON, l_bounds=[Tmin], u_bounds=[Tmax], seed=123
)
Client-Side Responsibility¶
When running an offline study, Melissa manages job scheduling and parameter distribution, but data serialization is shifted entirely to the solver client application.
examples/heat-pde/executables/heat_valid_create.cpp shows that instead of executing a network broadcast via melissa::send, the solver can capture the environment metadata (such as MELISSA_SIMU_ID), aggregate the spatial domain matrices, and store the trajectory history locally to disk.
Data Storage Architecture¶
A typical reference implementation generates a structured output directory layout (e.g., VALIDATION_OUT/) containing:
-
checkpoints/sampled_parameters.npy: A 2D parameters matrix generated automatically by the Melissa server metadata system. -
trajectories/sim_{sim_id}.bin: Cohesive flat binary arrays containing all recorded simulation time-steps written out by individual clients.
Generate the Validation Set¶
Loading the Validation Set During Training¶
Once the offline generation phase finishes, you can integrate this data into your main Deep Learning training run. You can instantiate a memory-mapped TrajectoryDataset to stream the data from disk without exhausting system RAM resources:
from offline.dataset import create_trajectory_dataloader
class HeatPDEServerDL(TorchServer):
def __init__(self, config_dict: dict[str, Any]):
super().__init__(config_dict)
...
# Instantiate your custom validation loader pointing to the generated directory
self.valid_dataloader = create_trajectory_dataloader(
directory_path="/path/to/VALIDATION_OUT/",
mesh_size=self.mesh_size * self.mesh_size,
nb_time_steps=self.nb_time_steps,
batch_size=self.dl_config.get("batch_size", 32),
shuffle=False,
)
Note
By setting the self.valid_dataloader attribute in your main TorchServer implementation, Melissa will automatically trigger your validation_step hook every nb_batch_updates training steps.