Skip to content
Merged

Docs #108

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions docs/Functions & Validation Rules/Processor Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}$$
Expand All @@ -28,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}$$
Expand All @@ -38,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:
...
Expand Down
101 changes: 99 additions & 2 deletions docs/Functions & Validation Rules/System Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}$$
Expand All @@ -32,25 +43,84 @@ $$\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}$$

### 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}\}]$$
Expand All @@ -62,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}\}]$$
Expand All @@ -76,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]}$$
Expand Down