The experiment launcher is graphids.exp.run. It accepts a typed
RunConfig, constructs Ray TorchTrainer directly, and runs the worker loop
that builds data/model/trainer objects from YAML config.
Current stages:
fit / test -> Lightning trainer launch with config-driven data/model
instantiation, Ray Lightning strategy/environment, and Ray checkpoint/metric
reporting.
Ray normally uses its report callback for checkpointing. Supplying a Lightning
ModelCheckpoint callback also enables Lightning checkpointing by default; an
explicit trainer.enable_checkpointing setting takes precedence.
Sha256ModelCheckpoint(save_last=True) saves the latest eligible epoch even
when its monitored score ties or regresses. Best-checkpoint selection remains
separate, and every saved checkpoint has a SHA256 sidecar.
defbuild_component(spec:Any)->Any:"""Build a component config, or return an instantiated class-path object. ``build`` is the optional construction hook at this config boundary. Errors from the builder propagate unchanged. """resolved=resolve_spec(spec)builder=getattr(resolved,"build",None)returnbuilder()ifbuilderisnotNoneelseresolved
defexecute_run(run:RunConfig,*,ray:bool=False)->dict[str,Any]:"""Own the run lifecycle; tracking and Ray consume the saved result."""writer=Trueifray:fromrayimporttrainwriter=train.get_context().get_world_rank()==0logger=Nonemode=tracking_mode()ifwriter:write_config(run)record_status(run,"running",message="worker_started",tracking_mode=mode)try:if(run.resources.accelerator=="gpu"andrun.payload.model.get("type")=="event_graph_mamba"andrun.payload.model.get("backend","official")=="official"):fromgraphids.runtime_checksimportassert_mamba_backendassert_mamba_backend()ifwriterandmode=="online":logger=make_logger(run)result=run_lightning(run,logger=logger,ray=ray)ifwriter:record_status(run,"finished",result=result)ifloggerisnotNoneandlogger.run_idisnotNone:logger.experiment.set_terminated(logger.run_id,status="FINISHED")returnresultexceptBaseExceptionasexc:ifwriter:record_status(run,"failed",failure=f"{type(exc).__name__}: {exc}")ifloggerisnotNoneandlogger.run_idisnotNone:logger.experiment.set_terminated(logger.run_id,status="FAILED")raise
deflaunch_run(run:RunConfig,*,address:str|None=None)->RunSummary:"""Launch the supported single-worker run in a local or allocated Ray cluster."""try:importrayfromray.trainimportRunConfigasRayRunConfigfromray.trainimportScalingConfigfromray.train.torchimportTorchTrainerexceptModuleNotFoundErrorasexc:raiseRuntimeError("Ray is not installed. Install the project dependencies before launching experiments.")fromexctry:ifnotray.is_initialized():ray.init(address=address,ignore_reinit_error=True)resources=run.resourcesuse_gpu=resources.accelerator=="gpu"orresources.gpus_per_worker>0worker_resources={"CPU":max(1,resources.cpus_per_worker)}ifuse_gpu:worker_resources["GPU"]=resources.gpus_per_workeror1TorchTrainer(_worker_loop,train_loop_config={"run":run.model_dump(mode="json")},scaling_config=ScalingConfig(num_workers=1,use_gpu=use_gpu,resources_per_worker=worker_resources,),run_config=RayRunConfig(storage_path=str(run.outputs.run_dir.parent),name=run.outputs.run_dir.name,),).fit()exceptBaseExceptionasexc:manifest=load_manifest(run.outputs.run_dir,name=run.outputs.manifest_name)ifmanifestisNoneormanifest.status!="failed":write_config(run)record_status(run,"failed",failure=f"{type(exc).__name__}: {exc}",tracking_mode=tracking_mode(),)raisesummary=summarize_run(run.outputs.run_dir)ifsummaryisNone:raiseRuntimeError(f"Ray run finished without a GraphIDS manifest: {run.outputs.run_dir}")returnsummary
defprobe_ray_train_imports()->dict[str,str]:"""Import the Ray APIs GraphIDS relies on and return their module paths."""try:fromray.trainimportRunConfigasRayRunConfigfromray.trainimportScalingConfigfromray.train.lightningimport(RayDDPStrategy,RayLightningEnvironment,RayTrainReportCallback,prepare_trainer,)fromray.train.torchimportTorchTrainerexceptModuleNotFoundErrorasexc:raiseRuntimeError("Ray is not installed. Install the project dependencies before launching experiments.")fromexcreturn{"RunConfig":RayRunConfig.__module__,"ScalingConfig":ScalingConfig.__module__,"TorchTrainer":TorchTrainer.__module__,"prepare_trainer":prepare_trainer.__module__,"RayDDPStrategy":RayDDPStrategy.__module__,"RayLightningEnvironment":RayLightningEnvironment.__module__,"RayTrainReportCallback":RayTrainReportCallback.__module__,}
defresolve_spec(spec:Any)->Any:"""Resolve a nested component/class-path spec without calling ``build()``."""ifisinstance(spec,BaseModel):spec=spec.model_dump(mode="json")ifisinstance(spec,list):return[resolve_spec(item)foriteminspec]ifnotisinstance(spec,Mapping):returnspecif"class_path"inspec:class_path=str(spec["class_path"])module_path,_,class_name=class_path.rpartition(".")cls=getattr(importlib.import_module(module_path),class_name)init_args={k:resolve_spec(v)fork,vindict(spec.get("init_args")or{}).items()}returncls(**init_args)if"type"inspec:matchspec["type"]:case"can_event_dm":fromgraphids.data.configimportCANEventDataConfigconfig_class=CANEventDataConfigcase"event_graph_mamba":fromgraphids.models.configimportEventGraphMambaConfigconfig_class=EventGraphMambaConfigcase_:raiseValueError(f"unknown component type: {spec['type']!r}")returnconfig_class.model_validate({k:resolve_spec(v)fork,vinspec.items()})return{k:resolve_spec(v)fork,vinspec.items()}
execute_run also supports local Lightning diagnostics. records owns durable
status/results; tracking owns MLflow exports. Execution is limited to one
node/device, matching the active event contract.