feat: Add NodeDict collection for named node mappings#80
feat: Add NodeDict collection for named node mappings#80ConnorStoneAstro merged 12 commits intodevfrom
Conversation
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #80 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 1612 1688 +76
=========================================
+ Hits 1612 1688 +76
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot can you add unit tests for the dynamic property and for "update" with kwargs. Looks like those cases aren't covered. |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Added in 9b605d4.
|
|
@copilot can you add a section to the advanced tutorial for the NodeTuple, NodeList and NodeDict collections? It should just demo basic behaviour while adding some commentary on what these are useful for. The use cases include creating subsets of params for Gibbs sampling to make dynamic/static, picking out a list of params of interest to single them out for saving/updating, to select collections of modules/params for quick printing, etc. Should mention that collections of nodes assigned to a Module will automatically be turned into an appropriate node collection. Should also mention that the get_values and set_values methods work the same for collections as they do for Modules. |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Added in b6f81d9. The new "Node Collections:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a NodeDict collection type to the caskade library, filling the gap between the existing NodeList (mutable, ordered) and NodeTuple (immutable, ordered) collections with a mutable, key-indexed (str → Node) collection that integrates fully into the caskade DAG. It also auto-promotes plain Python dict assignments on Module attributes to NodeDict, consistent with existing list→NodeList / tuple→NodeTuple promotion.
Changes:
NodeDictimplementation incollection.py: adictsubclass ofNodeCollectionwith full mutation support and automatic link/unlink cycle management.- Auto-promotion in
module.py:Module.__setattr__now converts plaindictof nodes toNodeDict. - Tests and docs: comprehensive tests in
test_collection.pyand a new "Node Collections" section inAdvancedGuide.ipynb.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/caskade/collection.py |
Adds the NodeDict class with all mutation methods |
src/caskade/module.py |
Extends __setattr__ to auto-convert dict of nodes to NodeDict |
src/caskade/__init__.py |
Exports NodeDict as part of the public API |
tests/test_collection.py |
Tests for creation, mutation, param values, and module auto-conversion |
docs/source/notebooks/AdvancedGuide.ipynb |
New "Node Collections" section with usage examples |
.gitignore |
Adds safety-net entries for graphviz intermediate test files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot the review pointed out that if there is an error during one of the operations on the collection (i.e. |
…sure re-linking Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Done in a87467e. Every mutating method in |
NodeDictclass tosrc/caskade/collection.pyNodeDictfromsrc/caskade/__init__.pyModule.__setattr__to auto-convert plain dicts of nodes toNodeDictNodeDicttotests/test_collection.pydynamicpropertyupdatewith kwargsdocs/source/notebooks/AdvancedGuide.ipynbNodeListandNodeDictmutation methods intry/finallyso_link_nodes()is always called even when an error occursOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.