You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
The current system requires a complete TOML file for operation and has default values scattered and hardcoded within the codebase.
The new design will introduce a layered configuration model with a clear hierarchy of precedence: CLI Arguments > TOML File > Built-in Defaults. This will be achieved by creating a centralized default configuration module and leveraging serde and clap's advanced features. The primary goal is to make the tool more accessible to new users by providing scientifically sound defaults, while retaining full customizability for expert users.
Tasks:
Phase 1: Centralize All Default Parameters
Create a new module config/defaults.rs.
Define all default values for forcefield, sampling, and optimization parameters as constants within this module (e.g., S_FACTOR, MAX_ITERATIONS).
Create serde-compatible helper functions (e.g., fn default_s_factor() -> f64) for each default value.
Audit: Systematically scan the entire codebase, particularly config.rs and commands/place.rs, to identify and list all existing hardcoded default values (e.g., unwrap_or(100)). Ensure a corresponding default is created in the new module.
Phase 2: Architect the Layered Configuration Structs
Create a new module config/core.rs.
Define the primary Config struct and its sub-structs (ForcefieldConfig, OptimizationConfig, etc.). These structs will not use Option<T> for their fields.
Implement the Default trait for Config and all sub-structs, using the functions from the defaults.rs module.
Annotate all fields with #[serde(default = "...")] to ensure that serde uses our default functions when a field is missing from a TOML file.
Move the existing Partial...Config structs (which use Option<T>) into a separate module, config/partial.rs. Their sole purpose will be to parse TOML files.
Phase 3: Refactor CLI Arguments for Override Capability
In cli.rs:
Create a new ConfigArgs struct that mirrors the fields in PartialConfig (all fields as Option<T>).
Annotate ConfigArgs with #[derive(Args)].
In the main PlaceArgs struct, replace individual config-related arguments (like --s-factor) with #[command(flatten)] pub config_overrides: ConfigArgs.
Change the -c, --config argument from required = true to optional (Option<PathBuf>).
Unit Test: Add a test to verify that clap correctly parses the new flattened arguments (e.g., --max-iterations 150).
Phase 4: Implement and Integrate the New Loading Logic
Create a new module config/loader.rs with a public function load_and_merge_config.
Implement the three-layer merge logic within this function:
Start by creating an instance of Config::default().
If a config file path is provided, parse it into PartialConfig and merge its Some(...) values into the Config instance.
Merge the Some(...) values from the CLI's ConfigArgs into the Config instance.
In commands/place.rs:
Completely remove the old PartialPlacementConfig::merge_with_cli function.
Replace the configuration logic with a single call to config::loader::load_and_merge_config.
Crucial Cleanup: Search for and remove all remaining hardcoded unwrap_or(...) calls related to configuration, ensuring the PlacementConfig from the loader is the sole source of truth.
Description:
The current system requires a complete TOML file for operation and has default values scattered and hardcoded within the codebase.
The new design will introduce a layered configuration model with a clear hierarchy of precedence: CLI Arguments > TOML File > Built-in Defaults. This will be achieved by creating a centralized default configuration module and leveraging
serdeandclap's advanced features. The primary goal is to make the tool more accessible to new users by providing scientifically sound defaults, while retaining full customizability for expert users.Tasks:
Phase 1: Centralize All Default Parameters
config/defaults.rs.S_FACTOR,MAX_ITERATIONS).serde-compatible helper functions (e.g.,fn default_s_factor() -> f64) for each default value.config.rsandcommands/place.rs, to identify and list all existing hardcoded default values (e.g.,unwrap_or(100)). Ensure a corresponding default is created in the new module.Phase 2: Architect the Layered Configuration Structs
config/core.rs.Configstruct and its sub-structs (ForcefieldConfig,OptimizationConfig, etc.). These structs will not useOption<T>for their fields.Defaulttrait forConfigand all sub-structs, using the functions from thedefaults.rsmodule.#[serde(default = "...")]to ensure thatserdeuses our default functions when a field is missing from a TOML file.Partial...Configstructs (which useOption<T>) into a separate module,config/partial.rs. Their sole purpose will be to parse TOML files.Phase 3: Refactor CLI Arguments for Override Capability
cli.rs:ConfigArgsstruct that mirrors the fields inPartialConfig(all fields asOption<T>).ConfigArgswith#[derive(Args)].PlaceArgsstruct, replace individual config-related arguments (like--s-factor) with#[command(flatten)] pub config_overrides: ConfigArgs.-c, --configargument fromrequired = trueto optional (Option<PathBuf>).clapcorrectly parses the new flattened arguments (e.g.,--max-iterations 150).Phase 4: Implement and Integrate the New Loading Logic
config/loader.rswith a public functionload_and_merge_config.Config::default().PartialConfigand merge itsSome(...)values into theConfiginstance.Some(...)values from the CLI'sConfigArgsinto theConfiginstance.commands/place.rs:PartialPlacementConfig::merge_with_clifunction.config::loader::load_and_merge_config.unwrap_or(...)calls related to configuration, ensuring thePlacementConfigfrom the loader is the sole source of truth.