This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
116 lines (99 loc) · 3.2 KB
/
main.go
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
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"strconv"
// Blank imports needed for registering agents with agent package
// to enable TypedConfigList's
"github.com/samuelfneumann/gogym"
_ "github.com/samuelfneumann/golearn/agent/linear/continuous/actorcritic"
_ "github.com/samuelfneumann/golearn/agent/linear/discrete/esarsa"
_ "github.com/samuelfneumann/golearn/agent/linear/discrete/qlearning"
_ "github.com/samuelfneumann/golearn/agent/nonlinear/continuous/vanillaac"
_ "github.com/samuelfneumann/golearn/agent/nonlinear/continuous/vanillapg"
_ "github.com/samuelfneumann/golearn/agent/nonlinear/discrete/deepq"
"github.com/samuelfneumann/golearn/experiment"
"github.com/samuelfneumann/golearn/experiment/checkpointer"
"github.com/samuelfneumann/golearn/experiment/tracker"
)
func main() {
if len(os.Args) != 3 {
printHelp()
os.Exit(1)
}
expFile, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
dec := json.NewDecoder(expFile)
var expConf experiment.Config
err = dec.Decode(&expConf)
if err != nil {
panic(fmt.Sprintf("could not decode experiment config: %v",
err))
}
expFile.Close()
numSettings := int64(expConf.AgentConfig.Len())
hpIndex, err := strconv.ParseInt(os.Args[2], 0, 0)
if err != nil {
panic(err)
}
run := uint64(hpIndex / numSettings)
// Print some information about the experiment
fmt.Println("=== Experiment Starting")
fmt.Printf("\t Experiment Type:\t\t%v \n", expConf.Type)
fmt.Printf("\t Experiment Total Steps:\t%v \n", expConf.MaxSteps)
fmt.Printf("\t Total Configurations: \t\t%v\n", numSettings)
fmt.Printf("\t Configuration Index: \t\t%v\n", hpIndex%numSettings)
fmt.Printf("\t Run: \t\t\t\t%v\n", run)
fmt.Println()
fmt.Printf("\t Environment: \t\t\t%v\n", expConf.EnvConfig.Environment)
fmt.Printf("\t Environment Configuration: \t%v\n", expConf.EnvConfig)
fmt.Println()
fmt.Printf("\t Agent: \t\t\t%v\n", expConf.AgentConfig.Type)
fmt.Printf("\t Agent Configuration: \t\t%v\n",
expConf.AgentConfig.At(int(hpIndex)))
fmt.Println()
// Filenames of data to save
returnFilename := fmt.Sprintf(
"return_%v_%v_run%v.bin",
expConf.AgentConfig.Type,
expConf.EnvConfig.Environment,
run,
)
epLengthFilename := fmt.Sprintf(
"epLength_%v_%v_run%v.bin",
expConf.AgentConfig.Type,
expConf.EnvConfig.Environment,
run,
)
// Create trackers to track and save data from experiment
trackers := []tracker.Tracker{
tracker.NewReturn(returnFilename),
tracker.NewEpisodeLength(epLengthFilename),
}
// Don't checkpoint agents
var checkpointers []checkpointer.Checkpointer = nil
exp, err := expConf.CreateExp(int(hpIndex), run, trackers, checkpointers)
if err != nil {
log.Printf("Error creating experiment: %v\n", err)
log.Println("Terminating...")
}
if err := exp.Run(); err != nil {
log.Printf("Error in running experiment: %v\n", err)
log.Println("Terminating...")
}
exp.Save()
// LoadData -> should be int or float specified...
data := tracker.LoadFData(returnFilename)
fmt.Println(data)
// Clean up GoGym package before leaving
gogym.Close()
}
// printHelp prints a help menu that outlines the usage of the command
func printHelp() {
msg := fmt.Sprintf("\nusage: %v config index", os.Args[0])
fmt.Println(msg)
}