Repository navigation
Add Problem.get_unused_id - #561
Conversation
Add `petab.v2.Problem.get_unused_id`, which returns the given base ID or the first unused `<base>_<n>`. It checks PEtab entity IDs, condition targets, symbols in expressions and overrides, and model entity IDs. Use it in `assignments_to_experiments`, which previously only checked condition IDs and could create condition IDs that clash with, e.g., parameter IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84531a2 to
eb3c412
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #561 +/- ##
==========================================
+ Coverage 78.07% 78.19% +0.11%
==========================================
Files 68 68
Lines 7823 7842 +19
Branches 1399 1400 +1
==========================================
+ Hits 6108 6132 +24
+ Misses 1227 1224 -3
+ Partials 488 486 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| ids |= {c.id for c in self.conditions} | ||
| ids |= {e.id for e in self.experiments} | ||
| ids |= {m.petab_id for m in self.mappings} | ||
| ids |= {ch.target_id for c in self.conditions for ch in c.changes} |
There was a problem hiding this comment.
Is this necessary? If it's to account for SBML model IDs, isn't that already done above, specifically:
or any(m.has_entity_with_id(id_) for m in self.models)
targetId must be a reference in the condition table (I assume), and therefore redundant here.
There was a problem hiding this comment.
Technically you are right. If the PEtab problem is valid, this would be covered. If not – for example, if the target ID is not defined in the model yet – a newly added entity with the just checked ID might make it valid and unintentionally cover up the initial error. It's a bit hypothetical, but I guess I'd just leave it in there unless it turns out to be a performance bottleneck.
Adds
petab.v2.Problem.get_unused_id(base, *, exclude=()), which returnsbaseif it is unused, otherwise the first unusedbase_1,base_2, .... It treats an ID as used if it is any of the following:assignments_to_experimentsnow uses it for its newcond_<n>conditions. Before, it only checked condition IDs, so it could create a condition with the ID of, for example, a parameter.excludeis for choosing several IDs before adding the corresponding entities to the problem.🤖 Generated with Claude Code