This is the lua client for the crayon package.
- From luarocks:
$ luarocks install crayon- From source:
$ luarocks makeopenssl
On some distributions / OSs installing luasec (which lua-requests depends on) will
fail with some form of this error:
Error: Failed installing dependency: https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/lua-requests-1.1-1.src.rock \
- Failed installing dependency: https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luasec-0.6-1.rockspec - Could not find library file for OPENSSL
No file libssl.a in /usr/lib
No file libssl.so in /usr/lib
No file matching libssl.so.* in /usr/lib
To fix this (assuming openssl is already installed):
$ locate libssl.so
[...]
/usr/lib/x86_64-linux-gnu/libssl.so
$ ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.soAssuming you have Homebrew installed:
$ brew install openssl
$ brew list openssl
[...]
/usr/local/<YOUR_PATH_TO_OPEN_SSL>/openssl/<YOUR_VERSION>/lib
/usr/local/<YOUR_PATH_TO_OPEN_SSL>/openssl/<YOUR_VERSION>/bin
$ luarocks install luasec OPENSSL_DIR=/usr/local/$YOUR_PATH_TO_OPEN_SSL/openssl/<YOUR_VERSION>
$ luarocks install crayonRun:
# Start new test server
$ docker run -d -p 7998:8888 -p 7999:8889 --name crayon_lua_test alband/crayon
# Run test script
$ lua(jit) test.lua
# Remove test server
$ docker rm -f crayon_lua_testlocal crayon = require("crayon")
-- Connect to the server
-- substitute localhost and port with the ones you are using
local cc = crayon.CrayonClient("localhost", 8889)
-- Create a new experiment
local foo = cc:create_experiment("foo")
-- Send some scalar values to the server with their time
foo:add_scalar_value("accuracy", 0, 11.3)
foo:add_scalar_value("accuracy", 4, 12.3)
-- You can force the step value also
foo:add_scalar_value("accuracy", 6, 13.3, 4)
-- Get the datas sent to the server
foo:get_scalar_values("accuracy")
-- >> {
-- 1 :
-- {
-- 1 : 11.3
-- 2 : 0
-- 3 : 0
-- }
-- 2 :
-- {
-- 1 : 12.3
-- 2 : 1
-- 3 : 4
-- }
-- 3 :
-- {
-- 1 : 13.3
-- 2 : 4
-- 3 : 6
-- }
-- }
-- backup this experiment as a zip file
local filename = foo:to_zip()
-- delete this experiment from the server
cc:remove_experiment("foo")
-- using the `foo` object from now on will result in an error
-- Create a new experiment based on foo's backup
local bar = cc:create_experiment("bar", filename)
-- Get the name of all scalar plots in this experiment
bar:get_scalar_names()
-- >> {
-- 1 : "accuracy"
-- }
-- Get the data for this experiment
bar:get_scalar_values("accuracy")
-- >> {
-- 1 :
-- {
-- 1 : 11.3
-- 2 : 0
-- 3 : 0
-- }
-- 2 :
-- {
-- 1 : 12.3
-- 2 : 1
-- 3 : 4
-- }
-- 3 :
-- {
-- 1 : 13.3
-- 2 : 4
-- 3 : 6
-- }
-- }-
Creation:
CrayonClient(hostname="localhost", port=8889)- Create a client object and connect it to the server at address
hostnameand portport.
- Create a client object and connect it to the server at address
-
get_experiment_names()- Returns a list of string containing the name of all the experiments on the server.
-
create_experiment(xp_name, zip_file=nil)- Creates a new experiment with name
xp_nameand returns aCrayonExperimentobject. - If
zip_fileis provided, this experiment is initialized with the content of the zip file (seeCrayonExperiment.to_zipto get the zip file).
- Creates a new experiment with name
-
open_experiment(xp_name)- Opens the experiment called
xp_namethat already exists on the server.
- Opens the experiment called
-
remove_experiment(xp_name)- Removes the experiment
xp_namefrom the server. - WARNING: all elements from this experiment are permanently lost!
- Removes the experiment
-
remove_all_experiments()- Removes all experiment from the server.
- WARNING: all elements from all experiments are permanently lost!
-
Creation: can only be created by the
CrayonClient -
get_scalar_names()- Returns a list of string containing the name of all the scalar values in this experiment.
-
add_scalar_value(name, value, wall_time=-1, step=-1)- Adds a new point with value
valueto the scalar plot namedname. - If not specified, the
wall_timewill be set to the current time and thestepto the step of the previous point with this name plus one (or0if its the first point with this name).
- Adds a new point with value
-
add_scalar_dict(data, wall_time=-1, step=-1)- Add multiple points at the same times where
datais a dictionary where each key is a scalar name and the associated value the value to add for this scalar plot. wall_timeandstepare handled the same as foradd_scalar_valuefor each entry independently.
- Add multiple points at the same times where
-
get_scalar_values(name)- Return a list with one entry for each point added for this scalar plot.
- Each entry is a list containing [wall_time, step, value].
-
get_histogram_names()- Returns a list of string containing the name of all the histogram values in this experiment.
-
add_histogram_value(name, hist, tobuild=false, wall_time=-1, step=-1)- Adds a new point with value
histto the histogram plot namedname. - If
tobuildisfalse,histshould be a dictionary containing:{"min": minimum value, "max": maximum value, "num": number of items in the histogram, "bucket_limit": a list with the right limit of each bucket, "bucker": a list with the number of element in each bucket, "sum": optional, the sum of items in the histogram, "sum_squares": optional, the sum of squares of items in the histogram}. - If
tobuildifTrue,histshould be a list of value from which an histogram is going to be built. - If not specified, the
wall_timewill be set to the current time and thestepto the step of the previous point with this name plus one (or0if its the first point with this name).
- Adds a new point with value
-
get_histogram_values(name)- Return a list with one entry for each point added for this histogram plot.
- Each entry is a list containing [wall_time, step, hist].
- Where each
histis a dictionary similar to the one specified above.
-
to_zip(filename=nil)- Retrieve all the datas from this experiment from the server and store it in
filename. Iffilenameis not specified, it is saved in the current folder. - Returns the name of the file where the datas have been saved.
- This file can then be used to recreate a new experiment with the exact same content as this one.
- Retrieve all the datas from this experiment from the server and store it in