Skip to content

Commit

Permalink
Only display progress bars when Julia is in an interactive session (#134
Browse files Browse the repository at this point in the history
)

In particular, this reduces the amount of output in tests.
  • Loading branch information
vtjeng authored Feb 17, 2023
1 parent 9383d59 commit c73137e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/MIPVerify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ function frac_correct(nn::NeuralNet, dataset::LabelledDataset, num_samples::Inte

num_correct = 0.0
num_samples = min(num_samples, MIPVerify.num_samples(dataset))
@showprogress 1 "Computing fraction correct..." for sample_index in 1:num_samples
p = Progress(num_samples, desc = "Computing fraction correct...", enabled = isinteractive())
for sample_index in 1:num_samples
input = get_image(dataset.images, sample_index)
actual_label = get_label(dataset.labels, sample_index)
predicted_label = (input |> nn |> get_max_index) - 1
if actual_label == predicted_label
num_correct += 1
end
next!(p)
end
return num_correct / num_samples
end
Expand Down
10 changes: 5 additions & 5 deletions src/net_components/core_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ function relu(
l = lazy_tight_lowerbound.(x, u, nta = nta, cutoff = 0)
return relu.(x, l, u)
else
p1 = Progress(length(x), desc = " Calculating upper bounds: ")
p1 = Progress(length(x), desc = " Calculating upper bounds: ", enabled = isinteractive())
u = map(x_i -> (next!(p1); tight_upperbound(x_i, nta = nta, cutoff = 0)), x)
p2 = Progress(length(x), desc = " Calculating lower bounds: ")
p2 = Progress(length(x), desc = " Calculating lower bounds: ", enabled = isinteractive())
l = map(v -> (next!(p2); lazy_tight_lowerbound(v..., nta = nta, cutoff = 0)), zip(x, u))

reluinfo = ReLUInfo(l, u)
Memento.info(MIPVerify.LOGGER, "$reluinfo")

p3 = Progress(length(x), desc = " Imposing relu constraint: ")
p3 = Progress(length(x), desc = " Imposing relu constraint: ", enabled = isinteractive())
return x_r = map(v -> (next!(p3); relu(v...)), zip(x, l, u))
end
end
Expand Down Expand Up @@ -374,9 +374,9 @@ function maximum(xs::AbstractArray{T})::JuMP.AffExpr where {T<:JuMPLinearType}

# TODO (vtjeng): [PERF] skip calculating lower_bound for index if upper_bound is lower than
# largest current lower_bound.
p1 = Progress(length(xs), desc = " Calculating upper bounds: ")
p1 = Progress(length(xs), desc = " Calculating upper bounds: ", enabled = isinteractive())
us = map(x_i -> (next!(p1); tight_upperbound(x_i)), xs)
p2 = Progress(length(xs), desc = " Calculating lower bounds: ")
p2 = Progress(length(xs), desc = " Calculating lower bounds: ", enabled = isinteractive())
ls = map(x_i -> (next!(p2); tight_lowerbound(x_i)), xs)

l = Base.maximum(ls)
Expand Down

2 comments on commit c73137e

@vtjeng
Copy link
Owner Author

@vtjeng vtjeng commented on c73137e Feb 17, 2023

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/77871

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" c73137e4e8ef2366633768de854b9198ed9576df
git push origin v0.5.0

Please sign in to comment.