Create Generic Function for Executing Commands with Attribute Tracking and Validation
Description
We need a generic function that can execute a command on a provided object, track specified attributes before and after execution, log the results, and perform optional validations or checks. This function will be used throughout our simulation to monitor changes in metabolite levels and ensure conservation laws are respected.
Requirements
The function should accept the following parameters:
obj: The object on which to execute the command
command: The method of the object to be called
tracked_attributes: List of attribute names to track
args: Positional arguments to pass to the command (optional)
kwargs: Keyword arguments to pass to the command (optional)
validations: List of validation functions to run after execution (optional)
The function should:
Log initial values of tracked attributes
Execute the specified command
Log final values of tracked attributes
Calculate and log changes in tracked attributes
Perform any specified validations
Return a dictionary containing the results and tracked attribute values
The function should use Python's logging module for all logging operations
The function should handle both numeric and non-numeric attributes
The function should be type-hinted for better code readability and IDE support
Acceptance Criteria
The function is implemented as specified in the requirements
The function is well-documented with docstrings explaining its purpose, parameters, and return value
The function handles errors gracefully, logging warnings for failed validations rather than raising exceptions
The function is tested thoroughly (see Test Cases section)
The function is integrated into at least one existing part of the simulation (e.g., the Glycolysis class) as a proof of concept
Test Cases
Test with a simple object and command, tracking numeric attributes
Test with a complex object (e.g., Organelle) and command, tracking both numeric and non-numeric attributes
Test with no tracked attributes (should not raise an error)
Test with invalid tracked attributes (should log a warning and continue)
Test with a validation function that passes
Test with a validation function that fails (should log a warning)
Test with multiple validation functions
Test error handling when the command raises an exception
Implementation Details
Create a new file utils/tracking.py to house this function
Import and use the function in relevant parts of the simulation, such as the Glycolysis class
Update any existing tests that may be affected by this change
Related Issues
123 Improve metabolite tracking in glycolysis simulation
456 Implement conservation law checks across all reactions
Create Generic Function for Executing Commands with Attribute Tracking and Validation
Description
We need a generic function that can execute a command on a provided object, track specified attributes before and after execution, log the results, and perform optional validations or checks. This function will be used throughout our simulation to monitor changes in metabolite levels and ensure conservation laws are respected.
Requirements
The function should accept the following parameters:
obj
: The object on which to execute the commandcommand
: The method of the object to be calledtracked_attributes
: List of attribute names to trackargs
: Positional arguments to pass to the command (optional)kwargs
: Keyword arguments to pass to the command (optional)validations
: List of validation functions to run after execution (optional)The function should:
The function should use Python's logging module for all logging operations
The function should handle both numeric and non-numeric attributes
The function should be type-hinted for better code readability and IDE support
Acceptance Criteria
Test Cases
Implementation Details
utils/tracking.py
to house this functionRelated Issues
123 Improve metabolite tracking in glycolysis simulation
456 Implement conservation law checks across all reactions
Estimated Time
4-6 hours
Priority
High
Assigned To
[Your Name]
Labels
enhancement, simulation, testing