-
Notifications
You must be signed in to change notification settings - Fork 7
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
General API ergonomics improvements #81
Comments
This would be awesome, I was also wondering if it is really necessary to pass by value. It wasn't a performance issue for me, but just led to a somewhat ugly code with lots of cloning. Also e.g. A somewhat related issue is that I'd often want to quickly print out the number of variables and clauses, and |
Very insightful feedback, thanks. Since so far I have mostly been the only user of this library, I mainly wrote the API in a way that worked for me, trying to somewhat think about potential other use cases, but it's always better to get proper feedback.
How do these ideas sound to you for your usecases? Also, it would be great if you could drop any further inconveniences you run into in your applications here. |
Maybe I can expand a bit on my typical use cases. For me it's often convenient to define something like
Then high-level code might look a bit like this:
And here it would be natural that I understand the challenge that
and the final step of For this to work with external solvers one would indeed need to have |
I see. Do you ever incrementally change the |
One small API inconvenience: It's a common use case for me that I have e.g. |
Just for your information, I'll give you an overview of what I'm doing :) I'm actually generating my SAT instance using an external program ( https://github.com/conjure-cp/conjure ), which takes a high-level language and turns it into SAT. I then I have a little structure like:
Then I create a thread local copy of this using the I then use rayon to solve problems in parallel which require lots of solving SAT instances.
Then pop it into the mutex:
Good news, this works really well! My laptop has 32 cores, which I can saturate fairly easily just using rayon's par_iter. |
I assume neither of you are relying directly on the public API in |
No, but also in general as it's early days for the library, I'm happy to do any fixing -- one reason I've moved to using rust rather than pysat in Python (which is what I used to use, and is a well-written library) is that I just got annoyed that misuses of APIs in Python aren't caught until runtime, while in Rust when you change an API, you just whiz around in your editor and change all the places you call it, doesn't take long and I know I've fixed it :) |
I merged a fairly large PR implementing these improvements just now. Please see the newly added migration guide for what changes will be necessary to be made. I am hoping to actually publish a proper release once I get something for #79 working as well (as something I would want to do related to that might lead to some more breaking changes). |
I have a situation where I need to keep recreating the solver. There is a significant amount of time spent cloning the cnf, because
add_cnf
, which callsadd_clause
, both take by value.Looking at the implementations of
add_clause
, none of them seem to actually need the clause by value -- but changingadd_clause
to accept&Clause
"breaks the world", as it would need changing every call toadd_clause
.My best suggestion (assuming you are happy to improve it), would be to add
add_cnf_ref
andadd_clause_ref
toSolver
. These will allow people (like me) to add cnf and clauses by reference, and will only require implementingadd_clause_ref
to each solver (which, from trying out with kissat, actually can be done by just renamingadd_clause
toadd_clause_ref
, and then makingadd_clause
calladd_clause_ref
, because theadd_clause
implementations don't actually need the clause by value).The text was updated successfully, but these errors were encountered: