freenode/#lisp - IRC Chatlog
Search
18:19:32
jeosol
anyone running math/computational problems with random numbers where they save state and restart?
18:21:55
jeosol
apologies for my use of "save state" and "restart". These are not in the usual CL context. By "save state" I mean save information about the random number generator and by "restart" I mean restart the run again but now using the info from the random number generator
18:22:46
phoe
if you are using the Lisp RNG, then simply save *RANDOM-STATE* somehow, perhaps to a file
18:24:28
rme
You can always print *random-state* to a file and read it back in. The format of *random-state* is implementation-dependent, but you can always print and read it.
18:24:39
_death
in sbcl's case, even if it didn't provide a way, you'd still be able to reconstruct the state ("clone" it) since it's not a cryptographic rng
18:26:06
rme
I am pretty sure that the spec requires that you be able to print and read *random-state*.
18:26:38
jeosol
rme: I am able to initialize it and read back in. Let me quickly check that part of the code again
18:30:41
_death
on my flight home I actually ported my old Go code to clone the state.. https://gist.github.com/death/ba34a87cd43fc041215f36c735e0fe13
18:30:49
jeosol
when I start, I call make-random-state, save that info somewhere. If I need to continue to run, I read back that info
18:31:10
rme
For instance, in ccl, the default random-state object is #.(INITIALIZE-MRG31K3P-STATE 314159 42 1776 271828 6021023 1066)
18:32:54
rme
jeosol: the random state object gets modified every time you call random. the point of saving and restoring it is so that you can run your computation multiple times using the same sequence of (pseudo-) random values.
18:34:43
jeosol
they way my application works is this (simplified). I get a random number, do some calculations. Let's call this one iteration. I repeat this again for more iterations
18:35:19
jeosol
somewhere along the line (I may have power failure like today), I want to be able to pick up from where I stop, or sometimes just continue if I don't have convergence.
18:35:51
jeosol
So the reason is to continue the search trend I had before the disruption or just continue in the case of extension
18:36:57
jeosol
extending the run works fine, but with power failure, some required files for rerun where not written. I am currently working on this part ...
18:44:04
rme
Beware that *random-state* might be thread-local (it is on ccl). I have no idea if that applies to your situation.
18:46:44
phoe
welp, multiple threads might be modifying the random state at the same time, too. that might be dangerous.
18:48:09
jeosol
I run multiple threads for evaluation but I the generation of solutions is non-threaded
18:51:51
jeosol
I am sure this has been said enough. This place is like a hive of connected brains. Problems getting resolved quickly and also, you are getting multiple ideas and gotchas. What's there not to love
18:52:22
jeosol
I am singing to the choir, but with suggestions here over last few weeks, my code is more stable
18:54:26
fourier
jeosol: why dont you just precompute a series of number and run on it until you get some stable results?
18:57:04
jeosol
I am running an optimization problem with > 1000 variables per solution and like 30 solutions per iteration.
19:00:55
jeosol
So I just live with that approach for now. As per stability, for small problems (not expensive computationally), I perform multiple runs and average the results.
19:01:21
jeosol
with SBCL, the code is pretty fast the bottleneck is elsewhere. My current pain is instrumenting code for re-runs
19:11:20
ecraven
is there a way to print a custom "banner" in SLIME from the swank? it just says '; SLIME 2.20', but nothing about the actually connected lisp (only in the buffer name, but I'd love to see the actual lisp somewhere up there on connecting)
19:16:58
sea
Is there a way to tell lisp that a particular function always returns the same value, and can be compiled away?
19:17:15
ecraven
phoe: yea, but I'd love to see it somewhere up top too. I guess I'll have to add some :write-string somewhere to just show it that way
19:18:02
sea
(defun bar (x) (+ x (foo))). How can I make it evaluate that foo once, and store 42 in bar instead?
19:22:08
sea
I have a macro that compiles code to lisp, and I have a function I'm defining with one of those macros in it. I realized that every time I run the function, it re-compiles the code in it for no reason, and I wanted to avoid that
19:28:56
ealfonso
how can I avoid an undefined variable warning when using (cffi:defcvar ("my_var" my-var) :int) and then referring to my-var?
19:32:57
ealfonso
Bike https://pastebin.com/H8SEkxL4 I'm simply referring to the defcvar variable with setf
19:33:48
Bike
ealfonso: i believe defcvar is intended to be used at top level. the compiler won't be aware of the definition while compiling init-lib.
19:35:24
Bike
since defcvar just establishes a symbol macro it's largely pointless to do it at runtime, anyway
19:39:27
pierpa
sea: maybe you can do the computation at read time? (defun foo (x) #.(compute-something x))
19:40:16
sea
That's just the example code. I wanted something slow to take up time, so I could figure out if the macro was being run at compile-time or run-time
19:41:00
Bike
if you just evaluate it it could go either way, but in most implementations now it'll still be expanded just the once.
19:46:17
sea
Hrm, it's still slightly slower than it should be. I took the macro bit out altogether and put it as a global variable it can reference
19:51:25
sea
Maybe it's down to how I write my macros? Is there a better way to do this: (defmacro foo (x) (list 'quote (f x))) ?
19:55:53
ealfonso
any idea why something simple like this causes my sbcl instance to run out of memory and crash when it works fine in C: (cffi:with-foreign-object (g :pointer) (cffi:foreign-funcall "my_alloc_new_very_small_struct" :pointer))
20:12:23
ealfonso
Bike I was calling a binary function with zero args, so there was probably uninitialized data causing a huge malloc
20:59:14
Xach
rme: Sorry to bug you, but ccl.clozure.com is not working for me - what does :SHARED mean in make-hash-table?
21:01:02
Xach
rme: Trying to adapt some sbcl code which uses `:synchronized t` to mean "concurrent writers are safe", so that's my real question - how to get safe concurrent writers for ccl hash tables.
21:04:16
rme
They use a lock-free algorithm which is good for typical access, but slower for rehashing or growing the table.
23:33:53
jasom
Any hints for a fully-remote slime debug; I can connect to slime remotely and use tramp for opening the remote files, but do I need to do anything to get them all to play nicely together?
23:34:13
jasom
also if someone has a script for setting up a slime-over-ssh tunnel easily that would save me some time
0:16:39
cgay
Somehow never saw this before. Fun read. https://www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf
5:29:37
drmeister
::notify shiho Pull the latest clasp 'dev' and start building it again. I had introduced a problem in the previous version that only showed up when building quicklisp. The new 'dev' fixes it.
6:14:59
phoe
before I connect to the slime, I mount my Lisp projects directory using sshfs on the same location, so /home/phoe/Projects/Lisp/ refers to the same directory with the same contents both on the remote machine and the local one.
6:15:28
phoe
this way I avoid problems with translating names from local to remote ones, because they are the same.