Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using RNG in DSP #5

Open
iguinn opened this issue Apr 6, 2022 · 2 comments
Open

Using RNG in DSP #5

iguinn opened this issue Apr 6, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@iguinn
Copy link
Collaborator

iguinn commented Apr 6, 2022

It could be useful to generate random numbers in a ProcessingChain. One use for this would be in pulse generation. An example of what such a processing chain config might look like is:

{
    "processors": {
	"amp": {
	    "processor": "random_gaus",
	    "module": "???",
	    "args": [10, 1, "amp"]
	},
	"risetime": {
	    "processor": "random_uniform",
	    "module": "???",
	    "args": ["0.5*us", "1*us", "risetime(unit=us)"]
	},
	"offset": {
	    "processor": "random_gaus",
	    "module": "???",
	    "args": ["10*us", "1*us", "offset(unit=us)"],
	},
	"waveform": {
	    "processor": "pulse_injector",
	    "module": "pygama.dsp.processors",
	    "args": ["zeros_in", "amp", "risetime", "offset", "waveform"]
	}
    }
}

However, right now it's not clear what RNG processors we could use. The numpy.random generators to do not work with in place array filling. The same is true of the scipy.stats generators. Numba seems to have support for random number generation, but I'm not sure how it works yet. We also want to make sure that we can control the seeding of the RNGs, and make sure that this would work for multi-threading.

Here are the features we want for our RNG processors:

  1. Fill output array in place (i.e. have an out argument)
  2. Have a way to set initial seeds
  3. Robust for multithreaded and MPI
@jasondet
Copy link
Contributor

jasondet commented Sep 14, 2022

@iguinn numpy.random() does have an out argument that does in-place array filling, can't that do the job?

@gipert
Copy link
Member

gipert commented Sep 18, 2022

I guess we will then wrap NumPy's random functions to include an out argument? Maybe we can also do it generically with meta-programming?

From the Numba docs, looks like their implementation is thread-safe (except when using Generators).

To control random number sequences, as far as I understand, we will have to make sure to seed both the Numba and the NumPy random generator (see note here)

@jasondet can you elaborate?

@gipert gipert added the enhancement New feature or request label Sep 22, 2022
@gipert gipert transferred this issue from legend-exp/pygama May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants