From 92d3c0d61b4a52e6175b5cbf590fd033374178ce Mon Sep 17 00:00:00 2001 From: SeanMcOwen Date: Mon, 3 Mar 2025 21:20:09 -0500 Subject: [PATCH 1/5] Is primitive --- docs/Functions & Validation Rules/Processor Functions.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/Functions & Validation Rules/Processor Functions.md b/docs/Functions & Validation Rules/Processor Functions.md index 7d27e82..5aef086 100644 --- a/docs/Functions & Validation Rules/Processor Functions.md +++ b/docs/Functions & Validation Rules/Processor Functions.md @@ -17,6 +17,13 @@ $$\text{isPrimitive}: \text{Processor} \rightarrow \text{Bool}$$ ### Python Implementation +```python +class Processor: + ... + def is_primitive(self): + return self.subsystem is None +``` + ## Get System $$\text{getSystem}: \text{Processor} \rightarrow \text{System}$$ From fda2c3a481cf811b317af402b73d6b6fbd9a5f29 Mon Sep 17 00:00:00 2001 From: SeanMcOwen Date: Mon, 3 Mar 2025 21:26:48 -0500 Subject: [PATCH 2/5] Checkpoint --- .../Processor Functions.md | 13 +++++++++++-- .../System Functions.md | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/Functions & Validation Rules/Processor Functions.md b/docs/Functions & Validation Rules/Processor Functions.md index 5aef086..d8aa9f5 100644 --- a/docs/Functions & Validation Rules/Processor Functions.md +++ b/docs/Functions & Validation Rules/Processor Functions.md @@ -35,6 +35,17 @@ $$\text{getSystem}: \text{Processor} \rightarrow \text{System}$$ ### Python Implementation +```python +class Processor: + ... + def get_system(self): + if self.is_primitive(): + return None + else: + return self.subsystem +``` + + ## Get Shape $$\text{getShape}: \text{Processor} \rightarrow \text{Block}$$ @@ -45,8 +56,6 @@ $$\text{getShape}: \text{Processor} \rightarrow \text{Block}$$ ### Python Implementation -- The following is implemented on the python client's Processor class: - ```python class Processor: ... diff --git a/docs/Functions & Validation Rules/System Functions.md b/docs/Functions & Validation Rules/System Functions.md index 5d3d43d..701b9b6 100644 --- a/docs/Functions & Validation Rules/System Functions.md +++ b/docs/Functions & Validation Rules/System Functions.md @@ -22,6 +22,17 @@ $$\text{isValid}: \text{system} \rightarrow \text{Bool}$$ ### Python Implementation +- The python implementation assumes certain conditions, such as all inputs adhering to the schema, during loading. If these assumptions were incorrect, an error would already occur at that stage, making additional checks in this function redundant. + +```python +class System: + ... + def is_valid(self): + condition1 = len(self.get_open_ports()) == 0 + condition2 = self.is_connected() + return condition1 and condition2 +``` + ## Is Directed $$\text{isDirected}: \text{system} \rightarrow \text{Bool}$$ From 40fae042e83c0c48f359ad834254d32b5a6aaf48 Mon Sep 17 00:00:00 2001 From: SeanMcOwen Date: Mon, 3 Mar 2025 21:32:54 -0500 Subject: [PATCH 3/5] Two more --- .../System Functions.md | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/docs/Functions & Validation Rules/System Functions.md b/docs/Functions & Validation Rules/System Functions.md index 701b9b6..0800d30 100644 --- a/docs/Functions & Validation Rules/System Functions.md +++ b/docs/Functions & Validation Rules/System Functions.md @@ -43,15 +43,67 @@ $$\text{isDirected}: \text{system} \rightarrow \text{Bool}$$ ### Python Implementation +```python +class System: + ... + def is_directed(self): + processors = set([x.id for x in self.processors]) + while len(processors) > 0: + q = [processors.pop()] + visited = [] + while len(q) > 0: + cur = q.pop() + visited.append(cur) + cur = self.processors_map[cur] + wires = [x for x in self.wires if x.source["Processor"].id == cur.id] + for x in wires: + x = x.target["Processor"].id + if x in processors: + q.append(x) + processors.remove(x) + if x in visited: + return False + return True +``` + ## Is Connected $$\text{isConnected}: \text{system} \rightarrow \text{Bool}$$ ### Description -- A function which determines if there is a path between any two nodes, in the weakly connected sense + +- A function which determines if there is a path between any two nodes, in the weakly connected sense, i.e. either A->B or B->A would suffice for A and be being connected. ### Python Implementation +```python +class System: + ... + def is_connected(self): + processors = set([x.id for x in self.processors]) + + q = [processors.pop()] + while len(q) > 0: + cur = q.pop() + cur = self.processors_map[cur] + wires = [ + x + for x in self.wires + if x.source["Processor"].id == cur.id + or x.target["Processor"].id == cur.id + ] + for y in wires: + x = y.target["Processor"].id + if x in processors: + q.append(x) + processors.remove(x) + x = y.source["Processor"].id + if x in processors: + q.append(x) + processors.remove(x) + return len(processors) == 0 +``` + ## Is Dynamical $$\text{isDynamical}: \text{system} \rightarrow \text{Bool}$$ From ba2db6abe2503648b8a41f8749db8fb7a51afa3b Mon Sep 17 00:00:00 2001 From: SeanMcOwen Date: Mon, 3 Mar 2025 21:38:05 -0500 Subject: [PATCH 4/5] 2 more --- .../System Functions.md | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/Functions & Validation Rules/System Functions.md b/docs/Functions & Validation Rules/System Functions.md index 0800d30..e930ffb 100644 --- a/docs/Functions & Validation Rules/System Functions.md +++ b/docs/Functions & Validation Rules/System Functions.md @@ -110,10 +110,17 @@ $$\text{isDynamical}: \text{system} \rightarrow \text{Bool}$$ ### Description -- [NOTE]: Is this just the opposite of is directed? +- The opposite of `IsDirected` in the sense that there is looping behavior in the system ### Python Implementation +```python +class System: + ... + def is_dynamical(self): + return not self.is_directed() +``` + ## Get Open Ports $$\text{getOpenPorts}: \text{system} \rightarrow \text{List[Port]} = \text{List}[\{\text{Processor, Index, Space}\}]$$ @@ -125,6 +132,18 @@ $$\text{getOpenPorts}: \text{system} \rightarrow \text{List[Port]} = \text{List} ### Python Implementation +```python +class System: + ... + def get_open_ports(self): + out = [] + for processor in self.processor_ports_map: + for i, port_list in enumerate(self.processor_ports_map[processor]): + if len(port_list) == 0: + out.append([processor, i, processor.ports[i]]) + return out +``` + ## Get Available Terminals $$\text{getAvailableTerminals}: \text{system} \rightarrow \text{List[Terminal]} = \text{List}[\{\text{Processor, Index, Space}\}]$$ From 6c09bca649cb55b029ebee607a8e94f3c56286d9 Mon Sep 17 00:00:00 2001 From: SeanMcOwen Date: Mon, 3 Mar 2025 21:42:56 -0500 Subject: [PATCH 5/5] finish up --- .../System Functions.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/Functions & Validation Rules/System Functions.md b/docs/Functions & Validation Rules/System Functions.md index e930ffb..ad85835 100644 --- a/docs/Functions & Validation Rules/System Functions.md +++ b/docs/Functions & Validation Rules/System Functions.md @@ -158,6 +158,21 @@ $$\text{getAvailableTerminals}: \text{system} \rightarrow \text{List[Terminal]} ### Python Implementation +```python +class System: + ... + def get_available_terminals(self, open_only=False): + out = [] + for processor in self.processor_terminals_map: + for i, terminal_list in enumerate(self.processor_terminals_map[processor]): + if open_only: + if len(terminal_list) == 0: + out.append([processor, i, processor.terminals[i]]) + else: + out.append([processor, i, processor.terminals[i]]) + return out +``` + ## Get Connected Components $$\text{getConnectedComponents}: \text{system} \rightarrow \text{List[Processor]}$$