-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_molecules_Dynamic.py
95 lines (82 loc) · 3.66 KB
/
count_molecules_Dynamic.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
import numpy as np
from causalset import CausalSet
from causalsetfunctions import generate_adjacency_matrix, count_subgraphs, check_connected_graph, compute_spacetimecuts_tube
import time
import sys
import os
import csv
import pandas as pd
path = ''
if len(sys.argv) > 1:
path = sys.argv[1] + '/'
def count_chains(N, d, Time, moleculetype, Bounds):
np.random.seed(int.from_bytes(os.urandom(4), byteorder='little'))
#lambda-molecules
if moleculetype == 'lambda' or moleculetype == 'v':
c = CausalSet(sprinkling_density=N, dimension=d, BHtype = 'Dynamic', sprinkling='Tube', T=Time, bounds = Bounds)
H, b = c.find_molecules()
V, b2 = c.find_Vmolecules()
#v-moelcules
# elif moleculetype == 'v':
# c = CausalSet(sprinkling_density=N, dimension=d, BHtype = 'Dynamic', sprinkling='Tube', T=Time, bounds = Bounds)
# V, b2 = c.find_Vmolecules()
try:
Adjmatrix = generate_adjacency_matrix(c.VElementsLabelsList, c.CausalMatrix)
SubGraphs = count_subgraphs(Adjmatrix)
Connected = check_connected_graph(Adjmatrix)
print(f'Subgraphs number: {SubGraphs}')
print(f'Connected Graph: {Connected}')
return H, b, V, SubGraphs, Connected, b2
except:
print('Subgraphs number: 0')
print('Connected Graph: False')
return H, b, V, 0, False, b2
def main():
tic = time.time()
##d_array = [4]
d_array = [3]
T = 1
moleculeType = 'lambda'
##N_max = 23000
N_max = 9000
c = 1.5
rho2 = 10
#rho2 = 1e20
#moleculeType = 'lambda'
for dimension in d_array:
#for N_max in [16000]:
##for c in [2.0]:
for c in [3.7]:
# Number of realisations
n = 44
## n= 100
# try:
# df = pd.read_csv(path + f'TestRun_T_{T}/test_run_Dynamic_rho{rho}_{dimension}d.csv', names=['type', 'value'], header=None)
# min_time = max(df[df['type'] == 'min_time']['value'].min()*1.1, -T)
# #min_time = -1.2
# #min_distance = 0
# #max_distance = 5.9
# min_distance = max(df[df['type'] == 'min_distance']['value'].min()*0.95, 0)
# max_distance = min(df[df['type'] == 'max_distance']['value'].max()*1.05, 2*T)
# except:
# raise ValueError ('No test run information!')
#adding some leeway
#boundsArray = [min_distance, max_distance, T + min_time, T]
#N_max = 10000
boundsArray, rho = compute_spacetimecuts_tube(d = dimension, rho2 = rho2, N_max = N_max, b = c)
for _i in range(n):
print(f'\n realisation:{_i+1}, rho:{rho}, dimension:{dimension}')
print('BoundsArray:', boundsArray)
print('N_max:', N_max)
if moleculeType == 'lambda' or moleculeType == 'v':
H , b, V, Subgraphs, Connected, b2 = count_chains(rho, dimension, T, moleculeType, boundsArray)
with open(path + f'H_Dynamic{dimension}d_lambda.csv', 'a') as f:
writer = csv.writer(f, lineterminator='\n')
writer.writerow([rho, H, b])
with open(path + f'H_Dynamic{dimension}d_v.csv', 'a') as f:
writer = csv.writer(f, lineterminator='\n')
writer.writerow([rho, V, Subgraphs, Connected, b2])
toc = time.time()
print(f'Time taken is {toc - tic}')
if __name__ == "__main__":
main()