Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network representation optimizations for JSON encoding #217

Merged
merged 24 commits into from
Jan 4, 2024

Conversation

ianmkenney
Copy link
Collaborator

@ianmkenney ianmkenney commented Dec 22, 2023

Fixes #216

This PR implements a graph based optimization for representing gufe objects as an order dependent chain of keyed dicts, dramatically reducing memory usage (~ -97% for JSON representation size of our test networks).

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (c17a423) 81.23% compared to head (b1dba97) 82.10%.

Files Patch % Lines
alchemiscale/interface/api.py 85.71% 2 Missing ⚠️
alchemiscale/interface/client.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
+ Coverage   81.23%   82.10%   +0.86%     
==========================================
  Files          22       23       +1     
  Lines        2873     2939      +66     
==========================================
+ Hits         2334     2413      +79     
+ Misses        539      526      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@dotsdl dotsdl left a comment

Choose a reason for hiding this comment

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

Looking fantastic @ianmkenney! This is a huge improvement!

Can you also add a unit test (not integration test) for each of the methods this PR adds in alchemiscale.utils? We want to be sure in a fairly isolated way that any GufeTokenizables these methods handle are working as expected via these unit tests.

alchemiscale/base/api.py Show resolved Hide resolved
@@ -14,6 +14,7 @@
from gufe import AlchemicalNetwork, ChemicalSystem, Transformation
from gufe.protocols import ProtocolDAGResult
from gufe.tokenization import GufeTokenizable, JSON_HANDLER
import networkx as nx
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we use this import in this module.

@@ -317,12 +317,10 @@ def get_transformation(
validate_scopes(sk.scope, token)

transformation = n4js.get_gufe(scoped_key=sk)
return gufe_to_json(transformation)
return GufeJSONResponse(content=transformation)
Copy link
Member

Choose a reason for hiding this comment

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

My OCD: remove content= for consistency elsewhere. 😉

@@ -17,6 +17,7 @@
from gufe import AlchemicalNetwork, Transformation, ChemicalSystem
from gufe.tokenization import GufeTokenizable, JSON_HANDLER, GufeKey
from gufe.protocols import ProtocolResult, ProtocolDAGResult
import networkx as nx
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we use this import in this module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

seems we do, see get_transformation_tasks

Copy link
Member

Choose a reason for hiding this comment

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

Oh that's strange; not sure how we didn't already have this import 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we did, I added it as a repeated import because I didn't notice it 😮‍💨



def gufe_to_digraph(gufe_obj):
"""Recursively construct a DiGraph from a GufeTokenizable."""
Copy link
Member

Choose a reason for hiding this comment

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

Add something like:

This DiGraph encodes the dependency structure of the GufeTokenizable on other GufeTokenizables.

@@ -6,6 +6,9 @@

from alchemiscale.models import ScopedKey
from alchemiscale.base.client import json_to_gufe
from alchemiscale.utils import keyed_dicts_to_gufe, gufe_to_keyed_dicts

import networkx as nx
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this import is used in this module.

Copy link
Member

@dotsdl dotsdl left a comment

Choose a reason for hiding this comment

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

Amazing work @ianmkenney! Merging!

@dotsdl dotsdl merged commit 16b2776 into main Jan 4, 2024
4 checks passed
@dotsdl dotsdl deleted the 216-network-JSON-encoding branch January 4, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AlchemiscaleClient.create_network scales poorly with increasing AlchemicalNetwork size
3 participants