Browse Source

fix log limiter, use eng notation

devel
Stefan Holst 1 year ago
parent
commit
de79393dfc
  1. 16
      src/kyupy/__init__.py
  2. 4
      src/kyupy/logic_sim.py
  3. 1
      src/kyupy/sdf.py
  4. 4
      src/kyupy/wave_sim.py

16
src/kyupy/__init__.py

@ -57,6 +57,18 @@ def hr_bytes(nbytes):
multiplier += 1 multiplier += 1
return f'{nbytes:.1f}{["", "ki", "Mi", "Gi", "Ti", "Pi"][multiplier]}B' return f'{nbytes:.1f}{["", "ki", "Mi", "Gi", "Ti", "Pi"][multiplier]}B'
def eng(number):
"""Formats a given number using engineering notation."""
exponent = 0
if abs(number) < 1:
while abs(number) >= 1000:
number *= 1000
exponent -= 3
else:
while abs(number) >= 1000:
number /= 1000
exponent += 3
return f'{number:.0f}' + (f'e{exponent}' if exponent != 0 else '')
def hr_time(seconds): def hr_time(seconds):
"""Formats a given time interval for human readability.""" """Formats a given time interval for human readability."""
@ -138,10 +150,10 @@ class Log:
self._limit = limit self._limit = limit
def stop_limit(self): def stop_limit(self):
self._limit = -1
if self.filtered > 0: if self.filtered > 0:
log.info(f'{self.filtered} more messages (filtered).') self.info(f'{self.filtered} more messages (filtered).')
self.filtered = 0 self.filtered = 0
self._limit = -1
def __getstate__(self): def __getstate__(self):
return {'elapsed': time.perf_counter() - self.start} return {'elapsed': time.perf_counter() - self.start}

4
src/kyupy/logic_sim.py

@ -10,7 +10,7 @@ import math
import numpy as np import numpy as np
from . import numba, logic, hr_bytes, sim from . import numba, logic, hr_bytes, sim, eng
from .circuit import Circuit from .circuit import Circuit
class LogicSim(sim.SimOps): class LogicSim(sim.SimOps):
@ -44,7 +44,7 @@ class LogicSim(sim.SimOps):
self.s[:,:,1,:] = 255 # unassigned self.s[:,:,1,:] = 255 # unassigned
def __repr__(self): def __repr__(self):
return f'{{name: "{self.circuit.name}", sims: {self.sims}, m: {self.m}, c_bytes: {self.c.nbytes}}}' return f'{{name: "{self.circuit.name}", sims: {self.sims}, m: {self.m}, c_bytes: {eng(self.c.nbytes)}}}'
def s_to_c(self): def s_to_c(self):
"""Copies the values from ``s[0]`` the inputs of the combinational portion. """Copies the values from ``s[0]`` the inputs of the combinational portion.

1
src/kyupy/sdf.py

@ -61,6 +61,7 @@ class DelayFile:
delays = np.zeros((len(circuit.lines), 2, 2, 3)) # dataset last during construction. delays = np.zeros((len(circuit.lines), 2, 2, 3)) # dataset last during construction.
with log.limit(50):
for name, iopaths in self.cells.items(): for name, iopaths in self.cells.items():
name = name.replace('\\', '') name = name.replace('\\', '')
if cell := circuit.cells.get(name, None): if cell := circuit.cells.get(name, None):

4
src/kyupy/wave_sim.py

@ -16,7 +16,7 @@ import math
import numpy as np import numpy as np
from . import numba, cuda, sim, cdiv from . import numba, cuda, sim, cdiv, eng
TMAX = np.float32(2 ** 127) TMAX = np.float32(2 ** 127)
@ -103,7 +103,7 @@ class WaveSim(sim.SimOps):
def __repr__(self): def __repr__(self):
dev = 'GPU' if hasattr(self.c, 'copy_to_host') else 'CPU' dev = 'GPU' if hasattr(self.c, 'copy_to_host') else 'CPU'
return f'{{name: "{self.circuit.name}", device: "{dev}", sims: {self.sims}, ops: {len(self.ops)}, ' + \ return f'{{name: "{self.circuit.name}", device: "{dev}", sims: {self.sims}, ops: {len(self.ops)}, ' + \
f'levels: {len(self.level_starts)}, nbytes: {self.nbytes}}}' f'levels: {len(self.level_starts)}, nbytes: {eng(self.nbytes)}}}'
def s_to_c(self): def s_to_c(self):
"""Transfers values of sequential elements and primary inputs to the combinational portion. """Transfers values of sequential elements and primary inputs to the combinational portion.

Loading…
Cancel
Save