Skip to content

Commit 54ac55f

Browse files
committed
more steps towards an generator based data loading API
1 parent b81bd99 commit 54ac55f

27 files changed

+369
-1477
lines changed

README.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ with temp_dir() as td: # create temporary directory `td`
352352
make_random_sampling], # provide RS run creator
353353
n_runs=5) # we will execute 5 runs per setup
354354

355-
from_logs( # parse all log files and print end results
356-
td, lambda er: print(f"{er.algorithm} on {er.instance}: {er.best_f}"))
355+
for er in from_logs(td): # parse all log files and print end results
356+
print(f"{er.algorithm} on {er.instance}: {er.best_f}")
357357
# The temp directory is deleted as soon as we leave the `with` block.
358358
```
359359

@@ -682,8 +682,8 @@ with temp_dir() as td: # create temporary directory `td`
682682
instances=problems, # define the problem instances
683683
setups=[make_execution], # creator for our algorithm
684684
n_runs=5) # we will execute 5 runs per setup
685-
from_logs( # parse all log files and print end results
686-
td, lambda er: print(f"{er.algorithm} on {er.instance}: {er.best_f}"))
685+
for er in from_logs(td): # parse all log files and print end results
686+
print(f"{er.algorithm} on {er.instance}: {er.best_f}")
687687
# The temp directory is deleted as soon as we leave the `with` block.
688688
```
689689

@@ -1564,12 +1564,9 @@ with temp_dir() as td:
15641564
max_fes=10000, # we grant 10000 FEs per run
15651565
n_runs=4) # perform 4 runs per algorithm * instance combination
15661566

1567-
end_results = [] # this list will receive the end results records
1568-
from_logs(td, end_results.append) # get results from log files
1569-
1567+
data = list(from_logs(td)) # load end results
15701568
er_csv = to_csv( # store end results to csv file (returns path)
1571-
end_results, # the list of end results to store
1572-
td.resolve_inside("end_results.txt")) # path to the file to generate
1569+
data, td.resolve_inside("end_results.txt")) # path to output file
15731570
print(er_csv.read_all_str()) # read generated file as string and print it
15741571
# When leaving "while", the temp directory will be deleted
15751572
```
@@ -1700,8 +1697,7 @@ with temp_dir() as td:
17001697
max_fes=10000, # we grant 10000 FEs per run
17011698
n_runs=4) # perform 4 runs per algorithm * instance combination
17021699

1703-
end_results = [] # this list will receive the end results records
1704-
from_logs(td, end_results.append) # get results from log files
1700+
end_results = list(from_logs(td)) # get results from log files
17051701

17061702
end_stats = [] # the list to receive the statistics records
17071703
# compute end result statistics for all algorithm+instance combinations

examples/ecdf_plot.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,8 @@ def make_random_walk(problem) -> Execution:
128128
n_runs=31) # we will execute 31 runs per setup
129129
# Once we arrived here, the experiment with 2*1*31 = 62 runs has completed.
130130

131-
data = [] # we will load the data into this list
132-
from_logs(path=td, # the result directory
133-
consumer=data.append, # put the data into data
134-
time_unit="FEs", # time is in FEs (as opposed to "ms")
135-
f_name="plainF") # use raw, unscaled objective values
131+
data = list(from_logs( # load the data
132+
path=td, time_unit="FEs", f_name="plainF"))
136133
ecdfs = [] # we will load the ECDFs into this list
137134
# The below function uses the goal objective values from the log files to
138135
# compute the ECDF functions. It groups all runs of one algorithm together

examples/end_results_jssp.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
max_fes=10000, # we grant 10000 FEs per run
2323
n_runs=4) # perform 4 runs per algorithm * instance combination
2424

25-
end_results = [] # this list will receive the end results records
26-
from_logs(td, end_results.append) # get results from log files
27-
25+
data = list(from_logs(td)) # load end results
2826
er_csv = to_csv( # store end results to csv file (returns path)
29-
end_results, # the list of end results to store
30-
td.resolve_inside("end_results.txt")) # path to the file to generate
27+
data, td.resolve_inside("end_results.txt")) # path to output file
3128
print(er_csv.read_all_str()) # read generated file as string and print it
3229
# When leaving "while", the temp directory will be deleted

examples/end_results_plot.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def make_hill_climber(problem: Instance) -> Execution:
106106
n_runs=31) # we will execute 31 runs per setup
107107
# Once we arrived here, the experiment with 2*3*31=186 runs has completed.
108108

109-
data = [] # we will load the data into this list
110-
from_logs(td, data.append) # load all end results
109+
data = list(from_logs(td)) # we will load the data into this list
111110

112111
# Plot the end results in a scaled fashion: All objective values are
113112
# divided by the lower bound. Therefore, 1 is optimal.

examples/end_results_table.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ def make_random_sampling(problem: Instance) -> Execution:
152152
n_runs=7) # we will execute 31 runs per setup
153153
# Once we arrived here, the experiment with 3*3*7=63 runs has completed.
154154

155-
data = [] # we will load the data into this list
156-
from_logs(td, data.append) # load all end results
155+
data = list(from_logs(td)) # we will load the data into this list
157156

158157
file = tabulate_end_results(data, dir_name=td) # create the table
159158
print(f"\nnow presenting markdown data from file {file!r}.\n")

examples/end_results_tests.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ def rls(problem, op1) -> Execution:
8787
lambda p: rls(p, Op1MoverNflip(p.n, 2)), # flip bits at p=2/n
8888
], n_runs=21) # conduct 21 independent runs per setup
8989

90-
# load all the end results
91-
end_results = []
92-
from_logs(td, end_results.append)
90+
end_results = list(from_logs(td)) # we will load the data into this list
9391

9492
# create a markdown table with statistical test results
9593
file = tabulate_result_tests(end_results, dir_name=td)

examples/end_results_with_limits_plot.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,10 @@ def make_rls(problem: OneMax) -> Execution:
7070

7171
# We now collect the end results at different stages, namely at 16 FEs,
7272
# 32 FEs, 64 FEs, and after the full rumtime = 128 FEs.
73-
data_16 = [] # results after 16 FEs
74-
from_logs(td, data_16.append, max_fes=16) # load end results
75-
data_32 = [] # results after 32 FEs
76-
from_logs(td, data_32.append, max_fes=32) # load end results
77-
data_64 = [] # results after 64 FEs
78-
from_logs(td, data_64.append, max_fes=64) # load end results
79-
data_128 = [] # results after 128 FEs
80-
from_logs(td, data_128.append, max_fes=128) # load end results
73+
data_16 = list(from_logs(td, max_fes=16)) # results after 16 FEs
74+
data_32 = list(from_logs(td, max_fes=32)) # results after 16 FEs
75+
data_64 = list(from_logs(td, max_fes=64)) # results after 16 FEs
76+
data_128 = list(from_logs(td, max_fes=128)) # results after 16 FEs
8177
items = [[16, data_16], [32, data_32], [64, data_64], [128, data_128]]
8278

8379
# We create a multi-figure, i.e., one figure with multiple charts inside.

examples/end_statistics_jssp.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
max_fes=10000, # we grant 10000 FEs per run
2424
n_runs=4) # perform 4 runs per algorithm * instance combination
2525

26-
end_results = [] # this list will receive the end results records
27-
from_logs(td, end_results.append) # get results from log files
26+
end_results = list(from_logs(td)) # get results from log files
2827

2928
end_stats = [] # the list to receive the statistics records
3029
# compute end result statistics for all algorithm+instance combinations

examples/end_statistics_over_feature_plot.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def make_rls(problem) -> Execution:
8080
n_runs=7) # we will execute 7 runs per setup
8181
# Once we arrived here, the 20*7 = 140 runs have completed.
8282

83-
end_results = [] # we will load the raw data into this list
84-
from_logs(td, end_results.append)
83+
end_results = list(from_logs(td)) # load results
8584

8685
end_stats = [] # the end statistics go into this list
8786
from_end_results(end_results, end_stats.append)

examples/end_statistics_over_param_plot.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def make_rls(problem, m: int) -> Execution:
9393
n_runs=11) # we will execute 11 runs per setup
9494
# Once we arrived here, the 11*11*2 = 242 runs have completed.
9595

96-
end_results = [] # we will load the raw data into this list
97-
from_logs(td, end_results.append)
96+
end_results = list(from_logs(td)) # load results
9897

9998
end_stats = [] # the end statistics go into this list
10099
from_end_results(end_results, end_stats.append)

examples/ert_plot.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,8 @@ def make_random_walk(problem) -> Execution:
110110
n_runs=21) # we will execute 71 runs per setup
111111
# Once we arrived here, the experiment with 2*1*31 = 62 runs has completed.
112112

113-
data = [] # we will load the data into this list
114-
from_logs(path=td, # the result directory
115-
consumer=data.append, # put the data into data
116-
time_unit="FEs", # time is in FEs (as opposed to "ms")
117-
f_name="plainF") # use raw, unscaled objective values
113+
data = list(from_logs( # load the data
114+
path=td, time_unit="FEs", f_name="plainF"))
118115
ert = [] # we will load the ERT into this list
119116
# The below function groups all runs of one algorithm and instance
120117
# together and then computes the ERT.

examples/ertecdf_plot.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ def make_rls(problem) -> Execution:
7171
n_runs=21) # we will execute 21 runs per setup
7272
# Once we arrived here, the experiment with 11*21 = 231 runs has completed.
7373

74-
data = [] # we will load the data into this list
75-
from_logs(path=td, # the result directory
76-
consumer=data.append, # put the data into data
77-
time_unit="FEs", # time is in FEs (as opposed to "ms")
78-
f_name="plainF") # use raw, unscaled objective values
74+
data = list(from_logs( # load the data
75+
path=td, time_unit="FEs", f_name="plainF"))
7976
ertecdf = [] # we will load the ERT-ECDFs into this list
8077
# The below function uses the goal objective values from the log files to
8178
# compute the ERT-ECDF functions. It groups all runs of one algorithm

examples/progress_plot.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ def make_random_walk(problem) -> Execution:
120120
n_runs=5) # we will execute 5 runs per setup
121121
# Once we arrived here, the experiment with 2*2*5 = 20 runs has completed.
122122

123-
data = [] # we will load the data into this list
124-
pr_from_logs(path=td, # the result directory
125-
consumer=data.append, # put the data into data
126-
time_unit="FEs", # time is in FEs (as opposed to "ms")
127-
f_name="plainF") # use raw, unscaled objective values
123+
data = list(pr_from_logs( # we will load the data into this list
124+
path=td, # the result directory
125+
time_unit="FEs", # time is in FEs (as opposed to "ms")
126+
f_name="plainF")) # use raw, unscaled objective values
128127

129128
# The first plot will contain every single one of the 20 runs.
130129
# The system will choose different styles for different algorithms

0 commit comments

Comments
 (0)