Skip to content

Retain unmodeled species#84

Merged
JR-1991 merged 6 commits intomainfrom
retain-unmodeled-species
Sep 17, 2025
Merged

Retain unmodeled species#84
JR-1991 merged 6 commits intomainfrom
retain-unmodeled-species

Conversation

@JR-1991
Copy link
Member

@JR-1991 JR-1991 commented Aug 28, 2025

This pull request is based on the discussion in #82 and introduces functionality to automatically remove unmodeled species from EnzymeML documents in the thin layer base class, improves model copying in the Psyces thin layer, and adds comprehensive unit tests for the new behavior. The most important changes are grouped below by theme.

Core functionality: Automatic removal of unmodeled species

  • Added a remove_unmodeled_species parameter to the BaseThinLayer constructor in pyenzyme/thinlayers/base.py. When enabled, species not referenced in any reaction or ODE equation, as well as measurements containing only such species, are removed from the EnzymeML document. The new static method _remove_unmodeled_species implements this logic.

Testing and validation

  • Added a new unit test suite in tests/unit/test_thinlayer.py that verifies correct removal of unmodeled species and measurements, and ensures the option to preserve unmodeled species works as intended. Includes a mock thin layer for testing.

Serialization and model handling

  • Switched from using deepcopy to dill for copying PySCeS models in to_pysces_model to improve compatibility and reliability. Also added dill as a dependency in pyproject.toml. [1] [2] [3]

Dependency management

  • Added dill as a required dependency to pyproject.toml to support serialization of complex Python objects.

These changes improve the robustness of thin layer initialization, ensure data consistency, and provide thorough test coverage for the new species filtering logic.


This change is Reviewable

Introduces a method to filter out species not referenced in reactions or ODEs from EnzymeML documents, and updates measurements accordingly. Adds unit tests to verify correct removal and preservation of unmodeled species based on the new flag.
Replaced usage of deepcopy with dill serialization for copying model objects in InitMap. Added dill as a dependency in pyproject.toml to support this change.
@JR-1991 JR-1991 requested review from Copilot and jmrohwer August 28, 2025 16:16
@JR-1991 JR-1991 added this to EnzymeML Aug 28, 2025
@JR-1991 JR-1991 added bug Something isn't working enhancement New feature or request labels Aug 28, 2025
The deepcopy import was not used in pyenzyme/thinlayers/psyces.py and has been removed to clean up the code.
@JR-1991 JR-1991 moved this to QA in EnzymeML Aug 28, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces functionality to automatically remove unmodeled species from EnzymeML documents in the thin layer base class, improving data consistency and model handling. The changes enable filtering out species that aren't referenced in reactions or ODE equations, along with their associated measurements.

  • Adds a remove_unmodeled_species parameter to BaseThinLayer with automatic species filtering
  • Replaces deepcopy with dill for better PySCeS model serialization
  • Adds comprehensive unit tests for the new species removal functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pyenzyme/thinlayers/base.py Implements core species filtering logic and adds constructor parameter
pyenzyme/thinlayers/psyces.py Switches from deepcopy to dill for model copying
pyproject.toml Adds dill dependency for serialization
tests/unit/test_thinlayer.py Adds comprehensive test suite for species removal functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

The unnecessary 'noqa: F401' comment was removed from the dill import statement in psyces.py, as the import is now used.
The 'remove_unmodeled_species' parameter was removed from BaseThinLayer and related tests. Unmodeled species are now always removed during optimization, simplifying the API and test logic.
Introduces the exclude_unmodeled_species parameter to BaseThinLayer and ThinLayerPysces, allowing control over whether unmodeled species are removed from EnzymeML documents during processing.
@JR-1991
Copy link
Member Author

JR-1991 commented Sep 1, 2025

@jmrohwer As discussed today, I’ve moved the dataset pruning of unmodeled species outside of the __init__-method and into the property-method df which holds the experimental data for fitting. This means the original EnzymeML document remains unchanged, and the pruned data is used for fitting. I’ve added this method to the base thin layer class, so other layers can also utilize it.

Can you test this PR with your data?

@JR-1991 JR-1991 marked this pull request as ready for review September 17, 2025 10:04
@JR-1991 JR-1991 merged commit d7ec01d into main Sep 17, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from QA to Done in EnzymeML Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants