Skip to content

Commit

Permalink
many simscripts updates -- get rid of version dir, auto-fill config f…
Browse files Browse the repository at this point in the history
…ields to extent possible.
  • Loading branch information
rcoreilly committed Jun 19, 2024
1 parent 20290c8 commit 0fe4592
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 36 deletions.
10 changes: 4 additions & 6 deletions simscripts/00-Jobs.cosh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

// note: br is browser

func OpenJobs(path string) {
func OpenJobs() {
tv := br.NewTabTensorTable("Jobs")
dt := tv.Table.Table
JobsTableView = tv
JobsTable = dt
dpath := filepath.Join(br.DataRoot, path)
dpath := filepath.Join(br.DataRoot, "jobs")
// fmt.Println("opening data at:", dpath)

if dt.NumColumns() == 0 {
Expand Down Expand Up @@ -41,10 +41,8 @@ func OpenJobs(path string) {

// Default update function:
UpdateFunc = func() {
OpenJobs(Config.Version)
OpenJobs()
}

fmt.Println(Config.Version)

OpenJobs(Config.Version)
OpenJobs()

6 changes: 3 additions & 3 deletions simscripts/10-Status.cosh
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func JobStatus(jid string, force bool) {
core.MessageSnackbar(br, "Job: " + jid + " updated with status: " + sstat)
}

func JobsStatus(path string) {
func JobsStatus() {
@0
br.UpdateFiles()
dpath := filepath.Join(br.DataRoot, path)
dpath := filepath.Join(br.DataRoot, "jobs")
ds := fsx.Dirs(dpath)
for _, jid := range ds {
JobStatus(jid, false) // true = update all -- for format and status edits
Expand All @@ -95,5 +95,5 @@ func JobsStatus(path string) {
Update()
}

{go JobsStatus(Config.Version)}
{go JobsStatus()}

6 changes: 3 additions & 3 deletions simscripts/20-Fetch.cosh
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func FetchJob(jid string, force bool) {
}
}

func FetchJobs(path string) {
func FetchJobs() {
@0
tv := JobsTableView
jobs := tv.SelectedColumnStrings("JobID")
if len(jobs) == 0 {
dpath := filepath.Join(br.DataRoot, path)
dpath := filepath.Join(br.DataRoot, "jobs")
jobs = fsx.Dirs(dpath)
}
for _, jid := range jobs {
Expand All @@ -67,5 +67,5 @@ func FetchJobs(path string) {
Update()
}

{go FetchJobs(Config.Version)}
{go FetchJobs()}

3 changes: 3 additions & 0 deletions simscripts/30-Submit.cosh
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func NewJob(message, args, label string) {
scp {sfn} "@1:go.sum"
@1
go mod edit -module {projPath}
if Config.ExtraGoGet != "" {
go get {Config.ExtraGoGet}
}
go mod tidy
@0
scp "@1:go.mod" "go.mod"
Expand Down
12 changes: 6 additions & 6 deletions simscripts/70-Cancel.cosh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// with a confirmation prompt.

// CancelJobs cancels the given jobs
func CancelJobs(jobs []string, path string) {
func CancelJobs(jobs []string) {
@0
dpath := filepath.Join(br.DataRoot, path)
spath := filepath.Join(Config.ServerRoot, path)
dpath := filepath.Join(br.DataRoot, "jobs")
spath := filepath.Join(Config.ServerRoot, "jobs")
@1
for _, jid := range jobs {
sjob := ValueForJob(jid, "ServerJob")
Expand All @@ -19,18 +19,18 @@ func CancelJobs(jobs []string, path string) {
core.MessageSnackbar(br, "Done canceling jobs")
}

func CancelJobsPrompt(path string) {
func CancelJobsPrompt() {
tv := JobsTableView
jobs := tv.SelectedColumnStrings("JobID")
if len(jobs) == 0 {
core.MessageSnackbar(br, "No jobs selected for cancel")
return
}
databrowser.PromptOKCancel(br, "Ok to cancel these jobs: " + strings.Join(jobs, " "), func() {
CancelJobs(jobs, path)
CancelJobs(jobs)
Update()
})
}

CancelJobsPrompt(Config.Version)
CancelJobsPrompt()

12 changes: 6 additions & 6 deletions simscripts/80-Delete.cosh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Delete deletes the selected Jobs, with a confirmation prompt.

// DeleteJobs deletes the given jobs
func DeleteJobs(jobs []string, path string) {
func DeleteJobs(jobs []string) {
@0
dpath := filepath.Join(br.DataRoot, path)
spath := filepath.Join(Config.ServerRoot, path)
dpath := filepath.Join(br.DataRoot, "jobs")
spath := filepath.Join(Config.ServerRoot, "jobs")
for _, jid := range jobs {
@1
cd
Expand All @@ -20,18 +20,18 @@ func DeleteJobs(jobs []string, path string) {
core.MessageSnackbar(br, "Done deleting jobs")
}

func DeleteJobsPrompt(path string) {
func DeleteJobsPrompt() {
tv := JobsTableView
jobs := tv.SelectedColumnStrings("JobID")
if len(jobs) == 0 {
core.MessageSnackbar(br, "No jobs selected for deletion")
return
}
databrowser.PromptOKCancel(br, "Ok to delete these jobs: " + strings.Join(jobs, " "), func() {
DeleteJobs(jobs, path)
DeleteJobs(jobs)
Update()
})
}

DeleteJobsPrompt(Config.Version)
DeleteJobsPrompt()

14 changes: 7 additions & 7 deletions simscripts/85-Archive.cosh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// for results that are useful but not immediately relevant.

// ArchiveJobs archives the given jobs
func ArchiveJobs(jobs []string, path string) {
func ArchiveJobs(jobs []string) {
@0
dpath := filepath.Join(br.DataRoot, path)
apath := filepath.Join(br.DataRoot, "archive", path)
dpath := filepath.Join(br.DataRoot, "jobs")
apath := filepath.Join(br.DataRoot, "archive", "jobs")
mkdir -p {apath}
spath := filepath.Join(Config.ServerRoot, path)
spath := filepath.Join(Config.ServerRoot, "jobs")
for _, jid := range jobs {
@1
cd
Expand All @@ -25,18 +25,18 @@ func ArchiveJobs(jobs []string, path string) {
core.MessageSnackbar(br, "Done archiving jobs")
}

func ArchiveJobsPrompt(path string) {
func ArchiveJobsPrompt() {
tv := JobsTableView
jobs := tv.SelectedColumnStrings("JobID")
if len(jobs) == 0 {
core.MessageSnackbar(br, "No jobs selected for archiving")
return
}
databrowser.PromptOKCancel(br, "Ok to archive these jobs: " + strings.Join(jobs, " "), func() {
ArchiveJobs(jobs, path)
ArchiveJobs(jobs)
Update()
})
}

ArchiveJobsPrompt(Config.Version)
ArchiveJobsPrompt()

31 changes: 31 additions & 0 deletions simscripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,38 @@ The general workflow is as follows, assuming a standard [install](#install) has

# Install

From this `simscripts` directory, run:

```sh
> ./install.cosh ~/full/path/to/sim
```

Which creates a project directory in `~/simdata/projname/username` that has a symbolic link in the sim directory so it is accessible directly from there, but is not actually located there so there are no issues with git ownership of these files.

You then need to create a `defaults.cosh` file that sets various parameters on the `Config` object specific to this project, including extra non-Go file and sub-directories that might need to be copied up to the server to run it. There are also job configuration parameters (e.g., max runtime). Here is an example, for a sim in `axon/examples`, that requires the extra `go get`:

```go
// to run, in numbers:
// databrowser.NewBrowserWindow("simdata")

// primary remote server: avail as @1
cossh hpc2.engr.ucdavis.edu

func defaults() {
cf := &Config
cf.Defaults()
cf.ServerName = "hpc2"
cf.ExtraGoGet = "github.com/emer/axon/v2@main"
cf.Job.Hours = 1
cf.Job.Qos = "oreillylab"
cf.ExcludeNodes = "agate-[0,17-19,28,41-45]"
cf.ExtraFiles = []string{"config_job.toml"}

cf.Update()
}

defaults()
```

# Example `cosh` code

Expand Down
22 changes: 17 additions & 5 deletions simscripts/config.cosh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import (
"fmt"
"os"
"path/filepath"
"strings"

"cogentcore.org/core/core"
"cogentcore.org/core/plot/plotcore"
Expand Down Expand Up @@ -93,7 +93,7 @@ type Configuration struct {
// name of simulation project, lowercase (should be name of source dir)
Project string

// current version string, e.g., v008 or v112: names subdirectory of jobs
// current git version string, from git describe --tags
Version string

// parameters for job resources etc
Expand All @@ -118,6 +118,11 @@ type Configuration struct {
// name of current server using to run jobs; gets recorded with each job
ServerName string

// ExtraGoGet is an extra package to do "go get" with, for launching the job.
// Typically set this to the parent packge if running within a larger package
// upon which this simulation depends, e.g., "github.com/emer/axon/v2@main"
ExtraGoGet string

// root path from user home dir on server.
// is auto-set to: filepath.Join("simdata", Project, User)
ServerRoot string
Expand All @@ -136,7 +141,14 @@ type Configuration struct {
}

func (cf *Configuration) Defaults() {
cf.User = os.Getenv("USER")
@0
cd
cd {br.StartDir}
Config.Version = strings.TrimSpace(`git describe --tags`)
cd {br.DataRoot}
cf.User = strings.TrimSpace(`echo $USER`)
_, pj := filepath.Split(br.StartDir)
cf.Project = pj
cf.Job.Defaults()
cf.FetchFiles = "*.tsv"
cf.Plot.Defaults()
Expand Down Expand Up @@ -187,11 +199,11 @@ var (
)

func JobPath(jid string) string {
return filepath.Join(br.DataRoot, Config.Version, jid)
return filepath.Join(br.DataRoot, "jobs", jid)
}

func ServerJobPath(jid string) string {
return filepath.Join(Config.ServerRoot, Config.Version, jid)
return filepath.Join(Config.ServerRoot, "jobs", jid)
}

// Call update after each action that affects jobs.
Expand Down

0 comments on commit 0fe4592

Please sign in to comment.