-
Notifications
You must be signed in to change notification settings - Fork 11
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
Stop transformation steps when no longer possible and add verbose flag #50
Conversation
hi, Thanks for the report. Could you please add the reproducible examples as a test, so we can make sure to fix this bug? When there are no more edges to split on, the algorithm should finish and return the last circuit. Returning One possible solution could be: |
Oops. I only noticed now that one of my changes was on diff --git a/src/transformations.jl b/src/transformations.jl
index 9097b31..01a7d95 100644
--- a/src/transformations.jl
+++ b/src/transformations.jl
@@ -344,6 +344,8 @@ end
Split step
"""
function split_step(circuit::Node; loss=random_split, depth=0, sanity_check=true)
+ res = loss(circuit)
+ if isnothing(res) return nothing end
edge, var = loss(circuit)
split(circuit, edge, var; depth=depth, sanity_check=sanity_check)
end
@@ -354,12 +356,17 @@ Structure learning manager
function struct_learn(circuit::Node;
primitives=[split_step],
kwargs=Dict(split_step=>(loss=random_split, depth=0)),
- maxiter=typemax(Int), stop::Function=x->false)
+ maxiter=typemax(Int), stop::Function=x->false, verbose = true)
for iter in 1 : maxiter
primitive_step = rand(primitives)
kwarg = kwargs[primitive_step]
- c2, _ = primitive_step(circuit; kwarg...)
+ r = primitive_step(circuit; kwarg...)
+ if isnothing(r)
+ verbose && println("No more edges to transform. Skipping next iterations.")
+ return circuit
+ end
+ c2, _ = r
if stop(c2)
return c2
end Your solution looks cleaner though. I like the idea of using |
Going back to this PR I noticed we have a couple of problems with this approach (of using
For (1) a possible direction we could take (which is what I do in the post directly above this one) is require transformations to return a What do you think? |
@RenatoGeh Interesting, yeah this makes sense and looks good to me. One thing not sure at is if clone without split makes sense or not. |
This solution looks good to me as well. Clone without split is valid on the circuit as long as the |
1a3af3b
to
2ed1ac4
Compare
2ed1ac4
to
b2cc5a9
Compare
Great. I pushed the necessary changes, and now the PR is ready for review. I also pushed the |
Nice, thanks, I guess we will push the LogicCircuit ones first and then rerun the tests here and should be good to go. |
Hi,
When having a high enough
maxiter
onlearn_circuit
(orinit_maxiter
onlearn_strudel
), Juice spits out the following error.This is because there are no more possible edges to apply the split operation on. Instead of throwing out an error, Juice should probably stop the split iteration gracefully and skip to the next step of learning.
This PR addresses this issue and early stops when no longer possible to apply any transformation steps. It also adds a verbose flag to
learn_circuit
andlearn_strudel
to suppress the printing when not needed.Here's a minimal reproducible example for the above stacktrace:
Thanks