params

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: BSD-3-Clause Imports: 15 Imported by: 156

README

GoDoc

See Wiki Params page for detailed docs.

Package params provides general-purpose parameter management functionality for organizing multiple sets of parameters efficiently, and basic IO for saving / loading from JSON files and generating Go code to embed into applications, and a basic GUI for viewing and editing.

The main overall unit that is generally operated upon at run-time is the params.Set, which is a collection of params.Sheet's (akin to CSS style sheets) that constitute a coherent set of parameters.

A good strategy is to have a "Base" Set that has all the best parameters so far, and then other sets can modify specific params relative to that one. Order of application is critical, as subsequent params applications overwrite earlier ones, and the typical order is:

  • Defaults() method called that establishes the hard-coded default parameters.
  • Then apply "Base" params.Set for any changes relative to those.
  • Then optionally apply one or more additional params.Set's with current experimental parameters.

Critically, all of this is entirely up to the particular model program(s) to determine and control -- this package just provides the basic data structures for holding all of the parameters, and the IO / and Apply infrastructure.

Within a params.Set, multiple different params.Sheet's can be organized, with each CSS-style sheet achieving a relatively complete parameter styling of a given element of the overal model, e.g., "Network", "Sim", "Env". Or Network could be further broken down into "Learn" vs. "Act" etc, or according to different brain areas ("Hippo", "PFC", "BG", etc). Again, this is entirely at the discretion of the modeler and must be performed under explict program control, especially because order is so critical.

Each params.Sheet consists of a collection of params.Sel elements which actually finally contain the parameters. The Sel field specifies a CSS-style selector determining over what scope the parameters should be applied:

  • Type (no prefix) = name of a type -- anything having this type name will get these params.

  • .Class = anything with a given class label (each object can have multiple Class labels and thus receive multiple parameter settings, but again, order matters!)

  • #Name = a specific named object.

The order of application within a given Sheet is also critical -- typically put the most general Type params first, then .Class, then the most specific #Name cases, to achieve within a given Sheet the same logic of establishing Base params for all types and then more specific overrides for special cases (e.g., an overall learning rate that appplies across all projections, but maybe a faster or slower one for a .Class or specific #Name'd projection).

There is a params.Styler interface with methods that any Go type can implement to provide these different labels. The emer.Network, .Layer, and .Prjn interfaces each implement this interface.

Otherwise, the Apply method will just directly apply params to a given struct type if it does not implement the Styler interface.

Parameter values are limited to float64 values only. These can be specified using "enum" style const integer values, and can be applied to any numeric type (they will be automatically converted), but internally this is the only parameter value type, which greatly simplifies the overall interface, and handles the vast majority of use-cases (especially because named options are just integers and can be set as such).

Finally, there are methods to show where params.Set's set the same parameter differently, and to compare with the default settings on a given object type using go struct field tags of the form def:"val1[,val2...]".

Documentation

Overview

Package params provides general-purpose parameter management functionality for organizing multiple sets of parameters efficiently, and basic IO for saving / loading from JSON files and generating Go code to embed into applications, and a basic GUI for viewing and editing.

The main overall unit that is generally operated upon at run-time is the params.Set, which is a collection of params.Sheet's (akin to CSS style sheets) that constitute a coherent set of parameters.

A good strategy is to have a "Base" Set that has all the best parameters so far, and then other sets can modify specific params relative to that one. Order of application is critical, as subsequent params applications overwrite earlier ones, and the typical order is:

  • Defaults() method called that establishes the hard-coded default parameters.
  • Then apply "Base" params.Set for any changes relative to those.
  • Then optionally apply one or more additional params.Set's with current experimental parameters.

Critically, all of this is entirely up to the particular model program(s) to determine and control -- this package just provides the basic data structures for holding all of the parameters, and the IO / and Apply infrastructure.

Within a params.Set, multiple different params.Sheet's can be organized, with each CSS-style sheet achieving a relatively complete parameter styling of a given element of the overal model, e.g., "Network", "Sim", "Env". Or Network could be further broken down into "Learn" vs. "Act" etc, or according to different brain areas ("Hippo", "PFC", "BG", etc). Again, this is entirely at the discretion of the modeler and must be performed under explict program control, especially because order is so critical.

Each params.Sheet consists of a collection of params.Sel elements which actually finally contain the parameters. The Sel field specifies a CSS-style selector determining over what scope the parameters should be applied:

* Type = name of a type -- anything having this type name will get these params.

* .Class = anything with a given class label (each object can have multiple Class labels and thus receive multiple parameter settings, but again, order matters!)

* #Name = a specific named object.

The order of application within a given Sheet is also critical -- typically put the most general Type params first, then .Class, then the most specific #Name cases, to achieve within a given Sheet the same logic of establishing Base params for all types and then more specific overrides for special cases (e.g., an overall learning rate that appplies across all projections, but maybe a faster or slower one for a .Class or specific #Name'd projection).

There is a params.Styler interface with methods that any Go type can implement to provide these different labels. The emer.Network, .Layer, and .Prjn interfaces each implement this interface.

Otherwise, the Apply method will just directly apply params to a given struct type if it does not implement the Styler interface.

Parameter values are limited to float64 values *only*. These can be specified using "enum" style const integer values, and can be applied to any numeric type (they will be automatically converted), but internally this is the only parameter value type, which greatly simplifies the overall interface, and handles the vast majority of use-cases (especially because named options are just integers and can be set as such).

Finally, there are methods to show where params.Set's set the same parameter differently, and to compare with the default settings on a given object type using go struct field tags of the form def:"val1[,val2...]".

Index

Constants

This section is empty.

Variables

View Source
var KiT_Params = kit.Types.AddType(&Params{}, ParamsProps)
View Source
var KiT_Sel = kit.Types.AddType(&Sel{}, SelProps)
View Source
var KiT_Set = kit.Types.AddType(&Set{}, SetProps)
View Source
var KiT_Sets = kit.Types.AddType(&Sets{}, SetsProps)
View Source
var KiT_Sheet = kit.Types.AddType(&Sheet{}, SheetProps)
View Source
var KiT_Sheets = kit.Types.AddType(&Sheets{}, SheetsProps)
View Source
var ParamsProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SaveJSON", ki.Props{
			"label": "Save As...",
			"desc":  "save to JSON formatted file",
			"icon":  "file-save",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"OpenJSON", ki.Props{
			"label": "Open...",
			"desc":  "open from JSON formatted file",
			"icon":  "file-open",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"sep-gocode", ki.BlankProp{}},
		{"SaveGoCode", ki.Props{
			"label": "Save Code As...",
			"desc":  "save to Go-formatted initializer code in file",
			"icon":  "go",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".go",
				}},
			},
		}},
		{"StringGoCode", ki.Props{
			"label":       "Show Code",
			"desc":        "shows the Go-formatted initializer code, can be copy / pasted into program",
			"icon":        "go",
			"show-return": true,
		}},
	},
}
View Source
var SelProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SaveJSON", ki.Props{
			"label": "Save As...",
			"desc":  "save to JSON formatted file",
			"icon":  "file-save",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"OpenJSON", ki.Props{
			"label": "Open...",
			"desc":  "open from JSON formatted file",
			"icon":  "file-open",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"sep-gocode", ki.BlankProp{}},
		{"SaveGoCode", ki.Props{
			"label": "Save Code As...",
			"desc":  "save to Go-formatted initializer code in file",
			"icon":  "go",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".go",
				}},
			},
		}},
		{"StringGoCode", ki.Props{
			"label":       "Show Code",
			"desc":        "shows the Go-formatted initializer code, can be copy / pasted into program",
			"icon":        "go",
			"show-return": true,
		}},
	},
}
View Source
var SetProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SaveJSON", ki.Props{
			"label": "Save As...",
			"desc":  "save to JSON formatted file",
			"icon":  "file-save",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"OpenJSON", ki.Props{
			"label": "Open...",
			"desc":  "open from JSON formatted file",
			"icon":  "file-open",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"sep-gocode", ki.BlankProp{}},
		{"SaveGoCode", ki.Props{
			"label": "Save Code As...",
			"desc":  "save to Go-formatted initializer code in file",
			"icon":  "go",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".go",
				}},
			},
		}},
		{"StringGoCode", ki.Props{
			"label":       "Show Code",
			"desc":        "shows the Go-formatted initializer code, can be copy / pasted into program",
			"icon":        "go",
			"show-return": true,
		}},
		{"sep-diffs", ki.BlankProp{}},
		{"DiffsWithin", ki.Props{
			"desc":        "reports where the same param path is being set to different values within this set (both within the same Sheet and betwen sheets)",
			"icon":        "search",
			"show-return": true,
		}},
	},
}
View Source
var SetsProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SaveJSON", ki.Props{
			"label": "Save As...",
			"desc":  "save to JSON formatted file",
			"icon":  "file-save",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"OpenJSON", ki.Props{
			"label": "Open...",
			"desc":  "open from JSON formatted file",
			"icon":  "file-open",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"sep-gocode", ki.BlankProp{}},
		{"SaveGoCode", ki.Props{
			"label": "Save Code As...",
			"desc":  "save to Go-formatted initializer code in file",
			"icon":  "go",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".go",
				}},
			},
		}},
		{"StringGoCode", ki.Props{
			"label":       "Show Code",
			"desc":        "shows the Go-formatted initializer code, can be copy / pasted into program",
			"icon":        "go",
			"show-return": true,
		}},
		{"sep-diffs", ki.BlankProp{}},
		{"DiffsAll", ki.Props{
			"desc":        "between all sets, reports where the same param path is being set to different values",
			"icon":        "search",
			"show-return": true,
		}},
		{"DiffsFirst", ki.Props{
			"desc":        "between first set (e.g., the Base set) and rest of sets, reports where the same param path is being set to different values",
			"icon":        "search",
			"show-return": true,
		}},
		{"DiffsWithin", ki.Props{
			"desc":        "reports all the cases where the same param path is being set to different values within different sheets in given set",
			"icon":        "search",
			"show-return": true,
			"Args": ki.PropSlice{
				{"Set Name", ki.Props{}},
			},
		}},
	},
}
View Source
var SheetProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SaveJSON", ki.Props{
			"label": "Save As...",
			"desc":  "save to JSON formatted file",
			"icon":  "file-save",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"OpenJSON", ki.Props{
			"label": "Open...",
			"desc":  "open from JSON formatted file",
			"icon":  "file-open",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"sep-gocode", ki.BlankProp{}},
		{"SaveGoCode", ki.Props{
			"label": "Save Code As...",
			"desc":  "save to Go-formatted initializer code in file",
			"icon":  "go",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".go",
				}},
			},
		}},
		{"StringGoCode", ki.Props{
			"label":       "Show Code",
			"desc":        "shows the Go-formatted initializer code, can be copy / pasted into program",
			"icon":        "go",
			"show-return": true,
		}},
	},
}
View Source
var SheetsProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SaveJSON", ki.Props{
			"label": "Save As...",
			"desc":  "save to JSON formatted file",
			"icon":  "file-save",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"OpenJSON", ki.Props{
			"label": "Open...",
			"desc":  "open from JSON formatted file",
			"icon":  "file-open",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".params",
				}},
			},
		}},
		{"sep-gocode", ki.BlankProp{}},
		{"SaveGoCode", ki.Props{
			"label": "Save Code As...",
			"desc":  "save to Go-formatted initializer code in file",
			"icon":  "go",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"ext": ".go",
				}},
			},
		}},
		{"StringGoCode", ki.Props{
			"label":       "Show Code",
			"desc":        "shows the Go-formatted initializer code, can be copy / pasted into program",
			"icon":        "go",
			"show-return": true,
		}},
		{"sep-diffs", ki.BlankProp{}},
		{"DiffsWithin", ki.Props{
			"desc":        "reports where the same param path is being set to different values within this set (both within the same Sheet and betwen sheets)",
			"icon":        "search",
			"show-return": true,
		}},
	},
}

Functions

func ClassMatch

func ClassMatch(sel, cls string) bool

ClassMatch returns true if given class names -- handles space-separated multiple class names

func FindParam

func FindParam(val reflect.Value, path string) (reflect.Value, error)

FindParam parses the path and recursively tries to find the parameter pointed to by the path (dot-delimited field names). Returns error if not found, and always also emits error messages -- the target type should already have been identified and this should only be called when there is an expectation of the path working.

func GetParam

func GetParam(obj interface{}, path string) (float64, error)

GetParam gets parameter value at given path on given object. converts target type to float64. returns error if path not found or target is not a numeric type (always logged).

func SelMatch

func SelMatch(sel string, name, cls, styp, gotyp string) bool

SelMatch returns true if Sel selector matches the target object properties

func SetParam

func SetParam(obj interface{}, path string, val string) error

SetParam sets parameter at given path on given object to given value converts the string param val as appropriate for target type. returns error if path not found or cannot set (always logged).

func WriteGoPrelude

func WriteGoPrelude(w io.Writer, varNm string)

WriteGoPrelude writes the start of a go file in package main that starts a variable assignment to given variable -- for start of SaveGoCode methods.

Types

type Params

type Params map[string]string

Params is a name-value map for parameter values that can be applied to any numeric type in any object. The name must be a dot-separated path to a specific parameter, e.g., Prjn.Learn.Lrate The first part of the path is the overall target object type, e.g., "Prjn" or "Layer", which is used for determining if the parameter applies to a given object type.

All of the params in one map must apply to the same target type because only the first item in the map (which could be any due to order randomization) is used for checking the type of the target. Also, they all fall within the same Sel selector scope which is used to determine what specific objects to apply the parameters to.

func (*Params) Apply

func (pr *Params) Apply(obj interface{}, setMsg bool) error

Apply applies all parameter values to given object. Object must already be the appropriate target type based on the first element of the path (see TargetType method). If setMsg is true, then it will log a confirmation that the parameter was set (it always prints an error message if it fails to set the parameter at given path, and returns error if so).

func (*Params) Diffs

func (pr *Params) Diffs(op *Params, nm1, nm2 string) string

Diffs returns comparison between all params in this params versus the other params, where the path is the same but the parameter value is different. Nm1 is the name / id of the 'this' Params, and nm2 is for the other params.

func (*Params) OpenJSON

func (pr *Params) OpenJSON(filename gi.FileName) error

OpenJSON opens params from a JSON-formatted file.

func (*Params) ParamByName added in v1.0.0

func (pr *Params) ParamByName(name string) string

ParamByName returns given parameter by name (just does the map access) Returns "" if not found -- use Try version for error

func (*Params) ParamByNameTry added in v1.0.0

func (pr *Params) ParamByNameTry(name string) (string, error)

ParamByNameTry returns given parameter, by name. Returns error if not found.

func (*Params) Path

func (pr *Params) Path(path string) string

Path returns the second part of the path after the target type, indicating the path to the specific parameter being set.

func (*Params) SaveGoCode

func (pr *Params) SaveGoCode(filename gi.FileName) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Params) SaveJSON

func (pr *Params) SaveJSON(filename gi.FileName) error

SaveJSON saves params to a JSON-formatted file.

func (*Params) SetParamByName added in v1.0.0

func (pr *Params) SetParamByName(name, value string)

SetParamByName sets given parameter by name to given value. (just a wrapper around map set function)

func (*Params) StringGoCode

func (pr *Params) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Params) TargetType

func (pr *Params) TargetType() string

TargetType returns the first part of the path, indicating what type of object the params apply to. Uses the first item in the map (which is random) everything in the map must have the same target.

func (*Params) WriteGoCode

func (pr *Params) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Sel

type Sel struct {
	Sel    string `` /* 279-byte string literal not displayed */
	Desc   string `` /* 180-byte string literal not displayed */
	Params Params `view:"no-inline" desc:"parameter values to apply to whatever matches the selector"`
}

params.Sel specifies a selector for the scope of application of a set of parameters, using standard css selector syntax (. prefix = class, # prefix = name, and no prefix = type)

func (*Sel) Apply

func (ps *Sel) Apply(obj interface{}, setMsg bool) (bool, error)

Apply checks if Sel selector applies to this object according to (.Class, #Name, Type) using the params.Styler interface, and returns false if it does not. The TargetType of the Params is always tested against the obj's type name first. If it does apply, or is not a Styler, then the Params values are set. 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 (*Sel) OpenJSON

func (pr *Sel) OpenJSON(filename gi.FileName) error

OpenJSON opens params from a JSON-formatted file.

func (*Sel) SaveGoCode

func (pr *Sel) SaveGoCode(filename gi.FileName) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sel) SaveJSON

func (pr *Sel) SaveJSON(filename gi.FileName) error

SaveJSON saves params to a JSON-formatted file.

func (*Sel) SelMatch

func (ps *Sel) SelMatch(obj interface{}) bool

SelMatch returns true if Sel selector matches the target object properties

func (*Sel) StringGoCode

func (pr *Sel) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sel) TargetTypeMatch

func (ps *Sel) TargetTypeMatch(obj interface{}) bool

TargetTypeMatch return true if target type applies to object

func (*Sel) WriteGoCode

func (pr *Sel) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Set

type Set struct {
	Name   string `desc:"unique name of this set of parameters"`
	Desc   string `width:"60" desc:"description of this param set -- when should it be used?  how is it different from the other sets?"`
	Sheets Sheets `` /* 337-byte string literal not displayed */
}

Set is a collection of Sheet's that constitute a coherent set of parameters -- a particular specific configuration of parameters, which the user selects to use. A good strategy is to have a "Base" set that has all the best parameters so far, and then other sets can modify relative to that one. It is up to the Sim code to apply parameter sets in whatever order is desired.

Within a params.Set, multiple different params.Sheet's can be organized, with each CSS-style sheet achieving a relatively complete parameter styling of a given element of the overal model, e.g., "Network", "Sim", "Env". Or Network could be further broken down into "Learn" vs. "Act" etc, or according to different brain areas ("Hippo", "PFC", "BG", etc). Again, this is entirely at the discretion of the modeler and must be performed under explict program control, especially because order is so critical.

Note that there is NO deterministic ordering of the Sheets due to the use of a Go map structure, which specifically randomizes order, so simply iterating over them and applying may produce unexpected results -- it is better to lookup by name.

func (*Set) Diffs

func (ps *Set) Diffs(ops *Set) string

Diffs reports all the cases where the same param path is being set to different values between this set and the other set.

func (*Set) DiffsWithin

func (ps *Set) DiffsWithin() string

DiffsWithin reports all the cases where the same param path is being set to different values within different sheets

func (*Set) OpenJSON

func (pr *Set) OpenJSON(filename gi.FileName) error

OpenJSON opens params from a JSON-formatted file.

func (*Set) SaveGoCode

func (pr *Set) SaveGoCode(filename gi.FileName) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Set) SaveJSON

func (pr *Set) SaveJSON(filename gi.FileName) error

SaveJSON saves params to a JSON-formatted file.

func (*Set) SheetByName added in v1.0.0

func (ps *Set) SheetByName(name string) *Sheet

SheetByName finds given sheet by name -- returns nil if not found. Use this when sure the sheet exists -- otherwise use Try version.

func (*Set) SheetByNameTry

func (ps *Set) SheetByNameTry(name string) (*Sheet, error)

SheetByNameTry tries to find given sheet by name, and returns error if not found (also logs the error)

func (*Set) StringGoCode

func (pr *Set) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Set) ValidateSheets

func (ps *Set) ValidateSheets(valids []string) error

ValidateSheets ensures that the sheet names are among those listed -- returns error message for any that are not. Helps catch typos and makes sure params are applied properly. Automatically logs errors.

func (*Set) WriteGoCode

func (pr *Set) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Sets

type Sets []*Set

Sets is a collection of Set's that can be chosen among depending on different desired configurations etc. Thus, each Set represents a collection of different possible specific configurations, and different such configurations can be chosen by name to apply as desired.

func (*Sets) DiffsAll

func (ps *Sets) DiffsAll() string

DiffsAll reports all the cases where the same param path is being set to different values across different sets

func (*Sets) DiffsFirst

func (ps *Sets) DiffsFirst() string

DiffsFirst reports all the cases where the same param path is being set to different values between the first set (e.g., the "Base" set) and all other sets

func (*Sets) DiffsWithin

func (ps *Sets) DiffsWithin(setName string) string

DiffsWithin reports all the cases where the same param path is being set to different values within different sheets in given set

func (*Sets) ElemLabel

func (ps *Sets) ElemLabel(idx int) string

ElemLabel satisfies the gi.SliceLabeler interface to provide labels for slice elements

func (*Sets) OpenJSON

func (pr *Sets) OpenJSON(filename gi.FileName) error

OpenJSON opens params from a JSON-formatted file.

func (*Sets) SaveGoCode

func (pr *Sets) SaveGoCode(filename gi.FileName) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sets) SaveJSON

func (pr *Sets) SaveJSON(filename gi.FileName) error

SaveJSON saves params to a JSON-formatted file.

func (*Sets) SetByName

func (ps *Sets) SetByName(name string) *Set

SetByName returns given set by name -- for use when confident that it exists, as a nil will return if not found with no error

func (*Sets) SetByNameTry

func (ps *Sets) SetByNameTry(name string) (*Set, error)

SetByNameTry tries to find given set by name, and returns error if not found (also logs the error)

func (*Sets) StringGoCode

func (pr *Sets) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sets) ValidateSheets

func (ps *Sets) ValidateSheets(valids []string) error

ValidateSheets ensures that the sheet names are among those listed -- returns error message for any that are not. Helps catch typos and makes sure params are applied properly. Automatically logs errors.

func (*Sets) WriteGoCode

func (pr *Sets) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Sheet

type Sheet []*Sel

Sheet is a CSS-like style-sheet of params.Sel values, each of which represents a different set of specific parameter values applied according to the Sel selector: .Class #Name or Type.

The order of elements in the Sheet list is critical, as they are applied in the order given by the list (slice), and thus later Sel's can override those applied earlier. Thus, you generally want to have more general Type-level parameters listed first, and then subsequently more specific ones (.Class and #Name)

This is the highest level of params that has an Apply method -- above this level application must be done under explicit program control.

func (*Sheet) Apply

func (ps *Sheet) Apply(obj interface{}, setMsg bool) (bool, error)

Apply applies entire sheet to given object, using param.Sel's in order see param.Sel.Apply() for details. 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 (*Sheet) Diffs

func (ps *Sheet) Diffs(ops *Sheet, setNm1, setNm2 string) string

Diffs reports all the cases where the same param path is being set to different values between this sheeet and the other sheeet.

func (*Sheet) DiffsWithin

func (ps *Sheet) DiffsWithin(shtNm string) string

DiffsWithin reports all the cases where the same param path is being set to different values within different Sel's in this Sheet.

func (*Sheet) ElemLabel

func (sh *Sheet) ElemLabel(idx int) string

ElemLabel satisfies the gi.SliceLabeler interface to provide labels for slice elements

func (*Sheet) OpenJSON

func (pr *Sheet) OpenJSON(filename gi.FileName) error

OpenJSON opens params from a JSON-formatted file.

func (*Sheet) SaveGoCode

func (pr *Sheet) SaveGoCode(filename gi.FileName) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sheet) SaveJSON

func (pr *Sheet) SaveJSON(filename gi.FileName) error

SaveJSON saves params to a JSON-formatted file.

func (*Sheet) SelByName added in v1.0.0

func (sh *Sheet) SelByName(sel string) *Sel

SelByName returns given selector within the Sheet, by Name. Returns nil if not found -- use Try version for error

func (*Sheet) SelByNameTry added in v1.0.0

func (sh *Sheet) SelByNameTry(sel string) (*Sel, error)

SelByNameTry returns given selector within the Sheet, by Name. Returns nil and error if not found.

func (*Sheet) StringGoCode

func (pr *Sheet) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sheet) WriteGoCode

func (pr *Sheet) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Sheets

type Sheets map[string]*Sheet

Sheets is a map of named sheets -- used in the Set

func (*Sheets) DiffsWithin

func (ps *Sheets) DiffsWithin() string

DiffsWithin reports all the cases where the same param path is being set to different values within different sheets

func (*Sheets) OpenJSON

func (pr *Sheets) OpenJSON(filename gi.FileName) error

OpenJSON opens params from a JSON-formatted file.

func (*Sheets) SaveGoCode

func (pr *Sheets) SaveGoCode(filename gi.FileName) error

SaveGoCode saves params to corresponding Go initializer code.

func (*Sheets) SaveJSON

func (pr *Sheets) SaveJSON(filename gi.FileName) error

SaveJSON saves params to a JSON-formatted file.

func (*Sheets) StringGoCode

func (pr *Sheets) StringGoCode() []byte

StringGoCode returns Go initializer code as a byte string.

func (*Sheets) WriteGoCode

func (pr *Sheets) WriteGoCode(w io.Writer, depth int)

WriteGoCode writes params to corresponding Go initializer code.

type Styler

type Styler interface {
	// TypeName returns the name of this type. CSS Sel selector with no prefix
	// operates on type name.  This type is used *in addition* to the actual
	// Go type name of the object, and is a kind of type-category (e.g., Layer
	// or Prjn in emergent network objects)
	TypeName() string

	// Class returns the space-separated list of class selectors (tags).
	// Parameters with a . prefix target class tags.
	// Do NOT include the. in the Class tags on Styler objects however
	// -- those are only in the Sel selector on the params.Sel.
	Class() string

	// Name returns the name of this object.
	// Parameters with a # prefix target object names, which are typically
	// unique.  Note, do not include the # prefix in the Styler name.
	Name() string
}

The params.Styler interface exposes TypeName, Class, and Name methods that allow the params.Sel CSS-style selection specifier to determine whether a given parameter applies. Adding Set versions of Name and Class methods is a good idea but not needed for this interface, so they are not included here.

Jump to

Keyboard shortcuts

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