-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-foundations.py
145 lines (107 loc) · 5.03 KB
/
01-foundations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
print('''
Welcome to the go2x3 tutorial series!''')
# First we import the 2x3 module. Sometime open and explore lib/py2x3.py
from py2x3 import *
# To express particle graphs, we make a new Graph from a vertex and edge initialization string.
# Vertices are labeled as positive integers and single (positive) edges appear as a dash.
#
# Recall each vertex in 2x3 has a combined total of 3 loops and/or edges.
# Vertices that have less than three edges are assumed to have positive self-connected edges (loops).
# A proton has two loops on each end ond one in the middle
proton = NewGraph("1-2-3")
# An electron is a single vertex with three loops
electron = NewGraph("1")
# We can output a Graph object to the console by using the str() conversion operator.
# This implicitly happens for ops like print() that auto-convert into a string.
print("Our friend the proton: ", proton)
# Vertices that are double or triple connected use multiple dashes.
photon = NewGraph("1---2")
# When a caret ('^') appears after a vertex, it means a negative loop.
positron = NewGraph("1^^^")
# A Z0 boson has two vertices, each with a positive and negative loop.
# Also, for convenience, using "Graph()" is equivalent to "NewGraph()""
z_boson = Graph("1^-2^")
# For graphs that can't be expressed in a single edge "run", use commas to serparate multiple runs
higgs = Graph("1-2-3-4-1-5-6-7-8-5, 2-6, 3-7, 4-8")
print('''
If we want to get the traces of a 2x3 graph, we can!''')
T1 = proton.Traces()
print("proton.Traces(): ", T1)
# Or, we can ask for more Trace elements to be computed.
T2 = proton.Traces(12)
print("proton.Traces(12): ", T2)
print('''
Or we can access each Traces element easily thanks to python:''')
for i in range(len(T2)):
print(" T[%d]: %d" % (i, T2[i]))
print()
print('''Now let's meet GraphStream, allowing us to do more useful things with particle Graph objects.
GraphStream is a chain (pipeline) of Graph operators where Graphs are "pushed" into a stream's inlet and "pulled" from its outlet.
Adding .Print(label) prints each graph that passes though the stream, printing the given label along with a counter.
Adding .Go() terminates a stream and pulls all the graphs through it:''')
proton.Stream().Print("Hello proton!").Go()
# Some commands "fan out", meaning for each given graph, they output multiple graphs
# Two of these are AllVtxSigns() and AllEdgeSigns()...
# AllVtxSigns() emits all possible +/- loops permutations for each input particle.
print('''
For each particle that AllVtxSigns() takes in, it sends out all possible permutations of loop signs:''')
electron.AllVtxSigns().Print("electron.AllVtxSigns").Go()
print('''
The more loops that are present, the more permutations that are possible:''')
proton.AllVtxSigns().Print("proton.AllVtxSigns").Go()
print('''
For particles containing only 'gamma' vertices, only one permutation is possible:''')
photon.AllVtxSigns().Print("gamma.AllVtxSigns").Go()
print('''
All edge permutations for a two-vertex photon:''')
photon.AllEdgeSigns().Print("gamma.AllEdgeSigns").Go()
# AllEdgeSigns() emits all possible edge sign permutations for each input particle.
print('''
For each particle that AllEdgeSigns() takes in, it sends out all possible permutations of positive and negative edges:''')
proton.AllEdgeSigns().Print("proton.AllEdgeSigns").Go()
# Since we're using python, we can use data structures like lists and dicts to make life easier:
neutrons = {}
print('''
Most graphs can be expressed identically in multiple ways.
Consider various equivalent ways to label a neutron:''')
neutrons["a"] = Graph("1-2-3-1-4")
neutrons["b"] = Graph("1-2-3-1, 2-4")
neutrons["c"] = Graph("3-4,2-3-1-2")
print("neutron[a]: ", neutrons["a"])
print("neutron[b]: ", neutrons["b"])
print("neutron[c]: ", neutrons["c"])
print('''
EnumPureParticles() runs an algorithm that generates all possible valid particles having only loops and positive edges.
This algorithm is mechanical and will therefore repeat equivalent particles having different labels.
Let's generate from v=1 to v=3:''')
EnumPureParticles(1,3).Print().Go()
print('''
The DropDupes() operator only emits unique graphs while dropping duplicates.''')
EnumPureParticles(1,3).DropDupes().Print().Go()
# Now we introduce a powerful GraphStream() operator called Select() that is a filter and selects Graphs that meet criteria that we provide.
# The Select() operator uses a struct called a GraphSelector that specifies which graphs you want to select.
sel = NewSelector()
print('''
We can select by matching Traces:''')
sel.traces = photon
EnumPureParticles(1,3).Select(sel).Print().Go()
print('''
We can also select by min and max vertex count:''')
sel.traces = None
sel.min.verts = 1
sel.max.verts = 2
EnumPureParticles(1,3).Select(sel).Print().Go()
print('''
We can select by + or - loops:''')
sel.Init()
sel.min.pos_loops = 2
sel.max.pos_loops = 3
EnumPureParticles(1,3).Select(sel).Print().Go()
print('''
We can select by + or - loops:''')
sel.Init()
sel.min.pos_loops = 2
sel.max.pos_loops = 3
sel.min.neg_loops = 1
sel.max.neg_loops = 100
proton.AllVtxSigns().Select(sel).Print().Go()