lundi 12 juin 2017

How does one control all source of randomness in python reliably?

The specific scenario I was considering was that I am receiving a function (pointer/handle) and the function is implementing some arbitrary program f. The program is random and might be using who knows what source of randomness (scikit, random pkg, tensorflow, numpy, not sure what else exists). However, its all in python (hopefully that constraint helps). Thus I was hoping I could "seed python's randomness" before executing f. Something like:

seed_all_of_python_reliably(seed=seed)
f(seed=seed) # now f works properly according to my seeding

if the model of the world is the way I hope it is that solution would be ideal.

However, it seems that the list of randomness in python is ridiculously large (and uncertain?) and who knows how each different library (say standard random vs numpy vs tensorflow etc) obtains its randomness. Thus it seems quite difficult to reliably implement seed_all_of_python_reliably(seed=seed) (unless there might be some way to control stuff through the os?). Thus, I thought of a different solution (with its own drawbacks):

Maybe the only reliable way to do this is for me to implement some class/module/API that gives access to randomness to the user. Thus, when I execute their programs I can control their randomness. I am fine with this solution except that it seems that the only way to guarantee that this works is to trust the user of my library to really use my randomness module. Unless there is some way to throw an exception or something if they every use any source of randomness that is not mine? Though this seems hard since the assumption right now is that f is arbitrary, so it seems hard to be able to check (statically or dynamically) if the user is only using my randomness library without any errors. Right?




Aucun commentaire:

Enregistrer un commentaire