egui

package
v1.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2022 License: BSD-3-Clause Imports: 21 Imported by: 31

README

Docs: GoDoc

egui handles all the GUI elements for a typical simulation, reducing boilerplate code in models.

The ra25 example has a fully updated implementation of this new GUI infrastructure.

Examples

Here's the start of the main ConfigGui method:

// ConfigGui configures the GoGi gui interface for this simulation,
func (ss *Sim) ConfigGui() *gi.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
	ss.GUI.NetView.SetNet(ss.Net)

    // optionally reconfigure the netview:
	ss.GUI.NetView.Scene().Camera.Pose.Pos.Set(0, 1, 2.75) 
	ss.GUI.NetView.Scene().Camera.LookAt(mat32.Vec3{0, 0, 0}, mat32.Vec3{0, 1, 0}) 
	ss.GUI.AddPlots(title, &ss.Logs) // automatically adds all configured plots

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 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

  • The action function is just a simple Func: func() { with no args -- use context capture of closures to access any relevant state.

  • Use ss.GUI.UpdateWindow() inside any action function instead of vp.SetNeedsFullRender()

Here is a typical item:

    ss.GUI.AddToolbarItem(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()
        },
    })

For actions that take any significant amount of time, call the function in a separate routine using go, and use the GUI based variables:

    ss.GUI.AddToolbarItem(egui.ToolbarItem{Label: "Train",
        Icon:    "run",
        Tooltip: "Starts the network training, picking up from wherever it may have left off.  If not stopped, training will complete the specified number of Runs through the full number of Epochs of training, with testing automatically occuring at the specified interval.",
        Active:  egui.ActiveStopped,
        Func: func() {
            if !ss.GUI.IsRunning {
                ss.GUI.IsRunning = true
                ss.GUI.ToolBar.UpdateActions()
                go ss.Train()
            }
        },
    })

Here's an ActiveRunning case:

    ss.GUI.AddToolbarItem(egui.ToolbarItem{Label: "Stop",
        Icon:    "stop",
        Tooltip: "Interrupts running.  Hitting Train again will pick back up where it left off.",
        Active:  egui.ActiveRunning,
        Func: func() {
            ss.Stop()
        },
    })

Spike Rasters

	stb := ss.GUI.TabView.AddNewTab(gi.KiT_Layout, "Spike Rasters").(*gi.Layout)
	stb.Lay = gi.LayoutVert
	stb.SetStretchMax()
	for _, lnm := range ss.Stats.Rasters {
		sr := ss.Stats.F32Tensor("Raster_" + lnm)
		ss.GUI.ConfigRasterGrid(stb, lnm, sr)
	}

Tensor Grid (e.g., of an Image)

	tg := ss.GUI.TabView.AddNewTab(etview.KiT_TensorGrid, "Image").(*etview.TensorGrid)
	tg.SetStretchMax()
	ss.GUI.SetGrid("Image", tg)
	tg.SetTensor(&ss.TrainEnv.Img.Tsr)

Activation-based Receptive Fields

	ss.GUI.AddActRFGridTabs(&ss.Stats.ActRFs)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KiT_ToolGhosting = kit.Enums.AddEnum(ToolGhostingN, kit.BitFlag, nil)

Functions

func AddDefaultGUICallbacks added in v1.2.4

func AddDefaultGUICallbacks(manager *looper.Manager, gui *GUI)

func PositionNetworkLayersAutomatically added in v1.2.4

func PositionNetworkLayersAutomatically(net emer.Network, numSettlingIterations int)

PositionNetworkLayersAutomatically tries to find a configuration for the network layers where they're close together, but not overlapping. It tries to put connected layers closer together, input layers near the bottom, and target layers near the top. It uses a random walk algorithm that randomly permutes the network and only keeps permutations if they improve the network's overall configuration score. numSettlingIterations is the number of random moves it tries for each layer. Larger values will generally get better results but compute time grows linearly.

Types

type GUI

type GUI struct {
	NetViewText         string `desc:"text to display at bottom of the NetView -- has relevant network state"`
	CycleUpdateInterval int    `desc:"how many cycles between updates of cycle-level plots"`
	Active              bool   `view:"-" desc:"true if the GUI is configured and running"`
	IsRunning           bool   `view:"-" desc:"true if sim is running"`
	StopNow             bool   `view:"-" desc:"flag to stop running"`

	Plots map[etime.ScopeKey]*eplot.Plot2D `desc:"plots by scope"`
	Grids map[string]*etview.TensorGrid    `desc:"tensor grid views by name -- used e.g., for Rasters or ActRFs -- use Grid(name) to access"`

	NetView    *netview.NetView `view:"-" desc:"the network viewer"`
	NetData    *netview.NetData `view:"-" desc:"net data for recording in nogui mode, if !nil"`
	ToolBar    *gi.ToolBar      `view:"-" desc:"the master toolbar"`
	StructView *giv.StructView  `view:"-" desc:"displays Sim fields on left"`
	TabView    *gi.TabView      `view:"-" desc:"tabs for different view elements: plots, rasters"`
	Win        *gi.Window       `view:"-" desc:"main GUI gui.Window"`
	ViewPort   *gi.Viewport2D   `view:"-" desc:"main viewport for Window"`
}

GUI manages all standard elements of a simulation Graphical User Interface

func (*GUI) AddActRFGridTabs added in v1.1.56

func (gui *GUI) AddActRFGridTabs(arfs *actrf.RFs)

AddActRFGridTabs adds tabs for each of the ActRFs.

func (*GUI) AddLooperCtrl added in v1.2.1

func (gui *GUI) AddLooperCtrl(loops *looper.Manager, modes []etime.Modes)

AddLooperCtrl adds toolbar control for looper.Stack with Run, Step controls.

func (*GUI) AddNetView added in v1.2.1

func (gui *GUI) AddNetView(tabName string) *netview.NetView

AddNetView adds NetView in tab with given name

func (*GUI) AddPlots

func (gui *GUI) AddPlots(title string, lg *elog.Logs)

AddPlots adds plots based on the unique tables we have, currently assumes they should always be plotted

func (*GUI) AddToolbarItem

func (gui *GUI) AddToolbarItem(item ToolbarItem)

AddToolbarItem adds a toolbar item but also checks when it be active in the UI

func (*GUI) ConfigRasterGrid

func (gui *GUI) ConfigRasterGrid(lay *gi.Layout, laynm string, rast *etensor.Float32) *etview.TensorGrid

ConfigRasterGrid configures a raster grid for given layer name. Uses Raster_laynm and given Tensor that has the raster data.

func (*GUI) FinalizeGUI

func (gui *GUI) FinalizeGUI(closePrompt bool)

FinalizeGUI wraps the end functionality of the GUI

func (*GUI) Grid added in v1.1.56

func (gui *GUI) Grid(name string) *etview.TensorGrid

Grid gets tensor grid view of given name, creating if not yet made

func (*GUI) InitNetData added in v1.1.56

func (gui *GUI) InitNetData(net emer.Network, nrecs int)

InitNetData initializes the NetData object to record NetView data when the GUI is not active (located in egui package because of the NetViewText that is also recorded)

func (*GUI) MakeWindow

func (gui *GUI) MakeWindow(sim interface{}, appname, title, about string)

MakeWindow specifies default window settings that are largely used in all windwos

func (*GUI) NetDataRecord added in v1.1.56

func (gui *GUI) NetDataRecord()

NetDataRecord records current netview data if InitNetData has been called and NetData exists.

func (*GUI) Plot

func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *eplot.Plot2D

Plot returns plot for mode, time scope

func (*GUI) PlotScope

func (gui *GUI) PlotScope(scope etime.ScopeKey) *eplot.Plot2D

PlotScope returns plot for given scope

func (*GUI) SaveActRFGrid added in v1.1.56

func (gui *GUI) SaveActRFGrid(tg *etview.TensorGrid, name string)

SaveActRFGrid stores the given TensorGrid in Grids under given name, and configures the grid view for ActRF viewing.

func (*GUI) SaveNetData added in v1.1.56

func (gui *GUI) SaveNetData(extra string)

SaveNetData saves NetData NetView data (if !nil) to a file named by the network name plus _extra name plus ".netdata.gz"

func (*GUI) SetGrid added in v1.1.56

func (gui *GUI) SetGrid(name string, tg *etview.TensorGrid)

SetGrid sets tensor grid view to given name

func (*GUI) SetPlot added in v1.1.56

func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *eplot.Plot2D)

SetPlot stores given plot in Plots map

func (*GUI) Stopped

func (gui *GUI) Stopped()

Stopped is called when a run method stops running -- updates the IsRunning flag and toolbar

func (*GUI) UpdateCyclePlot

func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *eplot.Plot2D

UpdateCyclePlot updates cycle plot for given mode. only updates every CycleUpdateInterval

func (*GUI) UpdateNetView

func (gui *GUI) UpdateNetView()

UpdateNetView updates the gui visualization of the network. Set the NetViewText field prior to updating

func (*GUI) UpdateNetViewCycle added in v1.2.1

func (gui *GUI) UpdateNetViewCycle(time etime.Times, cyc int)

UpdateNetViewCycle updates the gui visualization of the network at given time scale relative to given cycle. For all times longer than cycle intervals (ThetaCycle and above), it returns. Set the NetViewText field prior to updating

func (*GUI) UpdatePlot

func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *eplot.Plot2D

UpdatePlot updates plot for given mode, time scope

func (*GUI) UpdatePlotScope

func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *eplot.Plot2D

UpdatePlotScope updates plot at given scope

func (*GUI) UpdateWindow

func (gui *GUI) UpdateWindow()

UpdateWindow renders the viewport associated with the main window

func (*GUI) ViewActRFs added in v1.1.56

func (gui *GUI) ViewActRFs(atf *actrf.RFs)

ViewActRFs displays act rfs into tensor Grid views previously configured

type ToolGhosting

type ToolGhosting int32

ToolGhosting the mode enum

const (
	ActiveStopped ToolGhosting = iota

	ActiveRunning

	ActiveAlways

	ToolGhostingN
)

The evaluation modes for when a tool bar can be clicked

func (ToolGhosting) MarshalJSON

func (ev ToolGhosting) MarshalJSON() ([]byte, error)

func (*ToolGhosting) UnmarshalJSON

func (ev *ToolGhosting) UnmarshalJSON(b []byte) error

type ToolbarItem

type ToolbarItem struct {
	Label   string
	Icon    string
	Tooltip string
	Active  ToolGhosting
	Func    func()
}

ToolbarItem holds the configuration values for a toolbar item

type UserInterface added in v1.2.4

type UserInterface struct {
	Looper        *looper.Manager `desc:"The loop structure informs what buttons should be put in the GUI, and when logging should occur."`
	Network       emer.Network    `desc:"The Network model can be rendered in the GUI, and is used for logging."`
	Logs          *elog.Logs      `desc:"A pointer to a Logs object is needed if logging is to be configured."`
	Stats         *estats.Stats   `desc:"Stats may be filled out during logging."`
	GUI           *GUI            `desc:"More directly handles graphical elements."`
	AppName       string          `desc:"Displayed in GUI."`
	AppAbout      string          `desc:"Displayed in GUI."`
	AppTitle      string          `desc:"Displayed in GUI."`
	StructForView interface{}     `desc:"This might be Sim or any other object you want to display to the user in the GUI."`

	// Callbacks
	InitCallback              func()                             `desc:"If set, the GUI will contain an initialization button to call it."`
	AddNetworkLoggingCallback func(userInterface *UserInterface) `` /* 197-byte string literal not displayed */
	// contains filtered or unexported fields
}

UserInterface tries to make it easier to set up the user interface for a model. It can automatically add logging and configure a GUI all based on the configuration parameters it contains. It can run the model either with a GUI or on the command line.

func (*UserInterface) AddDefaultLogging added in v1.2.4

func (ui *UserInterface) AddDefaultLogging()

AddDefaultLogging adds log items and looper callbacks for logging. You will need to supply a AddNetworkLoggingCallback function that actually adds the log items. I recommend you use axon.AddCommonLogItemsForOutputLayers if you are using an axon network. This function is external because it needs to import axon. Hopefully you find that it adds the logging you need, or you can craft your own function like this:

ui.Logs.AddItem(&elog.Item{
	Name:  "MyLogName",
	Type:  etensor.FLOAT32,
	Plot:  elog.DTrue,
	Write: elog.WriteMap{etime.Scope(etime.Train, etime.Trial): func(ctx *elog.Context) {
		ctx.SetFloat32(myLoggingFunction())
	}}})

func (*UserInterface) AddServerButton added in v1.2.4

func (ui *UserInterface) AddServerButton(serverRunFunc func())

AddServerButton adds a button to start a server based on some callback. This function is only necessary if you want the network to exist in a separate thread, and you want the agent to provide a server that serves intelligent actions. It adds a button to start the server.

func (*UserInterface) CreateAndRunGui added in v1.2.4

func (ui *UserInterface) CreateAndRunGui()

CreateAndRunGui creates a GUI, with which the user can control the application. It will loop forever.

func (*UserInterface) CreateAndRunGuiWithAdditionalConfig added in v1.2.4

func (ui *UserInterface) CreateAndRunGuiWithAdditionalConfig(config func())

CreateAndRunGuiWithAdditionalConfig allows you to specify additional configuration that occurs before the GUI runs.

func (*UserInterface) RunWithoutGui added in v1.2.4

func (ui *UserInterface) RunWithoutGui()

RunWithoutGui runs the model without any GUI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL