Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a typed parameter schema system for pest/disease risk model engines, enabling more robust validation and extensibility for model-specific parameters. It adds new engine parameter schemas, updates the catalog to use them, and refactors existing model code to leverage these typed parameters. The changes also provide a mechanism for registering and retrieving engine parameter schemas via the model registry.
Key changes include:
Engine parameter schema system
EngineParamsBaseand specific subclasses (e.g.,FuzzyMamdaniParams,PowderyMildewGrapeParams) inengine_params.pyto define and validate engine-specific parameters using Pydantic, with model validators for domain-specific constraints.PestModelBaseto support an optionalengine_params_schemaclass variable, allowing each model to declare its parameter schema.Model registry enhancements
ModelRegistryto index and retrieve engine parameter schemas byengine_type, and added theEngineTypeNotFoundexception for missing schemas.Catalog and threat definition updates
pest_catalog.jsonto includeengine_typeandengine_paramsfields for threats, notably for "Powdery mildew" (grape) and added a new entry for "Pear scab" (pear), both specifying their engine and parameters.ThreatDefinitionto support lazy validation ofengine_paramsvia the registry, and to bridge legacy fuzzy rules if no typed params are present.Model refactoring for parameterization
PowderyMildewGrapemodel to use the newPowderyMildewGrapeParamsschema for all engine parameters, replacing hardcoded constants with values from the schema and updating logic accordingly.Type and import improvements
These changes lay the groundwork for a more extensible and robust model engine system, allowing for easier integration of new models and parameter types in the future.
Example: adding a model with its own engine type (Apple Scab, Mills-type)
A new engine type needs only a params schema, a model class and an entry point. No core changes.
1. Params schema
Subclass
EngineParamsBasewith a uniqueengine_typeliteral (the registry lookup key).2. Model
Subclass
PestModelBase, declaremetadataandengine_params_schema, and read per-threat overrides incalculate().3. Entry point
In
pyproject.toml(third-party packages do the same in their own):Re-run
pip install -e .to pick it up.4. Threat
In
src/agstack_pnd/catalog/data/pest_catalog.json, on the apple Venturia inaequalis entry:Threats without
engine_paramskeep the legacyfuzzy_rulesbehaviour.5. Verify