Skip to content

Commit

Permalink
more renaming of core packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Apr 14, 2024
1 parent d2c953f commit 93bde93
Show file tree
Hide file tree
Showing 34 changed files with 526 additions and 527 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -39,7 +39,7 @@ See [python README](https://github.com/emer/leabra/blob/master/python/README.md)

* The system is fully usable from within Python -- see the [Python Wiki](https://github.com/emer/emergent/wiki/Python). This includes interoperating with PyTorch via [eTorch](https://github.com/emer/etorch), and [PsyNeuLink](https://princetonuniversity.github.io/PsyNeuLink/) to make Leabra models accessible in that framework, and vice-versa. Furthermore, interactive, IDE-level tools such as `Jupyter` and `nteract` can be used to interactively develop and analyze the models, etc.

* We are leveraging the [GoGi Gui](https://cogentcore.org/core/gi/v2) to provide interactive 2D and 3D GUI interfaces to models, capturing the essential functionality of the original C++ emergent interface, but in a much more a-la-carte fashion. We also use and support the [GoNum](https://github.com/gonum) framework for analyzing and plotting results within Go.
* We are leveraging the [Cogent Core GUI](https://cogentcore.org/core) to provide interactive 2D and 3D GUI interfaces to models, capturing the essential functionality of the original C++ emergent interface, but in a much more a-la-carte fashion. We also use and support the [GoNum](https://github.com/gonum) framework for analyzing and plotting results within Go.

# Design / Organization

Expand Down
22 changes: 11 additions & 11 deletions confusion/confusion.go
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
"math"

"cogentcore.org/core/gi"
"cogentcore.org/core/core"

Check failure on line 13 in confusion/confusion.go

View workflow job for this annotation

GitHub Actions / build

import "cogentcore.org/core/core" is a program, not an importable package
"github.com/emer/etable/v2/etensor"
"github.com/emer/etable/v2/simat"
)
Expand Down Expand Up @@ -200,34 +200,34 @@ func (cm *Matrix) ScoreMatrix() {
}

// SaveCSV saves Prob result to a CSV file, comma separated
func (cm *Matrix) SaveCSV(fname gi.Filename) {
func (cm *Matrix) SaveCSV(fname core.Filename) {
etensor.SaveCSV(&cm.Prob, fname, ',')
}

// OpenCSV opens Prob result from a CSV file, comma separated
func (cm *Matrix) OpenCSV(fname gi.Filename) {
func (cm *Matrix) OpenCSV(fname core.Filename) {
etensor.OpenCSV(&cm.Prob, fname, ',')
}

/*
var MatrixProps = ki.Props{
"ToolBar": ki.PropSlice{
{"SaveCSV", ki.Props{
var MatrixProps = tree.Props{
"ToolBar": tree.PropSlice{
{"SaveCSV", tree.Props{
"label": "Save CSV...",
"icon": "file-save",
"desc": "Save CSV-formatted confusion probabilities (Probs)",
"Args": ki.PropSlice{
{"CSV File Name", ki.Props{
"Args": tree.PropSlice{
{"CSV File Name", tree.Props{
"ext": ".csv",
}},
},
}},
{"OpenCSV", ki.Props{
{"OpenCSV", tree.Props{
"label": "Open CSV...",
"icon": "file-open",
"desc": "Open CSV-formatted confusion probabilities (Probs)",
"Args": ki.PropSlice{
{"Weights File Name", ki.Props{
"Args": tree.PropSlice{
{"Weights File Name", tree.Props{
"ext": ".csv",
}},
},
Expand Down
4 changes: 2 additions & 2 deletions econfig/README.md
Expand Up @@ -5,7 +5,7 @@ Docs: [GoDoc](https://pkg.go.dev/github.com/emer/emergent/econfig)
* Standard usage:
+ `cfg := &ss.Config`
+ `cfg.Defaults()` -- sets hard-coded defaults -- user should define and call this method first.
+ It is better to use the `def:` field tag however because it then shows in `-h` or `--help` usage and in the [GoGi](https://cogentcore.org/core/gi/v2) GUI. See [Default Tags](#def_default_tags) for how to specify def values for more complex types.
+ It is better to use the `default:` field tag however because it then shows in `-h` or `--help` usage and in the [Cogent Core](https://cogentcore.org/core) GUI. See [Default Tags](#def_default_tags) for how to specify def values for more complex types.
+ `econfig.Config(cfg, "config.toml")` -- sets config values according to the standard order, with given file name specifying the default config file name.

* Has support for nested `Include` paths, which are processed in the natural deepest-first order. The processed `Config` struct field will contain a list of all such files processed. There are two options for include file support:
Expand Down Expand Up @@ -50,7 +50,7 @@ Docs: [GoDoc](https://pkg.go.dev/github.com/emer/emergent/econfig)
"Prjn:Prjn.Learn.LRate.Base" = 0.05
```

* Field tag `def:"value"`, used in the [GoGi](https://cogentcore.org/core/gi/v2) GUI, sets the initial default value and is shown for the `-h` or `--help` usage info.
* Field tag `default:"value"`, used in the [Cogent Core](https://cogentcore.org/core) GUI, sets the initial default value and is shown for the `-h` or `--help` usage info.

* [kit](https://cogentcore.org/core/ki) registered "enum" `const` types, with names automatically parsed from string values (including bit flags). Must use the [goki stringer](https://github.com/goki/stringer) version to generate `FromString()` method, and register the type like this: `var KitTestEnum = kit.Enums.AddEnum(TestEnumN, kit.NotBitFlag, nil)` -- see [enum.go](enum.go) file for example.

Expand Down
28 changes: 14 additions & 14 deletions econfig/args.go
Expand Up @@ -13,8 +13,8 @@ import (
"reflect"
"strings"

"cogentcore.org/core/grows/tomls"
"cogentcore.org/core/laser"
"cogentcore.org/core/iox/tomlx"
"cogentcore.org/core/reflectx"
"github.com/emer/empi/v2/mpi"
"github.com/iancoleman/strcase"
)
Expand Down Expand Up @@ -92,7 +92,7 @@ func ParseArg(s string, args []string, allArgs map[string]reflect.Value, errNotF
return
}

isbool := laser.NonPtrValue(fval).Kind() == reflect.Bool
isbool := reflectx.NonPtrValue(fval).Kind() == reflect.Bool

var value string
switch {
Expand Down Expand Up @@ -134,20 +134,20 @@ func ParseArg(s string, args []string, allArgs map[string]reflect.Value, errNotF

// SetArgValue sets given arg name to given value, into settable reflect.Value
func SetArgValue(name string, fval reflect.Value, value string) error {
nptyp := laser.NonPtrType(fval.Type())
nptyp := reflectx.NonPtrType(fval.Type())
vk := nptyp.Kind()
switch {
// todo: enum
// case vk >= reflect.Int && vk <= reflect.Uint64 && kit.Enums.TypeRegistered(nptyp):
// return kit.Enums.SetAnyEnumValueFromString(fval, value)
case vk == reflect.Map:
mval := make(map[string]any)
err := tomls.ReadBytes(&mval, []byte("tmp="+value)) // use toml decoder
err := tomlx.ReadBytes(&mval, []byte("tmp="+value)) // use toml decoder
if err != nil {
mpi.Println(err)
return err
}
err = laser.CopyMapRobust(fval.Interface(), mval["tmp"])
err = reflectx.CopyMapRobust(fval.Interface(), mval["tmp"])
if err != nil {
mpi.Println(err)
err = fmt.Errorf("econfig.ParseArgs: not able to set map field from arg: %s val: %s", name, value)
Expand All @@ -156,20 +156,20 @@ func SetArgValue(name string, fval reflect.Value, value string) error {
}
case vk == reflect.Slice:
mval := make(map[string]any)
err := tomls.ReadBytes(&mval, []byte("tmp="+value)) // use toml decoder
err := tomlx.ReadBytes(&mval, []byte("tmp="+value)) // use toml decoder
if err != nil {
mpi.Println(err)
return err
}
err = laser.CopySliceRobust(fval.Interface(), mval["tmp"])
err = reflectx.CopySliceRobust(fval.Interface(), mval["tmp"])
if err != nil {
mpi.Println(err)
err = fmt.Errorf("econfig.ParseArgs: not able to set slice field from arg: %s val: %s", name, value)
mpi.Println(err)
return err
}
default:
err := laser.SetRobust(fval.Interface(), value) // overkill but whatever
err := reflectx.SetRobust(fval.Interface(), value) // overkill but whatever
if err != nil {
err := fmt.Errorf("econfig.ParseArgs: not able to set field from arg: %s val: %s", name, value)
mpi.Println(err)
Expand Down Expand Up @@ -202,19 +202,19 @@ func addAllCases(nm, path string, pval reflect.Value, allArgs map[string]reflect
// fieldArgNamesStruct returns map of all the different ways the field names
// can be specified as arg flags, mapping to the reflect.Value
func fieldArgNamesStruct(obj any, path string, nest bool, allArgs map[string]reflect.Value) {
if laser.AnyIsNil(obj) {
if reflectx.AnyIsNil(obj) {
return
}
ov := reflect.ValueOf(obj)
if ov.Kind() == reflect.Pointer && ov.IsNil() {
return
}
val := laser.NonPtrValue(ov)
val := reflectx.NonPtrValue(ov)
typ := val.Type()
for i := 0; i < typ.NumField(); i++ {
f := typ.Field(i)
fv := val.Field(i)
if laser.NonPtrType(f.Type).Kind() == reflect.Struct {
if reflectx.NonPtrType(f.Type).Kind() == reflect.Struct {
nwPath := f.Name
if path != "" {
nwPath = path + "." + nwPath
Expand All @@ -226,10 +226,10 @@ func fieldArgNamesStruct(obj any, path string, nest bool, allArgs map[string]ref
nwNest = true
}
}
fieldArgNamesStruct(laser.PtrValue(fv).Interface(), nwPath, nwNest, allArgs)
fieldArgNamesStruct(reflectx.PtrValue(fv).Interface(), nwPath, nwNest, allArgs)
continue
}
pval := laser.PtrValue(fv)
pval := reflectx.PtrValue(fv)
addAllCases(f.Name, path, pval, allArgs)
if f.Type.Kind() == reflect.Bool {
addAllCases("No"+f.Name, path, pval, allArgs)
Expand Down
4 changes: 2 additions & 2 deletions econfig/defaults.go
Expand Up @@ -4,10 +4,10 @@

package econfig

import "cogentcore.org/core/laser"
import "cogentcore.org/core/reflectx"

// SetFromDefaults sets Config values from field tag `def:` values.
// Parsing errors are automatically logged.
func SetFromDefaults(cfg any) error {
return laser.SetFromDefaultTags(cfg)
return reflectx.SetFromDefaultTags(cfg)
}
12 changes: 6 additions & 6 deletions econfig/include.go
Expand Up @@ -11,8 +11,8 @@ import (
"errors"
"reflect"

"cogentcore.org/core/grows/tomls"
"cogentcore.org/core/laser"
"cogentcore.org/core/iox/tomlx"
"cogentcore.org/core/reflectx"
)

// Includeser enables processing of Includes []string field with files to include in Config objects.
Expand All @@ -35,7 +35,7 @@ type Includer interface {
// Returns an error if any of the include files cannot be found on IncludePath.
// Does not alter cfg.
func IncludesStack(cfg Includeser) ([]string, error) {
clone := reflect.New(laser.NonPtrType(reflect.TypeOf(cfg))).Interface().(Includeser)
clone := reflect.New(reflectx.NonPtrType(reflect.TypeOf(cfg))).Interface().(Includeser)
*clone.IncludesPtr() = *cfg.IncludesPtr()
return includesStackImpl(clone, nil)
}
Expand All @@ -54,7 +54,7 @@ func includesStackImpl(clone Includeser, includes []string) ([]string, error) {
var errs []error
for _, inc := range incs {
*clone.IncludesPtr() = nil
err := tomls.OpenFromPaths(clone, inc, IncludePaths)
err := tomlx.OpenFromPaths(clone, inc, IncludePaths)
if err == nil {
includes, err = includesStackImpl(clone, includes)
if err != nil {
Expand All @@ -73,7 +73,7 @@ func includesStackImpl(clone Includeser, includes []string) ([]string, error) {
// Returns an error if any of the include files cannot be found on IncludePath.
// Does not alter cfg.
func IncludeStack(cfg Includer) ([]string, error) {
clone := reflect.New(laser.NonPtrType(reflect.TypeOf(cfg))).Interface().(Includer)
clone := reflect.New(reflectx.NonPtrType(reflect.TypeOf(cfg))).Interface().(Includer)
*clone.IncludePtr() = *cfg.IncludePtr()
return includeStackImpl(clone, nil)
}
Expand All @@ -88,7 +88,7 @@ func includeStackImpl(clone Includer, includes []string) ([]string, error) {
includes = append(includes, inc)
var errs []error
*clone.IncludePtr() = ""
err := tomls.OpenFromPaths(clone, inc, IncludePaths)
err := tomlx.OpenFromPaths(clone, inc, IncludePaths)
if err == nil {
includes, err = includeStackImpl(clone, includes)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions econfig/io.go
Expand Up @@ -8,7 +8,7 @@ import (
"io/fs"
"strings"

"cogentcore.org/core/grows/tomls"
"cogentcore.org/core/iox/tomlx"
"github.com/emer/empi/v2/mpi"
)

Expand All @@ -19,7 +19,7 @@ import (
// Is equivalent to Open if there are no Includes.
// Returns an error if any of the include files cannot be found on IncludePath.
func OpenWithIncludes(cfg any, file string) error {
err := tomls.OpenFromPaths(cfg, file, IncludePaths)
err := tomlx.OpenFromPaths(cfg, file, IncludePaths)
if err != nil {
return err
}
Expand All @@ -40,13 +40,13 @@ func OpenWithIncludes(cfg any, file string) error {
}
for i := ni - 1; i >= 0; i-- {
inc := incs[i]
err = tomls.OpenFromPaths(cfg, inc, IncludePaths)
err = tomlx.OpenFromPaths(cfg, inc, IncludePaths)
if err != nil {
mpi.Println(err)
}
}
// reopen original
tomls.OpenFromPaths(cfg, file, IncludePaths)
tomlx.OpenFromPaths(cfg, file, IncludePaths)
if hasIncludes {
*incsObj.IncludesPtr() = incs
} else {
Expand All @@ -58,10 +58,10 @@ func OpenWithIncludes(cfg any, file string) error {
// OpenFS reads config from given TOML file,
// using the fs.FS filesystem -- e.g., for embed files.
func OpenFS(cfg any, fsys fs.FS, file string) error {
return tomls.OpenFS(cfg, fsys, file)
return tomlx.OpenFS(cfg, fsys, file)
}

// Save writes TOML to given file.
func Save(cfg any, file string) error {
return tomls.Save(cfg, file)
return tomlx.Save(cfg, file)
}
10 changes: 5 additions & 5 deletions econfig/usage.go
Expand Up @@ -9,7 +9,7 @@ import (
"reflect"
"strings"

"cogentcore.org/core/laser"
"cogentcore.org/core/reflectx"
)

// Usage returns the usage string for args based on given Config object
Expand All @@ -28,17 +28,17 @@ func Usage(cfg any) string {

// usageStruct adds usage info to given strings.Builder
func usageStruct(obj any, path string, b *strings.Builder) {
typ := laser.NonPtrType(reflect.TypeOf(obj))
val := laser.NonPtrValue(reflect.ValueOf(obj))
typ := reflectx.NonPtrType(reflect.TypeOf(obj))
val := reflectx.NonPtrValue(reflect.ValueOf(obj))
for i := 0; i < typ.NumField(); i++ {
f := typ.Field(i)
fv := val.Field(i)
if laser.NonPtrType(f.Type).Kind() == reflect.Struct {
if reflectx.NonPtrType(f.Type).Kind() == reflect.Struct {
nwPath := f.Name
if path != "" {
nwPath = path + "." + nwPath
}
usageStruct(laser.PtrValue(fv).Interface(), nwPath, b)
usageStruct(reflectx.PtrValue(fv).Interface(), nwPath, b)
continue
}
nm := f.Name
Expand Down
8 changes: 4 additions & 4 deletions egui/README.md
Expand Up @@ -10,7 +10,7 @@ Here's the start of the main ConfigGUI method:

```Go
// ConfigGUI configures the Cogent Core GUI interface for this simulation.
func (ss *Sim) ConfigGUI() *gi.Window {
func (ss *Sim) ConfigGUI() *core.Window {
title := "Leabra Random Associator"
ss.GUI.MakeWindow(ss, "ra25", title, `This demonstrates a basic Leabra model. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
ss.GUI.CycleUpdateInterval = 10
Expand All @@ -25,7 +25,7 @@ func (ss *Sim) ConfigGUI() *gi.Window {
## Toolbar Items
The `ToolbarItem` class provides toolbar configuration options, taking the place of `gi.ActOpts` from existing code that operates directly at the `GoGi` level. The main differences are
The `ToolbarItem` class provides toolbar configuration options, taking the place of `core.ActOpts` from existing code that operates directly at the `GoGi` level. The main differences are
* The standard `UpdateFunc` options of either making the action active or inactive while the sim is running are now handled using `Active: equi.ActiveStopped` or `egui.ActiveRunning` or `egui.ActiveAlways`
Expand Down Expand Up @@ -79,8 +79,8 @@ Here's an `ActiveRunning` case:
## Spike Rasters
```Go
stb := ss.GUI.TabView.AddNewTab(gi.KiT_Layout, "Spike Rasters").(*gi.Layout)
stb.Lay = gi.LayoutVert
stb := ss.GUI.TabView.AddNewTab(core.KiT_Layout, "Spike Rasters").(*core.Layout)
stb.Lay = core.LayoutVert
stb.SetStretchMax()
for _, lnm := range ss.Stats.Rasters {
sr := ss.Stats.F32Tensor("Raster_" + lnm)
Expand Down
8 changes: 4 additions & 4 deletions egui/grids.go
Expand Up @@ -5,7 +5,7 @@
package egui

import (
"cogentcore.org/core/gi"
"cogentcore.org/core/core"
"github.com/emer/emergent/v2/actrf"
"github.com/emer/etable/v2/etensor"
"github.com/emer/etable/v2/etview"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (gui *GUI) SetGrid(name string, tg *etview.TensorGrid) {

// ConfigRasterGrid configures a raster grid for given layer name.
// Uses Raster_laynm and given Tensor that has the raster data.
func (gui *GUI) ConfigRasterGrid(lay *gi.Layout, laynm string, rast *etensor.Float32) *etview.TensorGrid {
func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *etensor.Float32) *etview.TensorGrid {
tg := gui.Grid(laynm)
tg.SetName(laynm + "Raster")
gi.NewLabel(lay, laynm, laynm+":")
core.NewLabel(lay, laynm, laynm+":")
lay.AddChild(tg)
gi.NewSpace(lay, laynm+"_spc")
core.NewSpace(lay, laynm+"_spc")
rast.SetMetaData("grid-fill", "1")
tg.SetTensor(rast)
return tg
Expand Down

0 comments on commit 93bde93

Please sign in to comment.