-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
96 lines (85 loc) · 2.96 KB
/
main.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
import os
from optimizeInput import *
from itertools import combinations
from celloapi2 import CelloQuery, CelloResult
# Set our directory variables.
in_dir = os.path.join(os.getcwd(), 'input')
out_dir = os.path.join(os.getcwd(), 'output')
#Number of inputs into circuit
signal_input = 2
# Set our input files.
chassis_name = 'Eco1C1G1T1'
in_ucf = f'{chassis_name}.UCF.json'
v_file = 'and.v'
options = 'options.csv'
input_sensor_file = f'{chassis_name}.input.json'
output_device_file = f'{chassis_name}.output.json'
#Determine best score for unmodified input for calculation of delta
eval=True
if eval:
del_best_score = 0
qdel= CelloQuery(
input_directory=in_dir,
output_directory=out_dir,
verilog_file=v_file,
compiler_options=options,
input_ucf=in_ucf,
input_sensors=input_sensor_file,
output_device=output_device_file,
)
signals = qdel.get_input_signals()
signal_pairing = list(combinations(signals, signal_input))
for signal_set in signal_pairing:
signal_set = list(signal_set)
qdel.set_input_signals(signal_set)
qdel.get_results()
try:
delres = CelloResult(results_dir=out_dir)
if delres.circuit_score > del_best_score:
del_best_score = delres.circuit_score
except:
pass
qdel.reset_input_signals()
qdel.get_results()
delres = CelloResult(results_dir=out_dir)
#Perform calculations and modify input file
input_file_path = os.path.join(in_dir, input_sensor_file)
ucf_file_path = os.path.join(in_dir, in_ucf)
input_class_list = get_input_models_in_class(os.path.join(in_dir, input_sensor_file))
gate_class_list = get_file_gate_models_in_class(ucf_file_path)
modified_input_class_list = compute_optimal_parameters(input_class_list,gate_class_list)
NEWinput_sensor_file = f'{chassis_name}.NEWinput.json'
NEWinput_sensor_file_path = os.path.join(in_dir, NEWinput_sensor_file)
save_input_class_in_file(modified_input_class_list,input_file_path,NEWinput_sensor_file_path)
#Calculate best score for modified input
best_score=0
q = CelloQuery(
input_directory=in_dir,
output_directory=out_dir,
verilog_file=v_file,
compiler_options=options,
input_ucf=in_ucf,
input_sensors=NEWinput_sensor_file,
output_device=output_device_file,
)
signals = q.get_input_signals()
signal_pairing = list(combinations(signals, signal_input))
for signal_set in signal_pairing:
signal_set = list(signal_set)
q.set_input_signals(signal_set)
q.get_results()
try:
res = CelloResult(results_dir=out_dir)
if res.circuit_score > best_score:
best_score = res.circuit_score
best_chassis = chassis
best_input_signals = signal_set
except:
pass
q.reset_input_signals()
#Output best score for modified input
print("New best score: ",best_score)
#Caclulate and output delta
if eval:
delta = best_score - del_best_score
print("Delta: ",delta)