Skip to content
Snippets Groups Projects
signal_flow_graph.py 1.39 KiB
Newer Older
  • Learn to ignore specific revisions
  • """
    B-ASIC Signal Flow Graph Module.
    TODO: More info.
    """
    
    
    from b_asic.operation import Operation
    
    from b_asic.basic_operation import BasicOperation
    
    angloth's avatar
    angloth committed
    from b_asic.signal import Signal, SignalSource, SignalDestination
    
    from b_asic.simulation import SimulationState, OperationState
    
    from typing import List, Dict, Union
    from graph_id import GraphIDGenerator, GraphID
    
    
    class SFG(BasicOperation):
    	"""
    	Signal flow graph.
    	TODO: More info.
    	"""
    
    
    	_graph_objects: Dict(GraphID, Union(Operation, Signal))
    	_graph_id_generator: GraphIDGenerator
    
    angloth's avatar
    angloth committed
    	def __init__(self, input_destinations: List[SignalDestination], output_sources: List[SignalSource]):
    
    		"""
    		Construct a SFG.
    		"""
    
    		# TODO: Allocate input/output ports with appropriate IDs.
    
    		self._graph_objects = dict # Map Operation ID to Operation objects
    		self._graph_id_generator = GraphIDGenerator() 
    
    		# TODO: Traverse the graph between the inputs/outputs and add to self._operations.
    		# TODO: Connect ports with signals with appropriate IDs.
    
    	def evaluate(self, inputs: list) -> list:
    		return [] # TODO: Implement
    
    
    	def add_operation(self, operation: Operation) -> GraphID:
    		"""
    		Adds the entered operation to the SFG's dictionary of graph objects and
    		generates and returns a GraphID for it.
    		"""
    		graph_id = self._graph_id_generator.get_next_id("op")
    		self._graph_objects[graph_id] = operation
    		return graph_id
    
    	def _generate_id(self)