phanerozoic commited on
Commit
76a0242
·
verified ·
1 Parent(s): 75e4195

Upload routing/routing_schema.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. routing/routing_schema.md +103 -0
routing/routing_schema.md ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Routing Schema for 8-bit Threshold Computer
2
+
3
+ ## Overview
4
+
5
+ The routing file (`routing.json`) defines how gates are interconnected. Each entry maps a gate path to its input sources.
6
+
7
+ ## Schema Format
8
+
9
+ ```json
10
+ {
11
+ "version": 1,
12
+ "external_inputs": {
13
+ "circuit_path": ["input_name", ...]
14
+ },
15
+ "routing": {
16
+ "gate_path": ["source1", "source2", ...]
17
+ }
18
+ }
19
+ ```
20
+
21
+ ## Input Source Types
22
+
23
+ 1. **External input**: `"$input_name"` - Named input to the circuit
24
+ - Example: `"$a"`, `"$b"`, `"$cin"`
25
+
26
+ 2. **Gate output**: `"path.to.gate"` - Output of another gate
27
+ - Example: `"ha1.sum"`, `"layer1.or"`
28
+
29
+ 3. **Bit extraction**: `"$input[i]"` - Single bit from multi-bit input
30
+ - Example: `"$a[0]"` (LSB), `"$a[7]"` (MSB for 8-bit)
31
+
32
+ 4. **Constant**: `"#0"` or `"#1"` - Fixed value
33
+ - Example: `"#1"` for carry-in in two's complement
34
+
35
+ 5. **Relative reference**: `"../sibling.gate"` - Reference to sibling in hierarchy
36
+ - Example: `"../fa0.cout"` from fa1
37
+
38
+ ## Circuit Types
39
+
40
+ ### Single-Layer Gates
41
+ Gates with just `.weight` and `.bias`:
42
+ ```json
43
+ "boolean.and": ["$a", "$b"]
44
+ ```
45
+
46
+ ### Two-Layer Gates (XOR, XNOR)
47
+ Gates decomposed into layer1 + layer2:
48
+ ```json
49
+ "boolean.xor.layer1.or": ["$a", "$b"],
50
+ "boolean.xor.layer1.nand": ["$a", "$b"],
51
+ "boolean.xor.layer2": ["layer1.or", "layer1.nand"]
52
+ ```
53
+
54
+ ### Hierarchical Circuits
55
+ Complex circuits with sub-components:
56
+ ```json
57
+ "arithmetic.fulladder": {
58
+ "external_inputs": ["$a", "$b", "$cin"],
59
+ "gates": {
60
+ "ha1.sum.layer1.or": ["$a", "$b"],
61
+ "ha1.sum.layer1.nand": ["$a", "$b"],
62
+ "ha1.sum.layer2": ["ha1.sum.layer1.or", "ha1.sum.layer1.nand"],
63
+ "ha1.carry": ["$a", "$b"],
64
+ "ha2.sum.layer1.or": ["ha1.sum", "$cin"],
65
+ "ha2.sum.layer1.nand": ["ha1.sum", "$cin"],
66
+ "ha2.sum.layer2": ["ha2.sum.layer1.or", "ha2.sum.layer1.nand"],
67
+ "ha2.carry": ["ha1.sum", "$cin"],
68
+ "carry_or": ["ha1.carry", "ha2.carry"]
69
+ },
70
+ "outputs": {
71
+ "sum": "ha2.sum",
72
+ "cout": "carry_or"
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### Bit-Indexed Circuits
78
+ Circuits operating on multi-bit values:
79
+ ```json
80
+ "arithmetic.ripplecarry8bit": {
81
+ "external_inputs": ["$a[0:7]", "$b[0:7]"],
82
+ "gates": {
83
+ "fa0": {"inputs": ["$a[0]", "$b[0]", "#0"], "type": "fulladder"},
84
+ "fa1": {"inputs": ["$a[1]", "$b[1]", "fa0.cout"], "type": "fulladder"},
85
+ ...
86
+ }
87
+ }
88
+ ```
89
+
90
+ ## Naming Conventions
91
+
92
+ - External inputs: `$name` or `$name[bit]`
93
+ - Constants: `#0`, `#1`
94
+ - Internal gates: relative path from circuit root
95
+ - Outputs: named in `outputs` section
96
+
97
+ ## Validation Rules
98
+
99
+ 1. Every gate in routing must exist in tensors file
100
+ 2. Every tensor must have routing entry
101
+ 3. Input count must match weight dimensions
102
+ 4. No circular dependencies (DAG only)
103
+ 5. All referenced sources must exist