Added live reduction counter

master
Mark 2022-10-28 18:58:25 -07:00
parent e41de764e8
commit 6e46f485c1
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 14 additions and 0 deletions

View File

@ -1,7 +1,9 @@
from prompt_toolkit import PromptSession from prompt_toolkit import PromptSession
from prompt_toolkit.formatted_text import FormattedText from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit import print_formatted_text as printf from prompt_toolkit import print_formatted_text as printf
from prompt_toolkit.shortcuts import clear as clear_screen
import enum import enum
import math
import lamb import lamb
@ -77,6 +79,11 @@ class Runner:
# a bound variable. # a bound variable.
self.bound_variable_counter = 0 self.bound_variable_counter = 0
# Update iteration after this many iterations
# Make sure every place value has a non-zero digit
# so that all digits appear to be changing.
self.iter_update = 231
def prompt(self): def prompt(self):
return self.prompt_session.prompt(message = self.prompt_message) return self.prompt_session.prompt(message = self.prompt_message)
@ -101,6 +108,10 @@ class Runner:
while (self.reduction_limit is None) or (i < self.reduction_limit): while (self.reduction_limit is None) or (i < self.reduction_limit):
# Show reduction count
if (i >= self.iter_update) and (i % self.iter_update == 0):
print(f" Reducing... {i}", end = "\r")
try: try:
red_type, new_node = lamb.node.reduce( red_type, new_node = lamb.node.reduce(
node, node,
@ -123,6 +134,9 @@ class Runner:
if red_type == lamb.node.ReductionType.FUNCTION_APPLY: if red_type == lamb.node.ReductionType.FUNCTION_APPLY:
macro_expansions += 1 macro_expansions += 1
if i >= self.iter_update:
# Clear reduction counter
print(" " * round(14 + math.log10(i)), end = "\r")
if ( if (
stop_reason == StopReason.BETA_NORMAL or stop_reason == StopReason.BETA_NORMAL or