Skip to content

Commit

Permalink
all examples updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Dec 17, 2023
1 parent d0173f2 commit 9848f83
Show file tree
Hide file tree
Showing 33 changed files with 2,129 additions and 697 deletions.
6 changes: 3 additions & 3 deletions examples/deep_fsa/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
// EnvConfig has config params for environment
// note: only adding fields for key Env params that matter for both Network and Env
// other params are set via the Env map data mechanism.
type EnvConfig struct { //gti:add
type EnvConfig struct {

// env parameters -- can set any field/subfield on Env struct, using standard TOML formatting
Env map[string]any
Expand All @@ -34,7 +34,7 @@ func (cfg *EnvConfig) InitNameMap() {
}

// ParamConfig has config parameters related to sim params
type ParamConfig struct { //gti:add
type ParamConfig struct {

// network parameters
Network map[string]any
Expand All @@ -59,7 +59,7 @@ type ParamConfig struct { //gti:add
}

// RunConfig has config parameters related to running the sim
type RunConfig struct { //gti:add
type RunConfig struct {

// use the GPU for computation -- generally faster even for small models if NData ~16
GPU bool `def:"true"`
Expand Down
11 changes: 5 additions & 6 deletions examples/deep_fsa/deep_fsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// finite state automaton problem.
package main

//go:generate goki generate
//go:generate goki generate -add-types

import (
"log"
Expand Down Expand Up @@ -52,7 +52,7 @@ func main() {
// state information organized and available without having to pass everything around
// as arguments to methods, and provides the core GUI interface (note the view tags
// for the fields which provide hints to how things should be displayed).
type Sim struct { //gti:add
type Sim struct {

// simulation configuration parameters -- set by .toml config file and / or args
Config Config
Expand Down Expand Up @@ -611,7 +611,7 @@ func (ss *Sim) ConfigNetView(nv *netview.NetView) {
}

// ConfigGUI configures the GoGi gui interface for this simulation,
func (ss *Sim) ConfigGUI() *gi.Body {
func (ss *Sim) ConfigGUI() {
title := "DeepAxon Finite State Automaton"
ss.GUI.MakeBody(ss, "DeepFSA", title, `This demonstrates a basic DeepAxon model on the Finite State Automaton problem (e.g., the Reber grammar). See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
ss.GUI.CycleUpdateInterval = 10
Expand Down Expand Up @@ -674,13 +674,12 @@ func (ss *Sim) ConfigGUI() *gi.Body {
ss.Net.GPU.Destroy()
})
}
return ss.GUI.Body
}

func (ss *Sim) RunGUI() {
ss.Init()
b := ss.ConfigGUI()
b.NewWindow().Run().Wait()
ss.ConfigGUI()
ss.GUI.Body.NewWindow().Run().Wait()
}

func (ss *Sim) RunNoGUI() {
Expand Down
156 changes: 156 additions & 0 deletions examples/deep_fsa/gtigen.go

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions examples/deep_move/deep_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// on visual inputs.
package main

//go:generate goki generate -add-types

import (
"os"

Expand Down Expand Up @@ -49,7 +51,7 @@ func main() {
// state information organized and available without having to pass everything around
// as arguments to methods, and provides the core GUI interface (note the view tags
// for the fields which provide hints to how things should be displayed).
type Sim struct { //gti:add
type Sim struct {

// simulation configuration parameters -- set by .toml config file and / or args
Config Config
Expand Down Expand Up @@ -604,7 +606,7 @@ func (ss *Sim) ConfigNetView(nv *netview.NetView) {
}

// ConfigGUI configures the GoGi gui interface for this simulation,
func (ss *Sim) ConfigGUI() *gi.Body {
func (ss *Sim) ConfigGUI() {
title := "DeepAxon Move Prediction"
ss.GUI.MakeBody(ss, "DeepMove", title, `This demonstrates a basic DeepAxon model on move prediction. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
ss.GUI.CycleUpdateInterval = 10
Expand Down Expand Up @@ -675,13 +677,12 @@ func (ss *Sim) ConfigGUI() *gi.Body {
ss.Net.GPU.Destroy()
})
}
return ss.GUI.Body
}

func (ss *Sim) RunGUI() {
ss.Init()
b := ss.ConfigGUI()
b.NewWindow().Run().Wait()
ss.ConfigGUI()
ss.GUI.Body.NewWindow().Run().Wait()
}

func (ss *Sim) RunNoGUI() {
Expand Down
173 changes: 173 additions & 0 deletions examples/deep_move/gtigen.go

Large diffs are not rendered by default.

106 changes: 55 additions & 51 deletions examples/deep_music/deep_music.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// in a musical sequence of notes.
package main

//go:generate goki generate -add-types

import (
"fmt"
"os"
Expand Down Expand Up @@ -38,7 +40,7 @@ func main() {
sim.New()
sim.ConfigAll()
if sim.Config.GUI {
gimain.Main(sim.RunGUI)
gimain.Run(sim.RunGUI)
} else {
sim.RunNoGUI()
}
Expand Down Expand Up @@ -596,9 +598,9 @@ func (ss *Sim) ConfigNetView(nv *netview.NetView) {
}

// ConfigGUI configures the GoGi gui interface for this simulation,
func (ss *Sim) ConfigGUI() *gi.Window {
func (ss *Sim) ConfigGUI() {
title := "DeepAxon Music Prediction"
ss.GUI.MakeWindow(ss, "DeepMusic", title, `This demonstrates a basic DeepAxon model on music prediction. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
ss.GUI.MakeBody(ss, "DeepMusic", title, `This demonstrates a basic DeepAxon model on music prediction. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
ss.GUI.CycleUpdateInterval = 10

nv := ss.GUI.AddNetView("NetView")
Expand All @@ -610,68 +612,70 @@ func (ss *Sim) ConfigGUI() *gi.Window {

ss.GUI.AddPlots(title, &ss.Logs)

ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "Init", Icon: "update",
Tooltip: "Initialize everything including network weights, and start over. Also applies current params.",
Active: egui.ActiveStopped,
Func: func() {
ss.Init()
ss.GUI.UpdateWindow()
},
})
ss.GUI.Body.AddAppBar(func(tb *gi.Toolbar) {
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "Init", Icon: "update",
Tooltip: "Initialize everything including network weights, and start over. Also applies current params.",
Active: egui.ActiveStopped,
Func: func() {
ss.Init()
ss.GUI.UpdateWindow()
},
})

ss.GUI.AddLooperCtrl(ss.Loops, []etime.Modes{etime.Train, etime.Test})
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "Test Init",
Icon: "reset",
Tooltip: "restart testing",
Active: egui.ActiveAlways,
Func: func() {
ss.Loops.ResetCountersByMode(etime.Test)
},
})
ss.GUI.AddLooperCtrl(tb, ss.Loops, []etime.Modes{etime.Train, etime.Test})
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "Test Init",
Icon: "reset",
Tooltip: "restart testing",
Active: egui.ActiveAlways,
Func: func() {
ss.Loops.ResetCountersByMode(etime.Test)
},
})

////////////////////////////////////////////////
gi.NewSeparator(tb)"log")
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "Reset RunLog",
Icon: "reset",
Tooltip: "Reset the accumulated log of all Runs, which are tagged with the ParamSet used",
Active: egui.ActiveAlways,
Func: func() {
ss.Logs.ResetLog(etime.Train, etime.Run)
ss.GUI.UpdatePlot(etime.Train, etime.Run)
},
})
////////////////////////////////////////////////
gi.NewSeparator(tb)"misc")
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "New Seed",
Icon: "new",
Tooltip: "Generate a new initial random seed to get different results. By default, Init re-establishes the same initial seed every time.",
Active: egui.ActiveAlways,
Func: func() {
ss.RndSeeds.NewSeeds()
},
})
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "README",
Icon: "file-markdown",
Tooltip: "Opens your browser on the README file that contains instructions for how to run this model.",
Active: egui.ActiveAlways,
Func: func() {
gi.OpenURL("https://github.com/emer/axon/blob/master/examples/deep_music/README.md")
},
////////////////////////////////////////////////
gi.NewSeparator(tb)
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "Reset RunLog",
Icon: "reset",
Tooltip: "Reset the accumulated log of all Runs, which are tagged with the ParamSet used",
Active: egui.ActiveAlways,
Func: func() {
ss.Logs.ResetLog(etime.Train, etime.Run)
ss.GUI.UpdatePlot(etime.Train, etime.Run)
},
})
////////////////////////////////////////////////
gi.NewSeparator(tb)
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "New Seed",
Icon: "new",
Tooltip: "Generate a new initial random seed to get different results. By default, Init re-establishes the same initial seed every time.",
Active: egui.ActiveAlways,
Func: func() {
ss.RndSeeds.NewSeeds()
},
})
ss.GUI.AddToolbarItem(tb, egui.ToolbarItem{Label: "README",
Icon: "file-markdown",
Tooltip: "Opens your browser on the README file that contains instructions for how to run this model.",
Active: egui.ActiveAlways,
Func: func() {
gi.OpenURL("https://github.com/emer/axon/blob/master/examples/deep_music/README.md")
},
})
})

ss.GUI.FinalizeGUI(false)
if ss.Config.Run.GPU {
ss.Net.ConfigGPUwithGUI(&ss.Context)
gi.SetQuitCleanFunc(func() {
ss.Net.GPU.Destroy()
})
}
return ss.GUI.Win
}

func (ss *Sim) RunGUI() {
ss.Init()
win := ss.ConfigGUI()
win.StartEventLoop()
ss.ConfigGUI()
ss.GUI.Body.NewWindow().Run().Wait()
}

func (ss *Sim) RunNoGUI() {
Expand Down
Loading

0 comments on commit 9848f83

Please sign in to comment.