Configuration Guideļ
The homodyne package uses JSON configuration files to specify analysis parameters, file paths, and options.
Available Analysis Methodsļ
The homodyne package provides three main categories of parameter estimation methods:
Classical Optimization Methods:
Nelder-Mead: Derivative-free simplex method, robust for noisy functions
Gurobi: Quadratic programming solver (requires license), efficient for smooth functions
Robust Optimization Methods:
Wasserstein DRO: Distributionally robust optimization with Wasserstein uncertainty sets
Scenario-based: Multi-scenario optimization using bootstrap resampling
Ellipsoidal: Bounded uncertainty robust least squares
Method Selection:
# Use classical methods only
homodyne --method classical --config my_config.json
# Use robust methods only
homodyne --method robust --config my_config.json
# Use all available methods
homodyne --method all --config my_config.json
Quick Configurationļ
Generate a Template:
# Create configuration for specific mode
homodyne-config --mode static_isotropic --sample my_experiment
Basic Structure:
{
"analysis_settings": {
"static_mode": true,
"static_submode": "isotropic"
},
"file_paths": {
"c2_data_file": "data/correlation_data.h5",
"phi_angles_file": "data/phi_angles.txt"
},
"initial_parameters": {
"values": [1000, -0.5, 100]
}
}
Configuration Sectionsļ
v1.0.0 Configuration Featuresļ
Frame Counting Convention (Critical):
Frame counting uses 1-based inclusive indexing that is converted to 0-based Python slicing:
{
"experimental_data": {
"start_frame": 401, // First frame (1-based, inclusive)
"end_frame": 1000 // Last frame (1-based, inclusive)
}
}
Formula: time_length = end_frame - start_frame + 1
Examples:
- start_frame=1, end_frame=100 ā time_length=100 (not 99!)
- start_frame=401, end_frame=1000 ā time_length=600 (not 599!)
Conditional Angle Subsampling:
Automatically preserves angular information when n_angles < 4:
{
"subsampling": {
"n_angles": 4, // Target number of angles for subsampling
"n_time_points": 16, // Target number of time points
"strategy": "conditional", // Automatic angle preservation
"preserve_angular_info": true
}
}
Behavior:
- When n_angles < 4: All angles preserved (e.g., 2 angles ā 2 angles)
- When n_angles >= 4: Subsample to 4 angles (e.g., 10 angles ā 4 angles)
- Time subsampling still applied for performance (~16x reduction)
Analysis Settingsļ
Controls the analysis mode and behavior:
{
"analysis_settings": {
"static_mode": true, // true for static, false for flow
"static_submode": "isotropic", // "isotropic" or "anisotropic"
"enable_angle_filtering": true, // Enable angle filtering optimization
"angle_filter_ranges": [[-5, 5], [175, 185]] // Angle ranges to analyze
}
}
File Pathsļ
Specify input data locations:
{
"file_paths": {
"c2_data_file": "data/my_correlation_data.h5", // Main data file
"phi_angles_file": "data/scattering_angles.txt", // Angle file
"output_directory": "results/" // Output location
}
}
Initial Parametersļ
Starting values for optimization:
{
"initial_parameters": {
"parameter_names": ["D0", "alpha", "D_offset"],
"values": [1000, -0.5, 100],
"active_parameters": ["D0", "alpha", "D_offset"] // Parameters to optimize
}
}
Parameter Bounds and Constraintsļ
Optimization constraints and parameter bounds:
{
"parameter_space": {
"bounds": [
{"name": "D0", "min": 100, "max": 10000, "type": "Normal"},
{"name": "alpha", "min": -2.0, "max": 2.0, "type": "Normal"},
{"name": "D_offset", "min": 0, "max": 1000, "type": "Normal"}
]
}
}
Note
Parameter Bounds: The type field specifies the parameter distribution type for bounds checking. All seven parameters (D0, alpha, D_offset, gamma_dot_t0, beta, gamma_dot_t_offset, phi0) use Normal distributions for bounds specification.
Parameter Constraints and Rangesļ
The homodyne package implements comprehensive physical constraints to ensure scientifically meaningful results:
Core Model Parameters
Parameter |
Range |
Distribution |
Physical Constraint |
|---|---|---|---|
|
[1.0, 1000000.0] à ²/s |
TruncatedNormal(μ=10000.0, Ļ=1000.0) |
Must be positive |
|
[-2.0, 2.0] |
Normal(μ=-1.5, Ļ=0.1) |
none |
|
[-100, 100] à ²/s |
Normal(μ=0.0, Ļ=10.0) |
none |
|
[1e-06, 1.0] sā»Ā¹ |
TruncatedNormal(μ=0.001, Ļ=0.01) |
Must be positive |
|
[-2.0, 2.0] |
Normal(μ=0.0, Ļ=0.1) |
none |
|
[-0.01, 0.01] sā»Ā¹ |
Normal(μ=0.0, Ļ=0.001) |
none |
|
[-10, 10] degrees |
Normal(μ=0.0, Ļ=5.0) |
angular |
Physical Function Constraints
The package automatically enforces positivity for time-dependent functions:
D(t) = Dā(t)^α + D_offset ā max(D(t), 1Ć10ā»Ā¹ā°)
Prevents negative diffusion coefficients from any parameter combination
Maintains numerical stability with minimal threshold
γĢ(t) = γĢā(t)^β + γĢ_offset ā max(γĢ(t), 1Ć10ā»Ā¹ā°)
Prevents negative shear rates from any parameter combination
Ensures physical validity in all optimization scenarios
Scaling Parameters for Correlation Functions
The relationship c2_fitted = c2_theory Ć contrast + offset uses bounded parameters:
Parameter |
Range |
Distribution |
Physical Meaning |
|---|---|---|---|
|
(0.05, 0.5] |
TruncatedNormal(μ=0.3, Ļ=0.1) |
Correlation strength scaling |
|
(0.05, 1.95) |
TruncatedNormal(μ=1.0, Ļ=0.2) |
Baseline correlation level |
|
[1.0, 2.0] |
derived |
Final correlation function |
|
[0.0, 1.0] |
derived |
Theoretical correlation bounds |
Optimization Configurationļ
Classical Optimization:
{
"optimization_config": {
"classical_optimization": {
"methods": ["Nelder-Mead"],
"method_options": {
"Nelder-Mead": {
"maxiter": 1000,
"xatol": 1e-6,
"fatol": 1e-6
},
"Gurobi": {
"max_iterations": 1000,
"tolerance": 1e-6,
"output_flag": 0,
"method": 2,
"time_limit": 300
}
}
}
}
}
Available Optimization Methods:
Nelder-Mead: Derivative-free simplex method, robust for noisy functions
Gurobi: Quadratic programming solver (requires license), good for smooth functions with bounds
Note
Gurobi is automatically detected if installed and licensed. It uses quadratic approximation via finite differences and excels with smooth objective functions and bounds constraints.
Robust Optimization Configuration:
{
"optimization_config": {
"robust_optimization": {
"enabled": true,
"uncertainty_model": "wasserstein",
"method_options": {
"wasserstein": {
"uncertainty_radius": 0.02,
"regularization_alpha": 0.005
},
"scenario": {
"n_scenarios": 30,
"bootstrap_method": "residual",
"parallel_scenarios": true
},
"ellipsoidal": {
"gamma": 0.08,
"l1_regularization": 0.0005,
"l2_regularization": 0.005
}
},
"solver_settings": {
"preferred_solver": "CLARABEL",
"timeout": 300,
"enable_caching": true
}
}
}
}
Robust Methods Available:
Wasserstein DRO: Distributionally robust optimization using Wasserstein uncertainty sets
Scenario-based: Multi-scenario optimization using bootstrap resampling for outlier resistance
Ellipsoidal: Robust least squares with bounded uncertainty in correlation functions
Performance Settingsļ
Optimize computation:
{
"performance_settings": {
"num_threads": 4,
"data_type": "float64",
"memory_limit_gb": 8,
"enable_jit": true
}
}
Configuration Templatesļ
Static Isotropic Template:
{
"metadata": {
"config_version": "6.0",
"analysis_mode": "static_isotropic"
},
"analysis_settings": {
"static_mode": true,
"static_submode": "isotropic"
},
"file_paths": {
"c2_data_file": "data/correlation_data.h5"
},
"initial_parameters": {
"parameter_names": ["D0", "alpha", "D_offset"],
"values": [1000, -0.5, 100],
"active_parameters": ["D0", "alpha", "D_offset"]
},
"parameter_space": {
"bounds": [
{"name": "D0", "min": 100, "max": 10000, "type": "Normal"},
{"name": "alpha", "min": -2.0, "max": 2.0, "type": "Normal"},
{"name": "D_offset", "min": 0, "max": 1000, "type": "Normal"}
]
}
}
Laminar Flow Template:
{
"metadata": {
"config_version": "6.0",
"analysis_mode": "laminar_flow"
},
"analysis_settings": {
"static_mode": false,
"enable_angle_filtering": true,
"angle_filter_ranges": [[-5, 5], [175, 185]]
},
"file_paths": {
"c2_data_file": "data/correlation_data.h5",
"phi_angles_file": "data/phi_angles.txt"
},
"initial_parameters": {
"parameter_names": ["D0", "alpha", "D_offset", "gamma_dot_t0", "beta", "gamma_dot_t_offset", "phi0"],
"values": [1000, -0.5, 100, 10, 0.5, 1, 0],
"active_parameters": ["D0", "alpha", "D_offset", "gamma_dot_t0"]
},
"optimization_config": {
"classical_optimization": {
"methods": ["Nelder-Mead"],
"method_options": {
"Nelder-Mead": {"maxiter": 5000}
}
},
"robust_optimization": {
"enabled": true,
"uncertainty_model": "wasserstein"
}
}
}
Configuration Validationļ
Check Configuration Syntax:
# Validate JSON syntax
python -m json.tool my_config.json
Test Configuration:
from homodyne import ConfigManager
# Load and validate configuration
config = ConfigManager("my_config.json")
config.validate()
print("ā
Configuration is valid")
Common Configuration Patternsļ
High-Performance Setup:
{
"analysis_settings": {
"enable_angle_filtering": true,
"angle_filter_ranges": [[-10, 10], [170, 190]]
},
"performance_settings": {
"num_threads": 8,
"data_type": "float32",
"enable_jit": true
}
}
Multi-Method Optimization Setup:
{
"optimization_config": {
"classical_optimization": {
"methods": ["Nelder-Mead", "Gurobi"],
"method_options": {
"Nelder-Mead": {"maxiter": 5000},
"Gurobi": {"time_limit": 600}
}
},
"robust_optimization": {
"enabled": true,
"uncertainty_model": "wasserstein",
"uncertainty_radius": 0.03
}
},
"validation_rules": {
"fit_quality": {
"overall_chi_squared": {
"excellent_threshold": 5.0,
"acceptable_threshold": 10.0
}
}
}
}
Environment Variablesļ
You can use environment variables in configurations:
{
"file_paths": {
"c2_data_file": "${DATA_DIR}/correlation_data.h5",
"output_directory": "${HOME}/homodyne_results"
}
}
Set environment variables:
export DATA_DIR=/path/to/data
export HOME=/home/username
Troubleshootingļ
Configuration Errors:
Invalid JSON: Check syntax with
python -m json.tool config.jsonMissing files: Verify all file paths exist
Parameter bounds: Ensure min < max for all parameters
Mode mismatch: Check that parameters match the selected analysis mode
Performance Issues:
Enable angle filtering for faster computation
Use
float32data type to reduce memory usageIncrease
num_threadsto match your CPU coresSet appropriate
memory_limit_gbbased on available RAM