systems.base.numerical_integration.validate_method
systems.base.numerical_integration.validate_method(
method,
backend,
is_stochastic=False,
)Validate method for backend and system type.
Checks if a method is valid for the specified backend and system type (deterministic vs stochastic). Provides detailed error messages for invalid configurations.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| method | str | Method name to validate (canonical or backend-specific) | required |
| backend | Backend | Target backend: ‘numpy’, ‘torch’, or ‘jax’ | required |
| is_stochastic | bool | Whether the system is stochastic (SDE) or deterministic (ODE) | False |
Returns
| Name | Type | Description |
|---|---|---|
| is_valid | bool | True if method is valid, False otherwise |
| error_message | str or None | Description of problem if invalid, None if valid |
Validation Checks
- Normalization: Convert canonical names to backend-specific
- Backend availability: Check if method exists for backend
- Type mismatch: Detect SDE method on deterministic system
Does NOT check: - Whether required packages are installed (diffeqpy, torchsde, etc.) - Whether method will actually work (that’s for integrator factory) - Performance characteristics or accuracy
Examples
Valid configurations:
>>> # Canonical name on appropriate backend
>>> is_valid, error = validate_method('euler_maruyama', 'torch', is_stochastic=True)
>>> print(is_valid)
True
>>> print(error)
None>>> # Backend-specific name
>>> is_valid, error = validate_method('RK45', 'numpy', is_stochastic=False)
>>> print(is_valid)
True>>> # Manual implementation (works everywhere)
>>> is_valid, error = validate_method('rk4', 'jax', is_stochastic=False)
>>> print(is_valid)
TrueInvalid configurations:
>>> # Method doesn't exist for backend
>>> is_valid, error = validate_method('LSODA', 'torch', is_stochastic=False)
>>> print(is_valid)
False
>>> print(error)
Method 'LSODA' not available for torch backend. Available methods: ...>>> # SDE method on deterministic system
>>> is_valid, error = validate_method('euler_maruyama', 'numpy', is_stochastic=False)
>>> print(is_valid)
False
>>> print(error)
SDE method 'euler_maruyama' used on deterministic system>>> # Deterministic method on SDE system (WARNING, not error)
>>> is_valid, error = validate_method('rk4', 'numpy', is_stochastic=True)
>>> print(is_valid)
True # Valid, but may ignore noise (handled elsewhere)Usage in DiscretizedSystem:
>>> # Validate during initialization
>>> normalized_method = normalize_method_name(user_method, backend)
>>> is_valid, error = validate_method(normalized_method, backend, is_stochastic)
>>>
>>> if not is_valid:
... raise ValueError(f"Invalid method configuration: {error}")Pre-flight check before expensive computation:
>>> # Check multiple configurations
>>> configurations = [
... ('rk4', 'numpy', False),
... ('euler_maruyama', 'torch', True),
... ('LSODA', 'jax', False), # This will fail
... ]
>>>
>>> for method, backend, is_stochastic in configurations:
... is_valid, error = validate_method(method, backend, is_stochastic)
... if is_valid:
... print(f"✓ {method} on {backend}")
... else:
... print(f"✗ {method} on {backend}: {error}")Generate user-friendly error messages:
>>> def create_discretization(system, method, backend):
... is_valid, error = validate_method(
... method, backend, system.is_stochastic
... )
...
... if not is_valid:
... # Show user what went wrong
... print(f"Error: {error}")
...
... # Show alternatives
... available = get_available_methods(
... backend,
... method_type='stochastic' if system.is_stochastic else 'deterministic'
... )
... print(f"Try one of: {available['canonical_aliases']}")
... return None
...
... return DiscretizedSystem(system, dt=0.01, method=method)Notes
- Normalization happens automatically before validation
- Does not check if packages (diffeqpy, torchsde) are installed
- Only validates logical consistency, not runtime availability
- Original method name preserved in error messages for clarity
Ambiguous Method Handling: Some methods appear in both deterministic and SDE categories: - ‘euler’: Valid for both contexts (determined by is_stochastic flag) - ‘midpoint’: Valid for both contexts (determined by is_stochastic flag) - When is_stochastic=False and method is SDE-only, validation fails - When is_stochastic=True and method is deterministic, validation passes (with warning handled elsewhere, as noise will be ignored)
Limitations
- Cannot detect if specific method version is buggy
- Cannot check if method is appropriate for problem stiffness
- Cannot verify if tolerances are reasonable
- Does not check hardware compatibility (GPU, TPU)
See Also
normalize_method_name : Normalize before validation get_available_methods : List all methods for backend is_sde_method : Check if method is for stochastic systems