Global experiment counter

How would I go about making a global experiment counter that updates when any of a set of other cells change?

My use case is that I want the page to allow running of several experiments whose parameters are controlled via UI elements (e.g. a slider).

Each time any of the UI elements changes, I want to be able to

  1. increment the global experiment counter by one
  2. run an experiment with new parameters
  3. record it in some state object keyed by the experiment ID
  4. clean up WebGL memory from all older experiments.

Eventually it’d also be nice if an “experiment” was changing the code of a cell.

There may be something I’m missing here, but would love some guidance! Thanks!

Just found this, which solves my cleanup memory from the previous run of a cell problem:

Glad you thought of this in November, Mike :smiley:

Hi Nikhil,

We’ve just released the mutable keyword, which should give you an easier way to orchestrate the state of your experiments across cell boundaries. For the basics, check out the introductory notebook:

Specifically, I would imagine that you could:

  • Have a mutable experimentNo = 1 counter that you increment whenever an experiment is re-evaluated.
  • Have a mutable experimentRecords = {} object that you mutate and replace every time an experiment has finished and its results are finalized.
  • Have other cells that observe and react to either of those things.

Let me know if that doesn’t help you…

Awesome, that sounds like exactly what I want (I saw the “code stinks” notebook and stayed away from simply mutating an object of my own).

Thank you :slight_smile: