-
Notifications
You must be signed in to change notification settings - Fork 21
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
Added string model parsing in clingo wrapper #110
Conversation
Thanks, @camcunningham ! The functionality looks good, but we try to avoid duplicating so much code whenever possible. In this case, looks like the PR could be easily refactored e.g. with one single method with signature def parse_model(*, symbol_mapping, filename=None, content=None) then some check to make user the user provides Do you think you'd have the time to refactor the PR along those lines? |
@gfrances Absolutely! Makes a lot of sense - I'll make those changes tonight |
@gfrances Made some of those changes. Ended up iterating through the lines without a generator - didn't know if I'd need to use one. If you still want that I'd be happy to refactor |
I suggested the use of a generator because it would avoid the need for loading the entire file in memory, which is what the call to |
Makes sense - I'll make those changes. Thanks for the info on generators! |
Hm. That's strange. It passed the checks before the swap to generators - did I do it wrong or is there potentially an issue with using them there? |
Seems to be issues with the grounding on the docs with the LP solver. E.g., https://travis-ci.com/github/aig-upf/tarski/jobs/510458691 @gfrances -- any chance there's issues with gringo installing on travis? |
Nope, it's just that this line is iterating over the characters of the filename, not over the contents of the filename. Should be something like:
|
Codecov Report
@@ Coverage Diff @@
## devel #110 +/- ##
=======================================
Coverage 98.19% 98.19%
=======================================
Files 47 47
Lines 3046 3046
Branches 114 114
=======================================
Hits 2991 2991
Misses 45 45
Partials 10 10 Continue to review full report at Codecov.
|
Ah - that was dumb of me! Took your suggestion way too literally. Should be good to go now. |
def parse_model(*, filename=None, content=None, symbol_mapping): | ||
if filename and not content: | ||
with open(filename, "r") as f: | ||
return _parse_model((l for l in f), symbol_mapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this make it an iterator, or build the full list before calling the method? Might seem weird, but would just passing in f
work? It's treated as lines
in _parse_model
, and may well be just the iterator you're looking for...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (...)
syntax creates a generator, but you're totally right that passing in f
should work as well;
likewise, passing in content.splitlines()
below should work too.
@gfrances Any other changes you think need to be made? |
I would maybe just adopt the suggestion by Chris, passing |
Thanks @camcunningham, @haz ! |
A sort of addition onto my last commit - same theme. Needed to be able to create a model based on a string instead of a temp file. If there should be a better naming convention, feel free to change it up.
Again, if this functionality exists elsewhere, let me know!