Skip to content

Commit 3fcc2d8

Browse files
authored
Merge pull request #100 from BlockScience/methods
Methods
2 parents 7e81b8d + 0839108 commit 3fcc2d8

File tree

2 files changed

+141
-19
lines changed

2 files changed

+141
-19
lines changed

docs/Functions & Validation Rules/Processor Functions.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,40 @@ Here’s the revised version with consistent LaTeX formatting:
1111

1212
## Is Primitive
1313

14-
- $$\text{isPrimitive}: \text{Processor} \rightarrow \text{Bool}$$
14+
$$\text{isPrimitive}: \text{Processor} \rightarrow \text{Bool}$$
15+
16+
### Description
17+
18+
- The function will return true if there is no linked subsystem which it may be representing, i.e. it is NOT a composite block
19+
20+
### Python Implementation
1521

1622
## Get System
1723

18-
- $$\text{getSystem}: \text{Processor} \rightarrow \text{System}$$
24+
$$\text{getSystem}: \text{Processor} \rightarrow \text{System}$$
25+
26+
### Description
27+
28+
- Function for getting the linked system that this processor represents
29+
- If there is no linked function it will return NULL
30+
31+
### Python Implementation
32+
33+
## Get Shape
34+
35+
$$\text{getShape}: \text{Processor} \rightarrow \text{Block}$$
36+
37+
### Description
38+
39+
- A function which returns the block that a processor is meant to be implementing
40+
41+
### Python Implementation
1942

20-
## Get Shape
43+
- The following is implemented on the python client's Processor class:
2144

22-
- $$\text{getShape}: \text{Processor} \rightarrow \text{Block}$$
45+
```python
46+
class Processor:
47+
...
48+
def get_shape(self):
49+
return self.parent
50+
```

docs/Functions & Validation Rules/System Functions.md

Lines changed: 109 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,145 @@ parent: Functions & Validation Rules
99

1010
## Is Valid
1111

12-
- $$\text{isValid}: \text{system} \rightarrow \text{Bool}$$
12+
$$\text{isValid}: \text{system} \rightarrow \text{Bool}$$
13+
14+
### Description
15+
16+
- A function which checks the following is true of the system:
17+
- All inputs follow the schemas supplied
18+
- All references (through IDs) are present
19+
- There is one and only one wire into every port [NOTE: This means that systems which are part of composite processors are NOT valid outide of that context]
20+
- All blocks are connected to at least one other block
21+
22+
23+
### Python Implementation
1324

1425
## Is Directed
1526

16-
- $$\text{isDirected}: \text{system} \rightarrow \text{Bool}$$
27+
$$\text{isDirected}: \text{system} \rightarrow \text{Bool}$$
28+
29+
### Description
30+
31+
- A function which checks that there are no loops in the system
32+
33+
### Python Implementation
1734

1835
## Is Connected
1936

20-
- $$\text{isConnected}: \text{system} \rightarrow \text{Bool}$$
37+
$$\text{isConnected}: \text{system} \rightarrow \text{Bool}$$
38+
39+
### Description
40+
- A function which determines if there is a path between any two nodes
41+
- [NOTE] Do we want it to be that direction matters, i.e. there has to be looping behavior for this to be true (and everything needs to be reached by that loop even if downstream) or have it be that it just means that you couldn't partition the system into two subsystems without breaking a wiring?
42+
43+
### Python Implementation
2144

2245
## Is Dynamical
2346

24-
- $$\text{isDynamical}: \text{system} \rightarrow \text{Bool}$$
47+
$$\text{isDynamical}: \text{system} \rightarrow \text{Bool}$$
48+
49+
### Description
50+
51+
- [NOTE]: Is this just the opposite of is directed?
52+
53+
### Python Implementation
2554

2655
## Get Open Ports
2756

28-
- $$\text{getOpenPorts}: \text{system} \rightarrow \text{List[Terminal]} = \text{List}[\{\text{Processor, Index, Type}\}]$$
57+
$$\text{getOpenPorts}: \text{system} \rightarrow \text{List[Port]} = \text{List}[\{\text{Processor, Index, Space}\}]$$
58+
59+
### Description
60+
61+
- Returns a list of open ports which are defined as any ports in a system which have no wire going into them
62+
- The data type has a reference to the processor, the index of the port that is open and the space which that port is a type of
63+
64+
### Python Implementation
2965

3066
## Get Available Terminals
3167

32-
- $$\text{getAvailableTerminals}: \text{system} \rightarrow \text{List[Terminal]} = \text{List}[\{\text{Processor, Index, Type}\}]$$
68+
$$\text{getAvailableTerminals}: \text{system} \rightarrow \text{List[Terminal]} = \text{List}[\{\text{Processor, Index, Space}\}]$$
69+
70+
71+
### Description
72+
73+
- Returns a list of open or available terminals based on a default parameter of "open_only = True"
74+
- If open_only is true this will only return the list of terminals which have no wiring coming out of them
75+
- If false, it will return every single terminal in the system given terminals can be used more than once
76+
- The data type has a reference to the processor, the index of the terminal that is open and the space which that port is a type of
77+
78+
### Python Implementation
3379

3480
## Get Connected Components
3581

36-
- $$\text{getConnectedComponents}: \text{system} \rightarrow \text{List[System]}$$
82+
$$\text{getConnectedComponents}: \text{system} \rightarrow \text{List[Processor]}$$
83+
84+
### Description
85+
86+
- Returns a list of all processors which have at least one connection
87+
- [NOTE]: Is this supposed to be something else?
88+
89+
### Python Implementation
3790

3891
## Get Subsystems
3992

40-
- $$\text{getSubsystems}: \text{system} \rightarrow \text{List[Processor]}$$
41-
(subset of the processor list which isSubsystem)
93+
$$\text{getSubsystems}: \text{system} \rightarrow \text{List[Processor]}$$
94+
95+
96+
### Description
97+
98+
- This function will return the processors of the system which are also subsystems (meaning the isPrimitive function is false)
99+
- It will only return the top level, i.e. nested subsystems will not be returned, but the getHierachy function can achieve that
100+
101+
### Python Implementation
102+
42103

43104
## Get Hierarchy
44105

45-
- $$\text{getHierarchy}: \text{system} \rightarrow \text{NestedDict}$$
46-
(primitive processors are leaves in this tree)
106+
$$\text{getHierarchy}: \text{system} \rightarrow \text{NestedDict}$$
107+
108+
109+
### Description
110+
111+
- This function will recursively look through a system defining out branches where there are subsystems and leaves where there are processors to show the hierachy of nested subsystems
112+
113+
### Python Implementation
47114

48115
## Get Spaces
49116

50-
- $$\text{getSpaces}: \text{system} \rightarrow \text{List[Space]}$$
117+
$$\text{getSpaces}: \text{system} \rightarrow \text{List[Space]}$$
118+
119+
### Description
120+
121+
- A function which returns all the spaces used by processors in a system
122+
- If the argument nested=True, then it will also return all spaces which are used in subsystems of the system as well
123+
124+
### Python Implementation
51125

52126
## Make Processor
53127

54-
- $$\text{makeProcessor}: \text{system} \times \text{block} \times \text{List[wires]} \rightarrow \text{Processor}$$
128+
$$\text{makeProcessor}: \text{system} \times \text{block} \times \text{List[wires]} \rightarrow \text{Processor}$$
129+
130+
### Description
131+
132+
- A function which takes a system, a block it should represent, and the wires necessary to link up the composite processor and then turns it into a composite processor
133+
134+
### Python Implementation
55135

56136
## Lazy Make Processor
57137

58-
- $$\text{Imp}: \text{system} \rightarrow \text{Processor}$$
59-
(aka "lazy make processor")
138+
$$\text{Imp}: \text{system} \rightarrow \text{Processor}$$
139+
140+
### Description
141+
142+
- A function which lazily makes the composite processor following these steps:
143+
144+
1. get the ports using getOpenPorts(system)
145+
2. assign open ports to the new processors ports (inner wiring)
146+
3. get the terminals using getAvailableTerminals(system)
147+
4. assign the available terminals to the new processors terminals (inner wiring)
148+
5. create a block_id for a block which has these domains and codomains
149+
6. write the new block to the local toolbox
150+
7. create a new processor record with the above
151+
8. write the new processor record to the local workbench
152+
153+
### Python Implementation

0 commit comments

Comments
 (0)