[ANN] MiniObserve.jl

MiniObserve makes it easy to declare a set of variables to extract from a complex object (such as a simulation model) and write them to a CSV file or append them to a DataFrame.

Simulation models often have to keep track of a number of observation variables (some of which may be aggregate values) that will be recorded over the runtime of the simulation and written to a file for later analysis, displayed in a graph, etc. Writing this observation code by hand can be quite annoying, especially if variables are changed later. It is for example easy to add a new variable to the output but to forget to change the CSV header accordingly.

With MiniObserve.jl observation variables are declared once and code that handles data collection, CSV setup and output is generated from that declaration.

To give a quick example:

@observe Data model user1 user2 begin
	@record "time"      model.time
	@record "N"     Int length(model.population)

	for ind in model.population 
		@stat("capital", MaxMinAcc{Float64}, MeanVarAcc{FloatT}) <| ind.capital
		@stat("n_alone", CountAcc)           <| has_neighbours(ind)
	end

	@record u1			user1
	@record u2			user1 * user2
end

This will generate

  • a struct type Data containing all declared observation variables as properties
  • a method MiniObserve.observe(::Type{Data}, model, user1, user2) that will return an instance of Data
  • methods of functions to generate a CSV header, configure a DataFrame and add the content of a given Data object to the corresponding file or DataFrame

Please head over to the github page for the full documentation.

2 Likes