Skip to content

Commit

Permalink
econfig feature complete and tested -- now testing on ra25 case
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jul 3, 2023
1 parent 5745323 commit 94832b2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
7 changes: 6 additions & 1 deletion econfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Here's a standard `Config` struct, corresponding to the `AddStd` args from `ecmd
```Go
// Config is a standard Sim config -- use as a starting point.
// don't forget to update defaults, delete unused fields, etc.
typeConfig struct {
type Config struct {
Includes []string `desc:"specify include files here, and after configuration, it contains list of include files added"`
GUI bool `def:"true" desc:"open the GUI -- does not automatically run -- if false, then runs automatically and quits"`
GPU bool `desc:"use the GPU for computation"`
Expand All @@ -64,6 +64,8 @@ typeConfig struct {
Epochs int `def:"100" desc:"total number of epochs per run"`
NTrials int `def:"128" desc:"total number of trials per epoch. Should be an even multiple of NData."`
NData int `def:"16" desc:"number of data-parallel items to process in parallel per trial -- works (and is significantly faster) for both CPU and GPU. Results in an effective mini-batch of learning."`
TestInterval int `def:"5" desc:"how often to run through all the test patterns, in terms of training epochs -- can use 0 or -1 for no testing"`
PCAInterval int `def:"5" desc:"how frequently (in epochs) to compute PCA on hidden representations to measure variance?"`
SaveWts bool `desc:"if true, save final weights after each run"`
EpochLog bool `def:"true" desc:"if true, save train epoch log to file, as .epc.tsv typically"`
RunLog bool `def:"true" desc:"if true, save run log to file, as .run.tsv typically"`
Expand All @@ -72,6 +74,9 @@ typeConfig struct {
TestTrialLog bool `def:"false" desc:"if true, save testing trial log to file, as .tst_trl.tsv typically. May be large."`
NetData bool `desc:"if true, save network activation etc data from testing trials, for later viewing in netview"`
}

func (cfg *Config) IncludesPtr() *[]string { return &cfg.Includes }

```

# Key design considerations
Expand Down
5 changes: 2 additions & 3 deletions econfig/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package econfig
import (
"fmt"
"log"
"os"
"reflect"
"strings"

Expand All @@ -26,8 +25,8 @@ import (
// must refer to fields in the config, so any that fail to match trigger
// an error. Errors can also result from parsing.
// Errors are automatically logged because these are user-facing.
func SetFromArgs(cfg any) (leftovers []string, err error) {
leftovers, err = parseArgs(cfg, os.Args[1:])
func SetFromArgs(cfg any, args []string) (leftovers []string, err error) {
leftovers, err = parseArgs(cfg, args)
if err != nil {
fmt.Println(Usage(cfg))
}
Expand Down
2 changes: 1 addition & 1 deletion econfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Config(cfg any, defaultFile string) ([]string, error) {
if err != nil {
errs = append(errs, err)
}
args, err := SetFromArgs(cfg)
args, err := SetFromArgs(cfg, flag.Args())
if err != nil {
errs = append(errs, err)
}
Expand Down
2 changes: 1 addition & 1 deletion econfig/econfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestArgsPrint(t *testing.T) {
func TestArgs(t *testing.T) {
cfg := &TestConfig{}
SetFromDefaults(cfg)
//
// note: cannot use "-Includes=testcfg.toml",
args := []string{"-save-wts", "-nogui", "-no-epoch-log", "--NoRunLog", "--runs=5", "--run", "1", "--TAG", "nice", "--PatParams.Sparseness=0.1", "--Network", "{'.PFCLayer:Layer.Inhib.Gi' = '2.4', '#VSPatchPrjn:Prjn.Learn.LRate' = '0.01'}", "-Enum=TestValue2", "leftover1", "leftover2"}
leftovers, err := parseArgs(cfg, args)
if err != nil {
Expand Down
48 changes: 48 additions & 0 deletions params/applymap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package params

import (
"fmt"
"strings"
)

// ApplyMap applies given map[string]interface{} values, where the map keys
// are Selector:Path and the value is the value to apply.
// returns true if any Sel's applied, and error if any errors.
// If setMsg is true, then a message is printed to confirm each parameter that is set.
// It always prints a message if a parameter fails to be set, and returns an error.
func ApplyMap(obj interface{}, vals map[string]interface{}, setMsg bool) (bool, error) {
applied := false
var rerr error
for k, v := range vals {
fld := strings.Split(k, ":")
if len(fld) != 2 {
rerr = fmt.Errorf("ApplyMap: map key value must be colon-separated Selector:Path, not: %s", k)
continue
}
vstr, ok := v.(string)
if !ok {
rerr = fmt.Errorf("ApplyMap: map value must be a string type")
continue
}

sl := &Sel{Sel: fld[0], SetName: "ApplyMap"}
sl.Params = make(Params)
sl.Params[fld[1]] = vstr
app, err := sl.Apply(obj, setMsg)
if app {
applied = true
sl.NMatch++
if hist, ok := obj.(History); ok {
hist.ParamsApplied(sl)
}
}
if err != nil {
rerr = err
}
}
return applied, rerr
}

0 comments on commit 94832b2

Please sign in to comment.