Skip to content

Commit

Permalink
Refactor reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
saulshanabrook committed Jul 3, 2017
1 parent 47b44e3 commit 638bf0a
Show file tree
Hide file tree
Showing 21 changed files with 1,119 additions and 805 deletions.
3 changes: 2 additions & 1 deletion project.clj
Expand Up @@ -14,7 +14,8 @@
[clj-random "0.1.7"]
;; https://mvnrepository.com/artifact/org.apache.commons/commons-math3
[org.apache.commons/commons-math3 "3.2"]
[cheshire "5.7.1"]]
[cheshire "5.7.1"]
[prismatic/plumbing "0.5.4"]]
:plugins [[lein-codox "0.9.1"]
[lein-shell "0.5.0"]
[lein-gorilla "0.4.0"]
Expand Down
15 changes: 7 additions & 8 deletions src/clojush/args.clj
@@ -1,8 +1,7 @@
(ns clojush.args
(:require [clj-random.core :as random])
(:use [clojush globals random util pushstate]
[clojush.instructions.tag]
[clojush.pushgp report]))
[clojush.instructions.tag]))

(def push-argmap
(atom (sorted-map
Expand Down Expand Up @@ -89,8 +88,8 @@
:uniform-addition 0.0
:uniform-addition-and-deletion 0.0
:uniform-combination-and-deletion 0.0
:genesis 0.0
}
:genesis 0.0}

;; The map supplied to :genetic-operator-probabilities should contain genetic operators
;; that sum to 1.0. All available genetic operators are defined in clojush.pushgp.breed.
;; Along with single operators, pipelines (vectors) containing multiple operators are
Expand Down Expand Up @@ -376,11 +375,11 @@
;; The number of simplification steps that will happen during final report
;; simplifications.

:problem-specific-initial-report default-problem-specific-initial-report
:problem-specific-initial-report (fn [argmap] :no-problem-specific-initial-report-function-defined)
;; A function can be called to provide a problem-specific initial report, which happens
;; before the normal initial report is printed.

:problem-specific-report default-problem-specific-report
:problem-specific-report (fn [& args] :no-problem-specific-report-function-defined)
;; A function can be called to provide a problem-specific report, which happens before
;; the normal generational report is printed.

Expand Down Expand Up @@ -462,10 +461,10 @@
;; Should be in the format "<hostname>:<port>"
;; If set, will send logs of each run to a server running on this
;; host
:label nil
:label nil)))
;; If set, will send this in the configuration of the run, to the
;; external record
)))


(defn load-push-argmap
[argmap]
Expand Down
15 changes: 5 additions & 10 deletions src/clojush/core.clj
Expand Up @@ -16,33 +16,28 @@
;; for more details.

(ns clojush.core
(:require [clojush.pushgp.record :as r])
(:use [clojush.pushgp pushgp report])
(:require [clojush.log :refer [log!]])
(:use [clojush.pushgp pushgp])
(:gen-class))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; main function

(defn -main
(defn -main
"A main function for Clojush, which assumes that the first argument is the name
of a problem file that contains an argmap of arguments to PushGP.
Exits after completion of the call.
Any arguments after the first are treated as arguments to PushGP as key-value pairs.
This allows one to run an example with a call from the OS shell prompt like:
lein run examples.simple-regression :population-size 3000"
[& args]
(r/new-run!)
(println "Command line args:" (apply str (interpose \space args)))
(let [param-list (map #(if (.endsWith % ".ser")
(str %)
(read-string %))
(rest args))]
(require (symbol (r/config-data! [:problem-file] (first args))))
(require (symbol (first args)))
(let [example-params (eval (symbol (str (first args) "/argmap")))
params (merge example-params (apply sorted-map param-list))]
(println "######################################")
(println "Parameters set at command line or in problem file argmap; may or may not be default:")
(print-params (into (sorted-map) params))
(println "######################################")
(log! :init {:args args :params params})
(pushgp params)
(System/exit 0))))
19 changes: 19 additions & 0 deletions src/clojush/log.clj
@@ -0,0 +1,19 @@
(ns clojush.log
(:require [clojush.structured-logger :refer [->structured-logger]]
[clojush.log.events :refer [label->compute-graph]]
[clojush.log.handlers :refer [handlers]]))
;; this stuff is spread out over many files in subdirectories
;; Not only does this help with keeping files shorter, but it also allows
;; us to use the defnk names directly in the graph, because we don't
;; have to namespace them. For example, if we define `best` in the
;; lexicase file, then we can just throw that in the graph we defined
;; there, and it will registered under :best.

(def structured-logger
(->structured-logger
{:handlers handlers
:label->compute-graph label->compute-graph}))

(def log! (:log! structured-logger))

(def label->computed (:label->computed structured-logger))
9 changes: 9 additions & 0 deletions src/clojush/log/events.clj
@@ -0,0 +1,9 @@
(ns clojush.log.events
(:require [clojush.log.events.init]
[clojush.log.events.config]
[clojush.log.events.generation]))

(def label->compute-graph
{:init clojush.log.events.init/compute-graph
:config clojush.log.events.config/compute-graph
:generation clojush.log.events.generation/compute-graph})
45 changes: 45 additions & 0 deletions src/clojush/log/events/config.clj
@@ -0,0 +1,45 @@
(ns clojush.log.events.config
(:require [plumbing.core :refer [defnk]]
[plumbing.graph :as graph]
[clj-random.core :as random]
[local-file]
[clojure.string :as string]))

(defnk clojush-version []
(let [version-str (apply str (butlast (re-find #"\".*\""
(first (string/split-lines
(local-file/slurp* "project.clj"))))))]
(.substring version-str 1 (count version-str))))

(defnk argmap [argmap-input]
argmap-input)

(defnk registered-instructions [registered-instructions-input]
registered-instructions-input)

(defnk argmap-with-random-str [argmap-input]
(update argmap :random-seed random/seed-to-string))

(defnk git-hash []
(let [dir (local-file/project-dir)]
(string/trim
(slurp
(str dir
"/.git/"
(subs
(string/trim
(slurp
(str dir "/.git/HEAD")))
5))))))

(defnk initialization-ms [timing-map]
(:initialization timing-map))

(def compute-graph
(graph/graph
clojush-version
argmap
registered-instructions
git-hash
initialization-ms
argmap-with-random-str))

0 comments on commit 638bf0a

Please sign in to comment.