Skip to content

Commit

Permalink
Merge #237
Browse files Browse the repository at this point in the history
237: bugfix r=odunbar a=odunbar

<!--- THESE LINES ARE COMMENTED -->
## Purpose 
<!--- One sentence to describe the purpose of this PR, refer to any linked issues:
#14 -- this will link to issue 14
Closes #2 -- this will automatically close issue 2 on PR merge
-->
ProgressBars have patched the  "Key 9 not found" bug, so removing our local patch



<!---
Review checklist

I have:
- followed the codebase contribution guide: https://clima.github.io/ClimateMachine.jl/latest/Contributing/
- followed the style guide: https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/
- followed the documentation policy: https://github.com/CliMA/policies/wiki/Documentation-Policy
- checked that this PR does not duplicate an open PR.

In the Content, I have included 
- relevant unit tests, and integration tests, 
- appropriate docstrings on all functions, structs, and modules, and included relevant documentation.

-->

----
- [x] I have read and checked the items on the review checklist.


Co-authored-by: odunbar <[email protected]>
  • Loading branch information
bors[bot] and odunbar authored Oct 18, 2023
2 parents f95a1ed + 3019671 commit 4f6178b
Showing 1 changed file with 0 additions and 137 deletions.
137 changes: 0 additions & 137 deletions src/CalibrateEmulateSample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,143 +14,6 @@ import EnsembleKalmanProcesses: EnsembleKalmanProcesses, ParameterDistributions,

export EnsembleKalmanProcesses, ParameterDistributions, Observations, DataContainers

########################
########################
# bugfix for ProgressBars
# the only difference is the key "9" in the dict EIGHTS, following solve by:
# https://github.com/cloud-oak/ProgressBars.jl/issues/51
import ProgressBars
using Printf

EIGHTS = Dict(0 => ' ', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '', 8 => '', 9 => '')

function ProgressBars.update(iter::ProgressBars.ProgressBar, amount::Int64 = 1; force_print = false)
lock(iter.count_lock)
current = try
iter.current += amount
finally
unlock(iter.count_lock)
end

if current < iter.current_printed
return
end

if current == iter.total
if iter.leave
force_print = true
else
ProgressBars.clear_progress(iter)
return
end
end

if force_print
lock(iter.print_lock)
elseif time_ns() - iter.last_print >= iter.printing_delay
if !trylock(iter.print_lock)
return
end
else
return
end

try
if !iter.fixwidth
current_terminal_width = displaysize(iter.output_stream)[2]
terminal_width_changed = current_terminal_width != iter.width
if terminal_width_changed
iter.width = current_terminal_width
ProgressBars.make_space_after_progress_bar(iter.output_stream, iter.extra_lines)
end
end

seconds = (time_ns() - iter.start_time) * 1e-9
iteration = current - 1

elapsed = ProgressBars.format_time(seconds)
speed = iteration / seconds
if seconds == 0
# Dummy value of 1 it/s if no time has elapsed
speed = 1
end

if speed >= 1
iterations_per_second = ProgressBars.format_amount(speed, "$(iter.iter_unit)/s", iter.unit_scale)
else
# TODO: This might fail if speed == 0
iterations_per_second = ProgressBars.format_amount(1 / speed, "s/$(iter.iter_unit)", iter.unit_scale)
end

barwidth = iter.width - 2 # minus two for the separators

postfix_string = ProgressBars.postfix_repr(iter.postfix)

# Reset Cursor to beginning of the line
for line in 1:(iter.extra_lines)
ProgressBars.move_up_1_line(iter.output_stream)
end
ProgressBars.go_to_start_of_line(iter.output_stream)

if iter.description != ""
barwidth -= length(iter.description) + 1
print(iter.output_stream, iter.description * " ")
end

if (iter.total <= 0)
current_string = ProgressBars.format_amount(iter.current[], iter.iter_unit, iter.unit_scale)
status_string = "$(current_string) $elapsed [$iterations_per_second$postfix_string]"
barwidth -= length(status_string) + 1
if barwidth < 0
barwidth = 0
end

print(iter.output_stream, "")
print(iter.output_stream, join(IDLE[1 + ((i + current) % length(IDLE))] for i in 1:barwidth))
print(iter.output_stream, "")
print(iter.output_stream, status_string)
else
ETA = (iter.total - current) / speed

percentage_string = string(@sprintf("%.1f%%", current / iter.total * 100))

eta = ProgressBars.format_time(ETA)
current_string = ProgressBars.format_amount(current, iter.unit, iter.unit_scale)
total = ProgressBars.format_amount(iter.total, iter.unit, iter.unit_scale)
status_string = "$(current_string)/$(total) [$elapsed<$eta, $iterations_per_second$postfix_string]"

barwidth -= length(status_string) + length(percentage_string) + 1
if barwidth < 0
barwidth = 0
end

cellvalue = iter.total / barwidth
full_cells, remain = divrem(current, cellvalue)

print(iter.output_stream, percentage_string)
print(iter.output_stream, "")
print(iter.output_stream, repeat("", Int(full_cells)))
if (full_cells < barwidth)
part = Int(floor(9 * remain / cellvalue))
print(iter.output_stream, EIGHTS[part])
print(iter.output_stream, repeat(" ", Int(barwidth - full_cells - 1)))
end

print(iter.output_stream, "")
print(iter.output_stream, status_string)
end
multiline_postfix_string, iter.extra_lines = ProgressBars.newline_to_spaces(iter.multilinepostfix, iter.width)
print(iter.output_stream, multiline_postfix_string)
println(iter.output_stream)

iter.last_print = time_ns()
iter.current_printed = current
finally
unlock(iter.print_lock)
end
end
################
################

# Internal deps, light external deps
include("Utilities.jl")
Expand Down

0 comments on commit 4f6178b

Please sign in to comment.