Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New experiments features (model/agent/representation comparison, ...) #37

Open
wants to merge 236 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
236 commits
Select commit Hold shift + click to select a range
ed7c8b1
Made knapsack problem functional with metrics export
louis-gautier Apr 12, 2022
ad66ec8
Fixed MissingMethod error in tsptw experiment
louis-gautier Apr 12, 2022
50d021f
Adapted TSPTW to DefaultStateRepresentation
louis-gautier Apr 13, 2022
59eba22
Fixed hardcoding of the number of cities
louis-gautier Apr 13, 2022
9ea00cf
Merge branch 'master' into louis/experiments_fixes
louis-gautier Apr 14, 2022
be59294
Merge tsptw.jl et tsptw_defaultstaterepresentation.jl into one file
gostreap Apr 14, 2022
e7f7f91
Added FeaturizationHelper experiment for TSPTW
louis-gautier Apr 14, 2022
2411e12
Merge branch 'louis/experiments_fixes' of https://github.com/corail-r…
louis-gautier Apr 14, 2022
6f128af
Fix nb_features
gostreap Apr 14, 2022
723adeb
Provisory adjustment to take one-hot encoding of constraint type into…
louis-gautier Apr 20, 2022
fcc1b5b
Changed values to perform easy experiments on TSPTW
louis-gautier Apr 22, 2022
bf41887
Merge branch 'master' into louis/experiments_fixes
louis-gautier Apr 22, 2022
6a834e2
Merge branch 'master' into louis/experiments_fixes
louis-gautier Apr 29, 2022
6de3a93
Adapted agent and problem definition on graphcoloring to automatic ex…
louis-gautier May 2, 2022
1e8664a
Adapted TSPTW with DefaultStateRepresentation to new pipeline
louis-gautier May 6, 2022
9dc66f8
Best current agent hyperparameters for graphcoloring
louis-gautier May 6, 2022
96fee01
Better hyperparameters for TSPTW with DefaultStateRepresentation
louis-gautier May 6, 2022
2634017
More expressive params.json for TSPTW
louis-gautier May 6, 2022
3c41b7f
Better params.json for nqueens
louis-gautier May 6, 2022
f118dd3
Fixed some bugs with TSPTW
louis-gautier May 6, 2022
64298ef
Fixed some bugs with nqueens
louis-gautier May 6, 2022
042764d
Better parameters for graphcoloring and nqueens
louis-gautier May 10, 2022
d6a4982
Merge remote-tracking branch 'origin/master' into louis/experiments_f…
louis-gautier May 10, 2022
de6c19e
Converting LearnedHeuristic to SimpleLearnedHeuristic
louis-gautier May 10, 2022
9713ade
Adding all files to compare classic and heterogeneous pipeline
louis-gautier May 13, 2022
2da7af6
Merge remote-tracking branch 'origin/master' into heterogeneous
louis-gautier May 13, 2022
f014632
Saving parameters for graphcoloring
louis-gautier May 13, 2022
8bd57ce
Saving parameters for nqueens
louis-gautier May 13, 2022
280e73b
Saving parameters for TSPTW
louis-gautier May 13, 2022
2cd9fa6
Add common and graph coloring using common
gostreap May 13, 2022
ce80279
Fix and enhance common + convert nqueens to common
gostreap May 13, 2022
6d3670c
Modified agents.jl for comparing the same number of layers
louis-gautier May 17, 2022
8eb7a95
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier May 17, 2022
7724118
Create comparison folfer
gostreap May 18, 2022
486a33f
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap May 18, 2022
e6a599e
Add hetereogeneous utils to comparison
gostreap May 18, 2022
6f3738f
Add experiment compare n layers for heterogeneous
gostreap May 18, 2022
c84d5ae
Add chosen_features comparison for heterogeneous graphcoloring
gostreap May 18, 2022
36234de
Break comparison into mutliple files and add rb
gostreap May 19, 2022
a41e697
Fixes for new experiments
louis-gautier May 19, 2022
534f506
Add chosen features to comparison in graphcoloring
gostreap May 20, 2022
c761f58
Add kep to comparison
gostreap May 20, 2022
24eaba5
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap May 20, 2022
1561975
Small change to rb.jl
gostreap May 20, 2022
a7cfbbd
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap May 20, 2022
16187e6
Merge branch 'master' into heterogeneous
louis-gautier May 20, 2022
bc806d5
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier May 20, 2022
92465e2
Make heterogeneous_chosen_features generic
gostreap May 20, 2022
2d54a9e
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap May 20, 2022
536a9ef
Add chosen features heterogeneous to comparison for nqueens and kep
gostreap May 20, 2022
35efa19
Add dependency to comparison
gostreap May 20, 2022
e91bcd4
Add nohup to gitignore
gostreap May 20, 2022
e066d45
Add generic expriment_representation
gostreap May 20, 2022
623c648
Switch experiment representation of graph coloring to generic
gostreap May 20, 2022
6b86ed1
Add comparaison simple/supervised for heterogeneous for graphcoloring
gostreap May 24, 2022
c202d48
Make utils explorer independent
gostreap May 24, 2022
6bfdce6
add experiment + make utils cpnn independent
gostreap May 25, 2022
a09d8a1
add compare cpnn to comparison
gostreap May 25, 2022
e208ba4
Small clean
gostreap May 25, 2022
19d5d09
Add hgt in utils
gostreap Jun 1, 2022
4b1c351
Add experiment for pooling
gostreap Jun 2, 2022
16cbfa7
Clean the code and add add arguments
ziadelassal Jun 6, 2022
fd632d3
Add experiment to comparison/graphcoloring
gostreap Jun 6, 2022
e33a582
Add transfer.jl to graphcoloring
gostreap Jun 6, 2022
2d8ec3e
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 6, 2022
91e79e0
Comment everything related to hgt
gostreap Jun 6, 2022
891c017
Small Clean Up
gostreap Jun 6, 2022
baa2ac6
made experiment_n_conv generic
Jun 6, 2022
790d080
fix experiment_n_conv
Jun 6, 2022
86ec47a
fixed experiment_n_conv
Jun 6, 2022
0cc4176
fixed experiment_n_conv argument
Jun 6, 2022
257a464
Add pooling to utils
gostreap Jun 7, 2022
a233283
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 7, 2022
95af942
Fix comma
gostreap Jun 7, 2022
0d51f5f
fixed comparison.jl
Jun 7, 2022
0c8bc5b
fix latin features size
Jun 7, 2022
f91d462
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 7, 2022
983aad9
Prepares experiments for comparing impact of features
louis-gautier Jun 7, 2022
33bc0b1
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 7, 2022
3ec6da1
WIP on explorer exp
Jun 7, 2022
b6241dc
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 7, 2022
20ed468
Set output_size for mean
gostreap Jun 7, 2022
1b74ad0
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 7, 2022
84a7c99
Add default value in utils
gostreap Jun 7, 2022
114ee09
implemented Experiment Type 6
Jun 7, 2022
4d83118
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 7, 2022
905e8d5
Replaced experiment parameters by saving all files + new experiment
louis-gautier Jun 8, 2022
7669283
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 8, 2022
1d4727e
Preparation of features experiment
louis-gautier Jun 8, 2022
8c2d639
Add transfer experiment
gostreap Jun 8, 2022
0ecf11f
Clean the documentation
ziadelassal Jun 8, 2022
abe0176
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 8, 2022
c2788b8
Added MIS experiment
louis-gautier Jun 8, 2022
03c4826
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 8, 2022
82ae84d
added dependencies to avoid a compilation crash
Jun 8, 2022
72d9d49
added pooling arg for EXP 6
Jun 8, 2022
dc5a910
added pooling arg for EXP 6
Jun 8, 2022
639f1b2
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 8, 2022
de643e9
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 8, 2022
f8dc8a0
Corrections on features experiments
louis-gautier Jun 8, 2022
0f4cda6
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 8, 2022
9c03cee
Add experiment for restart
gostreap Jun 9, 2022
439b7f7
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 9, 2022
fa4ec8e
Add compatibility with FFCPNNv2
ziadelassal Jun 9, 2022
1ade471
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 9, 2022
f29bc56
Fix to restart experiment
gostreap Jun 9, 2022
7ce2a54
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 9, 2022
914a543
Change restart experiment name
gostreap Jun 9, 2022
30db6ed
Add compatibility with FFCPNNv3
ziadelassal Jun 9, 2022
ac059a3
Fix bugs in the creation of NNs with more than 2 layers
ziadelassal Jun 9, 2022
7132645
New features comparison experiments
louis-gautier Jun 10, 2022
e60f8de
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 10, 2022
16413e2
Add activation functions
ziadelassal Jun 10, 2022
d8bec2d
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 10, 2022
1a32bae
added pool for latin
Jun 10, 2022
1cf0fb9
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 10, 2022
a85a055
Add type better type to experiment 10 in MIS
gostreap Jun 13, 2022
79aceb3
Fix critical mistake with activation function on the last layer
louis-gautier Jun 13, 2022
1b8626c
Modified gitignore
louis-gautier Jun 13, 2022
bcb91b5
Modified gitignorer
louis-gautier Jun 13, 2022
841b302
Add activation experiment for nqueens
ziadelassal Jun 13, 2022
e2215bb
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 13, 2022
850e07c
Remove ArgParse
gostreap Jun 13, 2022
675e766
Add Project.toml to mis folder
gostreap Jun 13, 2022
245d2e6
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 13, 2022
e0e2ff1
Remove the activation function on the last layer
ziadelassal Jun 13, 2022
2fed826
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 13, 2022
501f059
Enabling evaluation with ILDS
louis-gautier Jun 13, 2022
33a3e7a
Added simple experiment on KEP
louis-gautier Jun 13, 2022
a22dee7
Experiment HGT vs HeterogeneousGraphConv
louis-gautier Jun 13, 2022
33eb30b
Add transfer learning to MIS.jl
gostreap Jun 14, 2022
0368324
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jun 14, 2022
9a5f807
Add n_eval_transfered to transfer experiment
gostreap Jun 14, 2022
8ac1686
Simple experiments in KEP, nqueens and MIS
louis-gautier Jun 14, 2022
927c07a
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 14, 2022
20fc8f7
Simple experiments updates
louis-gautier Jun 14, 2022
6a38068
fix typo
Jun 14, 2022
9b0ba1e
rl agents comparison
malikattalah Jun 14, 2022
dfa2814
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
malikattalah Jun 14, 2022
21a81a8
Simple graphcoloring experiment
louis-gautier Jun 14, 2022
16db24e
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 14, 2022
a2f45c3
RL experiment building
louis-gautier Jun 14, 2022
32a6182
simple dqn & ppo experiments working
malikattalah Jun 14, 2022
2b4ecbd
rl agents comparison functional
malikattalah Jun 15, 2022
d2cd315
added FFCPNN experiment for KEP
Jun 15, 2022
d2d0495
Add FFCPNNv4
ziadelassal Jun 15, 2022
f70bfb1
Add pooling experiment
ziadelassal Jun 15, 2022
b10546e
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 15, 2022
30af752
New explorer comparison experiment
louis-gautier Jun 16, 2022
e88b78b
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 16, 2022
0c3a44a
added seed for graphcoloring
Jun 17, 2022
a777018
max heuristic for kep
Jun 17, 2022
d9bedad
updated gitignore
Jun 17, 2022
0738c99
added seedTraining
Jun 17, 2022
d4b55b5
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 17, 2022
2bca43b
Comparison of tripartite graph vs specific representation
louis-gautier Jun 17, 2022
47b75ee
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 17, 2022
31e218c
Running MIS simple experiments
louis-gautier Jun 17, 2022
3d8ad79
enables ppo with MIS
malikattalah Jun 20, 2022
bebf813
Add update_freq and pooling experiments
ziadelassal Jun 20, 2022
a93e07e
Added jobshop problem
louis-gautier Jun 20, 2022
abb4962
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 20, 2022
8a65e52
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 20, 2022
cb5055a
ppo parameters modification
malikattalah Jun 21, 2022
cde9692
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
malikattalah Jun 21, 2022
6b53a31
Added performance profiles
louis-gautier Jun 21, 2022
9cafbd0
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 21, 2022
c9c8722
Exclude all .out files
louis-gautier Jun 21, 2022
2019a5e
added experiment reproductibily with seedTraining
Jun 23, 2022
428d104
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jun 23, 2022
21ad01c
Performance profiles and new jobshop experiments
louis-gautier Jun 23, 2022
a4e1329
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jun 23, 2022
28c49d7
Remove duplicate parameter
gostreap Jun 28, 2022
e883cad
Correct experiment functions documentation
ziadelassal Jun 28, 2022
52b1cd8
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
ziadelassal Jun 28, 2022
ba1c5a2
added reward comparison experience
Jul 6, 2022
1169192
add reward comparison experience
Jul 6, 2022
9a8dd29
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jul 6, 2022
e41be1e
Experiments with JobShop and comparison of rewards
louis-gautier Jul 7, 2022
4c2eab7
New experiments on graphcoloring
louis-gautier Jul 7, 2022
192728b
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jul 7, 2022
edf0ab9
added eval_generator
Jul 8, 2022
1aa227e
added simple experiment for GC and MIS
Jul 8, 2022
b63610e
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jul 8, 2022
ab394b1
Evaluation tool for benchmarks
louis-gautier Jul 8, 2022
4f3e90a
added seedEval in trytrain!
Jul 11, 2022
ca266c6
added seed for eval and model init
Jul 11, 2022
398f737
added seeding for MIS
Jul 11, 2022
b85c184
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jul 11, 2022
c0d9083
Add benchmark util
louis-gautier Jul 12, 2022
9894ee0
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jul 12, 2022
d2dc900
Fixed issue with rng in epsilon greedy explorer
louis-gautier Jul 12, 2022
9331707
added HeterogeneousModel24
Jul 12, 2022
9f36748
added seed on GC
Jul 12, 2022
3e05f5e
Improving benchmark util
louis-gautier Jul 13, 2022
6912ed5
Added comments on benchmark utils
louis-gautier Jul 13, 2022
2ae9ae9
changed relu to leakyrelu + convnet typo fix
Jul 18, 2022
6035d99
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jul 18, 2022
bbf6f55
added stratety argument for trytrain
Jul 19, 2022
7280ac3
more generic definition of HeterogeneousModel
Jul 19, 2022
1f10884
Add supervised vs simple experiment to mis
gostreap Jul 21, 2022
c53be3b
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
gostreap Jul 21, 2022
ff79a4c
Add chain transfer to comparison
gostreap Jul 26, 2022
d2d4a72
Fix typo in comparison
gostreap Jul 26, 2022
691607b
Add date folder to store experiment
gostreap Jul 26, 2022
817c0f7
Work on activation functions
louis-gautier Jul 27, 2022
b45c4cc
Work on comparisons
louis-gautier Jul 27, 2022
756c532
Work on experiments on specific problems
louis-gautier Jul 27, 2022
933655e
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Jul 27, 2022
356bbf2
fix GPU bug
Jul 28, 2022
6c071fb
WIP on KEP
Jul 28, 2022
1093a1a
new params for simple_graph_coloring_experiment
Jul 28, 2022
864b085
new params for simple_experiment_MIS
Jul 28, 2022
a9c7348
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Jul 28, 2022
68afc54
Last various modifications on SeaPearlZoo
louis-gautier Aug 3, 2022
9b7f576
Merge branch 'heterogeneous' of https://github.com/corail-research/Se…
louis-gautier Aug 3, 2022
e1231f7
added adctivation function for dense Chain
Aug 5, 2022
6e89bf3
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Aug 11, 2022
b0d5bed
added |> device
Aug 11, 2022
685dd88
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Aug 11, 2022
62fba5b
Remove old unused File
gostreap Aug 17, 2022
4aa131f
updated .gitignore
Aug 23, 2022
2f498b4
benchmark now order benchmark files
Aug 23, 2022
0212b62
updated project.toml
Aug 23, 2022
28a7039
added tuto tensorboard
Aug 23, 2022
029e6cd
automated plotting and benchmark for any training experiment
Aug 23, 2022
25ffd93
new experiments
Aug 23, 2022
b87eb94
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Aug 23, 2022
bb3282c
improved tensorboard logger
Aug 30, 2022
007e3c5
updated GC and MIS
Aug 30, 2022
17c1746
updated Project.toml
Aug 30, 2022
5621d19
updated benchmark.jl for more than ILDS(2) query
Sep 6, 2022
813947c
added device arg in trytrain func
Sep 6, 2022
18aea6d
updated all experiment
Sep 6, 2022
1583fb1
updated .gitignore
Sep 20, 2022
856158c
Merge branch 'heterogeneous' of github.com:corail-research/SeaPearlZo…
Sep 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,23 @@ exp_*/
*.png

# Plot files
*plot.ipynb
*plot.ipynb
*plot.py

# Save experiment files
*save_experiment.py

# nohup output
nohup*.out

learning_cp/tsptw/old_exp/
learning_cp/tsptw/TSPTW*
# all run files
run*.jl
*.sh
learning_cp/comparison/plots.jl

# all .out files (nohup output)
*.out

learning_cp/comparison/tensorboard_logs
142 changes: 142 additions & 0 deletions learning_cp/common/benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# This util evaluates a trained model on n new instances with ILDS(1), ILDS(2), ILDS with given budget and DFS
# Any heuristic using specific state representation should have "specific" in its file name
#include("../common/experiment.jl")
include("../comparison/comparison.jl")
include("utils.jl")

#include("experiment.jl")
#include("../comparison/comparison.jl")
#include("utils.jl")
using CUDA

# Parameters to edit
folder = "/home/martom/SeaPearl/SeaPearlZoo/learning_cp/comparison/2022-08-17/exp_MaxCut_100_10_4->10_4_10012-02-09/"

chosen_features = Dict(
"node_number_of_neighbors" => true,
"constraint_type" => true,
"constraint_activity" => true,
"nb_not_bounded_variable" => true,
"variable_initial_domain_size" => true,
"variable_domain_size" => true,
"variable_is_objective" => true,
"variable_assigned_value" => true,
"variable_is_bound" => true,
"values_raw" => true)

n = 20
k = 4
generator = SeaPearl.MaxCutGenerator(n,k)
n = 10 # Number of instances to evaluate on
budget = 10000 # Budget of visited nodes
has_objective = false # Set it to true if we have to branch on the objective variable
include_dfs = false # Set it to true if you want to evaluate with DFS in addition to ILDS

# Define your basic heuristics here
threshold = 2*k
MISHeuristic(x; cpmodel=nothing) = length(x.onDomainChange) - 1 < threshold ? 1 : 0
heuristic_mis = SeaPearl.BasicHeuristic(MISHeuristic)
selectMax(x::SeaPearl.IntVar; cpmodel=nothing) = SeaPearl.maximum(x.domain)
heuristic_max = SeaPearl.BasicHeuristic(selectMax)
basicHeuristics = OrderedDict(
"random" => SeaPearl.RandomHeuristic()
)

function benchmark(folder::String, n::Int, chosen_features, has_objective::Bool, generator, basicHeuristics, include_dfs, budget::Int; verbose=true, ILDS = nothing)
models=[]
models_names=[]
for file in readdir(folder)
if splitext(file)[2] == ".bson"
@load folder * "/" * file model
push!(models, model)
push!(models_names, replace(splitext(file)[1], "model_"=>""))
end
end

reward = SeaPearl.GeneralReward

eval_strategies = SeaPearl.SearchStrategy[]
search_strategy_names = String[]
if typeof(ILDS) == SeaPearl.ILDSearch
for i in 0:ILDS.d
push!(eval_strategies, SeaPearl.ILDSearch(i))
push!(search_strategy_names, "ILDS"*string(i))
end
push!(eval_strategies, SeaPearl.ILDSearch(10))
append!(search_strategy_names, ["ILDSbudget", "DFS"])
else
eval_strategies = SeaPearl.SearchStrategy[SeaPearl.ILDSearch(0),SeaPearl.ILDSearch(1),SeaPearl.ILDSearch(2),SeaPearl.ILDSearch(10)]
search_strategy_names = ["ILDS0", "ILDS1", "ILDS2", "ILDSbudget", "DFS"]
if include_dfs
push!(eval_strategies,SeaPearl.DFSearch())
end
end

agents = []
valueSelectionArray = SeaPearl.ValueSelection[]

for (i,model) in enumerate(models)
agent = RL.Agent(
policy=RL.QBasedPolicy(
learner=RL.DQNLearner(
approximator=RL.NeuralNetworkApproximator(
model=model,
optimizer=ADAM()
) |> cpu,
target_approximator=RL.NeuralNetworkApproximator(
model=model,
optimizer=ADAM()
) |> cpu,
loss_func=Flux.Losses.huber_loss
),
explorer=RL.EpsilonGreedyExplorer(
ϵ_stable=0.0
)
),
trajectory=RL.CircularArraySLARTTrajectory(
capacity=1,
state=SeaPearl.DefaultTrajectoryState[] => (),
legal_actions_mask=Vector{Bool} => (1,),
)
)
push!(agents,agent)
if occursin("specific",models_names[i])
if isa(generator, SeaPearl.MaximumIndependentSetGenerator)
state_representation = SeaPearl.MISStateRepresentation{SeaPearl.MISFeaturization,SeaPearl.DefaultTrajectoryState}
elseif isa(generator, SeaPearl.LegacyGraphColoringGenerator) || isa(generator, SeaPearl.HomogeneousGraphColoringGenerator) || isa(generator, SeaPearl.ClusterizedGraphColoringGenerator) || isa(generator, SeaPearl.BarabasiAlbertGraphGenerator) || isa(generator, SeaPearl.ErdosRenyiGraphGenerator) || isa(generator, SeaPearl.WattsStrogatzGraphGenerator)
state_representation = SeaPearl.GraphColoringStateRepresentation{SeaPearl.GraphColoringFeaturization, SeaPearl.DefaultTrajectoryState}
end
push!(valueSelectionArray, SeaPearl.SimpleLearnedHeuristic{state_representation,reward,SeaPearl.FixedOutput}(agent))
else
state_representation = SeaPearl.HeterogeneousStateRepresentation{SeaPearl.DefaultFeaturization, SeaPearl.HeterogeneousTrajectoryState}
push!(valueSelectionArray, SeaPearl.SimpleLearnedHeuristic{state_representation,reward,SeaPearl.FixedOutput}(agent; chosen_features=chosen_features))
end
end
append!(valueSelectionArray, collect(values(basicHeuristics)))
append!(models_names, collect(keys(basicHeuristics)))
variableHeuristic = SeaPearl.MinDomainVariableSelection{has_objective}()
evaluator = SeaPearl.SameInstancesEvaluator(valueSelectionArray, generator; nbInstances=n)
folder_names = split(folder, "/")
#println(pwd())
#println(folder)
if !isdir("../benchmarks/"*folder_names[1])
mkdir("../benchmarks/"*folder_names[1])
end
dir = mkdir("../benchmarks/"*folder)
for (j, search_strategy) in enumerate(eval_strategies)
if search_strategy == SeaPearl.ILDSearch(10)
SeaPearl.setNodesBudget!(evaluator, budget)
end
SeaPearl.evaluate(evaluator, variableHeuristic, search_strategy; verbose = verbose)
eval_metrics = evaluator.metrics
for i in 1:size(eval_metrics)[2]
SeaPearlExtras.storedata(eval_metrics[:, i]; filename= dir *"/"* search_strategy_names[j] * "_" * models_names[i])
end
# empty evaluator metrics
if search_strategy == SeaPearl.ILDSearch(10)
SeaPearl.resetNodesBudget!(evaluator)
end
empty!(evaluator)
end
end
#benchmark(folder, n, chosen_features, has_objective, generator, basicHeuristics, include_dfs, budget)
147 changes: 147 additions & 0 deletions learning_cp/common/experiment.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using SeaPearl
using SeaPearlExtras
using ReinforcementLearning
const RL = ReinforcementLearning
using Flux
using GeometricFlux
using JSON
using BSON: @save, @load
using Dates
using Random
using LightGraphs
using OrderedCollections
using CircularArrayBuffers
using PyCall
using Pkg
using TensorBoardLogger, Logging

"""
ENV["PYTHON"] = "/home/x86_64-unknown-linux_ol7-gnu/anaconda-2022.05/bin/python"
using Pkg
Pkg.build("PyCall")
run(`$(PyCall.python) -m pip install matplotlib`)
run(`$(PyCall.python) -m pip install pandas`)
run(`$(PyCall.python) -m pip install seaborn`)
run(`$(PyCall.python) -m pip install ipython`)
"""

# -------------------
# -------------------
# Core function
# -------------------
# -------------------

function trytrain(; nbEpisodes::Int, evalFreq::Int, nbInstances::Int, restartPerInstances::Int=1, generator::SeaPearl.AbstractModelGenerator, variableHeuristic::SeaPearl.AbstractVariableSelection=SeaPearl.MinDomainVariableSelection{false}(), learnedHeuristics::OrderedDict{String,<:SeaPearl.LearnedHeuristic}, basicHeuristics::OrderedDict{String,SeaPearl.BasicHeuristic}, base_name="experiment"::String, exp_name=""::String, out_solver=true::Bool, verbose=false::Bool, nbRandomHeuristics=0::Int, eval_timeout=nothing::Union{Nothing, Int}, training_timeout=nothing::Union{Nothing, Int}, eval_every =nothing::Union{Nothing, Int}, eval_strategy=SeaPearl.DFSearch(), strategy = SeaPearl.DFSearch(), seedTraining = nothing::Union{Nothing, Int}, seedEval = nothing, eval_generator=nothing, logger = nothing, device = cpu)


experienceTime = Base.replace("$(round(now(), Dates.Second(3)))", ":" => "-")
date = split(experienceTime, "T")[1]
time = split(experienceTime, "T")[2]
logger =TBLogger("tensorboard_logs/"*exp_name*date*"_"*time, min_level=Logging.Info)

if !isdir(date)
mkdir(date)
end
dir = mkdir(string(date, "/exp_", exp_name, time))
lh = last(collect(values(learnedHeuristics)))
code_dir = mkdir(dir*"/code/")
for file in readdir(".")
if isfile(file)
cp(file, code_dir*file)
end
end

randomHeuristics = Array{SeaPearl.BasicHeuristic}(undef, 0)
for i in 1:nbRandomHeuristics
push!(randomHeuristics, SeaPearl.RandomHeuristic())
end

valueSelectionArray = cat(collect(values(learnedHeuristics)), collect(values(basicHeuristics)), randomHeuristics, dims=1)

if !isnothing(eval_generator)
evaluator = SeaPearl.SameInstancesEvaluator(valueSelectionArray, eval_generator; evalFreq=evalFreq, nbInstances=nbInstances, evalTimeOut = eval_timeout, rng = MersenneTwister(seedEval) )
else
evaluator = SeaPearl.SameInstancesEvaluator(valueSelectionArray, generator; evalFreq=evalFreq, nbInstances=nbInstances, evalTimeOut = eval_timeout, rng = MersenneTwister(seedEval))
end
metricsArray, eval_metricsArray = SeaPearl.train!(
valueSelectionArray=valueSelectionArray,
generator=generator,
nbEpisodes=nbEpisodes,
strategy=strategy,
eval_strategy = eval_strategy,
variableHeuristic=variableHeuristic,
out_solver=out_solver,
verbose=verbose,
evaluator = evaluator,
training_timeout = training_timeout,
restartPerInstances=restartPerInstances,
rngTraining = MersenneTwister(seedTraining),
eval_every = eval_every,
logger = logger,
device = device,
)

#saving model weights
for (key, lh) in learnedHeuristics
if (hasfield(typeof(lh.agent.policy),:approximator)) #PPO
model = Flux.cpu(lh.agent.policy.approximator)
else #DQN
model = Flux.cpu(lh.agent.policy.learner.approximator)
end
@save dir * "/model_" * key * ".bson" model
end

counter = 0
for key in keys(learnedHeuristics)
counter += 1
SeaPearlExtras.storedata(metricsArray[counter]; filename=dir * "/" * base_name * "_training_" * key)
end

counter = 0
for key in keys(learnedHeuristics)
counter += 1
SeaPearlExtras.storedata(eval_metricsArray[:, counter]; filename=dir * "/" * base_name * "_" * key)
end
for key in keys(basicHeuristics)
counter += 1
SeaPearlExtras.storedata(eval_metricsArray[:, counter]; filename=dir * "/" * base_name * "_" * key)
end
for i = 1:nbRandomHeuristics
SeaPearlExtras.storedata(eval_metricsArray[:, counter+i]; filename=dir * "/" * base_name * "_random$(i)")
end

py"""
import sys
sys.path.insert(0, "/home/martom/SeaPearl/SeaPearlExtras.jl/src/metrics/basicmetrics/")
from benchmarkPy import *
import plots
import numpy as np
def benchmark(path):
print_all(path +"/")

def plot(path,eval):
plots.all(path +"/", window=100, estimator=np.mean, ilds= eval)
"""

py"plot"(dir, eval_strategy != SeaPearl.DFSearch())

chosen_features = valueSelectionArray[1].chosen_features
feature_size = [6, 5, 2]

n = 10 # Number of instances to evaluate on
budget = 1000 # Budget of visited nodes
has_objective = false # Set it to true if we have to branch on the objective variable
include_dfs = (eval_strategy == SeaPearl.DFSearch()) # Set it to true if you want to evaluate with DFS in addition to ILDS

selectMin(x::SeaPearl.IntVar; cpmodel=nothing) = SeaPearl.minimum(x.domain)
heuristic_min = SeaPearl.BasicHeuristic(selectMin)
basicHeuristics = OrderedDict(
"random" => SeaPearl.RandomHeuristic()
)
include("../common/benchmark.jl")
Base.invokelatest(benchmark, dir, n, chosen_features, has_objective, generator, basicHeuristics, include_dfs, budget; ILDS = eval_strategy)

py"benchmark"(dir)

return metricsArray, eval_metricsArray
end
Loading