-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add interface for defining external statistics. #23
Conversation
* Single-thread builds must not (yet) use C++11 features.
I'll talk to Max. It is probably a good idea to try to use this for the statistics in clingo and give feedback based on this. -R |
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.
Looks good, thanks for your effort.
CHANGES
Outdated
@@ -1,5 +1,6 @@ | |||
clasp 3.3.4: | |||
* fixed: Atoms of incremental programs not always marked as frozen. | |||
* added internal interface for user defined statistics |
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.
For consistency, I’d write “user-defined“ with a hyphen here as well.
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.
Yep. Thanks.
src/clasp_facade.cpp
Outdated
if (f.incremental()) { | ||
accu_ = new Accu(); | ||
accu_->step.bind(*f.accu_.get()); | ||
} | ||
setRoot(keys_.toStats()); | ||
} | ||
void ClaspFacade::Statistics::ClingoView::update(const ClaspFacade::Statistics& stats) { | ||
if (stats.userStats_.get() && !stats.userStats_->empty()) { | ||
keys_.add("userdefined", stats.userStats_->toStats()); |
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.
Is there a reason why userdefined
is spelled without a hyphen here? I know that comment is a bit picky, but it might be inconvenient to make such things consistent at a later point in time.
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.
For consistency, this should be user_defined
. Or alternatively, external
to indicate that these are not maintained by clasp.
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.
Okay. I was just referring to the fact that “user-defined” is a compound adjective and should be written with a hyphen, but if hyphens are not allowed within keys, that’s just how it is 🙂.
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.
Sorry, I forgot to add the "Yep, you are right". I just wanted to express that our keys typically use underscores (and unfortunately sometimes camel-case) instead of hyphens.
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.
I totally understand, thanks for the info … and sorry about the fuss and my pedantry anyway 😄!
Unused array indices are filled with empty objects. |
I will add a pull request regarding a unified interface for reading tomorrow. |
@MaxOstrowski I addressed the two issues you raised, i.e. I unified the interface (this also includes a new branch in libpotassco) and changed the behaviour of
I'm not sure whether I got the interplay between the "user root" and the stats callbacks right. The current implementation simply calls the callbacks with a stats object that is rooted at "user_stats". That is, inside of callbacks, clasp statistics are hidden and new stats automatically occur under "user_stats".
Any preferences? |
@BenKaufmann Thanks a lot for all your efforts.
This is perfectly fine |
@MaxOstrowski I implemented the |
Looks nice, thank you very much. |
@MaxOstrowski Can you explain a little bit how such a |
Exactly. This function allows Roland to implement any clingo interface he wants. Thanks a lot. |
Testing for the existence of a key in a map is a standard operation on maps in one of our target API languages: python. So far the statistics object in the python API was simply a python dict(). This is no longer possible once we make it writable (at least if we want a nice API). In python there are the Mapping and Sequence protocols. As far as I can see only a way to query for a subkey is missing to implement them (well, with the current API it could be implemented in linear time). This way the API can present nice pythonic interfaces that won't surprise our users. Ben's tryGet function proposal should do the job. |
@rkaminsk I understand your point but just to clarify: The suggested |
I do not care much for performance with the statistics. This is not a critical code point. And since it will be hidden behind an interface it can be changed if it becomes a problem. |
@rkaminsk @MaxOstrowski I added |
You can merge with dev, erverything should work now. |
Thanks, was too slow to agree too. 😉 |
Dear Max,
I created an alternative implementation for your pull request #20 that is a little bit more in the spirit of the existing clasp code.
Please let me know if this interface suits your needs or if you have any comments. Given that this new interface is quite low-level and not type-safe, I deliberately used more explicit function names, like e.g.
mapAdd()
andarrayAdd()
.