Browse Source

Fixed tracers and LaTeX gen

rparedis 3 years ago
parent
commit
a389fbd760

+ 1 - 0
examples/scripts/Fibonacci/Fibonacci_experiment.py

@@ -11,6 +11,7 @@ cbd = FibonacciGen("FibonacciGen")
 
 # Run the Simulation
 sim = Simulator(cbd)
+sim.setVerbose(None)
 sim.run(10)
 
 data = cbd.getSignalHistory('OUT1')

+ 1 - 1
src/CBD/Core.py

@@ -1,5 +1,5 @@
 import re
-import CBD.naivelog
+import CBD.naivelog as naivelog
 import logging
 from copy import deepcopy
 from .util import enum, hash64

+ 13 - 16
src/CBD/converters/latexify/CBD2Latex.py

@@ -105,7 +105,7 @@ class CBD2Latex:
 		for f in fncs:
 			f.args = [VarFnc(x) for x in inputs]
 		eqs = []
-		outputs = [self._rename(block.getPath(self.config["path_sep"]) + self.config['path_sep'] + x) for x in block.getSignals().keys()]
+		outputs = [self._rename(block.getPath(self.config["path_sep"]) + self.config['path_sep'] + x) for x in block.getOutputPortNames()]
 		for i, fnc in enumerate(fncs):
 			eqs.append(Eq(outputs[i], fnc))
 		return eqs
@@ -120,21 +120,9 @@ class CBD2Latex:
 		"""
 		# Add all blocks
 		for block in self.model.getBlocks():
-			if block.getBlockType() not in ["OutputPortBlock", "InputPortBlock", "WireBlock"]:
-				eq = self.get_block_equation(block)
-				for e in eq:
-					self.equations.append(e)
-			# elif block.getBlockType() in "WireBlock":
-			# 	path = block.getPath(self.config['path_sep'])
-			# 	lhs = self._rename(path + self.config['path_sep'] + "OUT1")
-			# 	rhs = VarFnc(self._rename(path + self.config['path_sep'] + "IN1"))
-			# 	self.equations.append(Eq(lhs, rhs))
-			# 	self.equations.append(Eq(self._rename(path), VarFnc(lhs)))
-			# elif block.getBlockType() in "InputPortBlock":
-			# 	path = block.getPath(self.config['path_sep'])
-			# 	lhs = self._rename(path)
-			# 	rhs = VarFnc(self._rename(path))
-			# 	self.equations.append(Eq(lhs, rhs))
+			eq = self.get_block_equation(block)
+			for e in eq:
+				self.equations.append(e)
 
 		# Add all connections
 		for block in self.model.getBlocks():
@@ -146,6 +134,15 @@ class CBD2Latex:
 				rhs = VarFnc(v_path)
 				self.equations.append(Eq(lhs, rhs))
 
+		# Add all outputs
+		for port in self.model.getOutputPorts():
+			prev = port.getIncoming().source
+			p_path = self._rename(
+				prev.block.getPath(self.config['path_sep']) + self.config['path_sep'] + prev.name)
+			n_path = self._rename(
+				port.block.getPath(self.config['path_sep']) + self.config['path_sep'] + port.name)
+			self.equations.append(Eq(n_path, VarFnc(p_path)))
+
 	def render(self, rl=None):
 		"""
 		Creates the LaTeX string for the model, based on the current level of simplifications.

+ 3 - 0
src/CBD/tracers/__init__.py

@@ -85,6 +85,9 @@ class Tracers:
 		"""
 		Stops all tracers.
 		"""
+		while len(self.bus) > 0:
+			evt, args = self.bus.pop(0)
+			evt(*args)
 		for tracer in self.tracers.values():
 			tracer.stopTracer()
 

+ 3 - 3
src/CBD/tracers/baseTracer.py

@@ -1,9 +1,9 @@
 import sys
 import time
+from CBD.realtime import accurate_time
 from .color import COLOR
 
-# TODO: do this on another thread to prevent simulation slowdown
-#       this can possibly be done using the pubsub architecture
+
 class BaseTracer:
 	"""
 	Base class for all tracers.
@@ -135,4 +135,4 @@ class BaseTracer:
 		See Also:
 			`Documentation on time formatting. <https://docs.python.org/3/library/time.html#time.strftime>`_
 		"""
-		return time.strftime(format, time.time())
+		return time.strftime(format, accurate_time.time())

+ 6 - 5
src/CBD/tracers/tracerVerbose.py

@@ -16,19 +16,20 @@ class VerboseTracer(BaseTracer):
 		txt4 = COLOR.colorize("{:>10.3}".format(time), COLOR.RED)
 		rem = "_" * (self.width - 11 - 5 - 8 - 10)
 		if curIt > 0:
-			self.trace("\n\n")
+			self.trace("\n")
 		self.traceln("__", txt1, txt2, txt3, txt4, rem)
+		self.trace("\n")
 
 	def traceCompute(self, curIt, block):
-		text = "\n " + COLOR.colorize(block.getPath(), COLOR.ITALIC, COLOR.CYAN) + ":"
+		text = " " + COLOR.colorize(block.getPath(), COLOR.ITALIC, COLOR.CYAN) + ":"
 		inps = block.getInputPorts()
-		deps = [x.getBlockName() for x in block.getDependencies(curIt)]
+		deps = [x.block.getBlockName() for x in block.getDependencies(curIt)]
 		if len(inps) > 0:
 			text += "\n\tINPUT VALUES:"
 			for inp in inps:
 				out = inp.getIncoming().source
 				other = out.block
-				if other in deps:
+				if other.getBlockName() in deps:
 					text += "\n\t\t{:>10} -> {:<10} : {}"\
 						.format(other.getPath() + ":" + out.name, inp.name,
 					            COLOR.colorize(str(inp.getHistory()[curIt]), COLOR.YELLOW))
@@ -39,4 +40,4 @@ class VerboseTracer(BaseTracer):
 			text += "\n\tOUTPUT VALUES:"
 			for out in outs:
 				text += "\n\t\t{:<24} : {}".format(out.name, COLOR.colorize(str(out.getHistory()[curIt]), COLOR.YELLOW))
-		self.traceln(text)
+		self.traceln(text + "\n")