Skip to content

Commit

Permalink
Fix the grammar of a few sentences
Browse files Browse the repository at this point in the history
  • Loading branch information
ziotom78 committed Nov 14, 2024
1 parent 10e0b3a commit 350a619
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions docs/source/random_numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@ a seed and a Random Number Generator (RNG) are used.
Seed
----

The ``random_seed`` is used to control the behaviour of the RNG. The seed
can be ``None`` or an integer number.
If you are **not** interested in the reproducibility of your results, you can
set ``random_seed`` to ``None``. However, this is not recommended.
In fact, this means that if you run multiple times a function or method where
a RNG is used, e.g. for producing noise timelines, then
the outputs will be **different** and you will not be able to re-obtain these
results again.
If instead you are interested in the reproducibility of your results, you can
set ``random_seed`` to an integer number.
With this choice, if you run multiple times a function or method where
a RNG is used, then the outputs will be **the same** and
you will re-obtain these results by re-running your script, as the random
numbers produced by the generator will be exactly the same.

How should you set the ``random_seed``? This parameter **must** be passed to
the constructor of a :class:`.Simulation` class.
If a :class:`.Simulation` instance is created without passing the seed, an
error will be raised and your script will fail. This feature has been
introduced on purpose in order to avoid automatic settings of the seed and
unclear behaviour of the generation of random numbers.
If you are running a parallel script using MPI, you do not have to
worry about setting a different seed for different MPI ranks: by passing
the same seed, the random numbers generated by the different ranks will be
different. This is ensured by the random number generator. We want this
behaviour as we do not want repetitions of, e.g., the same noise TOD if
we split their computation on different MPI ranks. For example, in this
way, if you split the TOD matrix of an :class:`.Observation` class by the
time, you will not encounter the same noise after the samples generated
by a certain rank; if you split the TOD matrix of an :class:`.Observation`
class by the detectors, each one will have a different noise timestream.

Regarding the reproducibility of the results in a parallel code, there is
an **important thing** to bear in mind: if you set the seed to an integer
number but run your script with a different number of MPI ranks, the
outputs will be **different**! Think about a noise time stream of 4 samples.
If you use 2 MPI ranks, then the first 2 samples will be generated by
one RNG (the one of rank 0), while the last 2 samples will be generated
by a different RNG (the one of rank 1). If you then run the same script
with the same seed but with 4 MPI ranks, each of the samples will be
generated by a different RNG and only the first sample will be the same
for the two runs, as it is always the first one generated by rank 0's RNG.
The ``random_seed`` is used to control the behavior of the RNG. The
seed can be ``None`` or an integer number. If you are **not**
interested in the reproducibility of your results, you can set
``random_seed`` to ``None``. However, this is not recommended, as if
you run many times a function or method that uses an RNG, e.g., for
producing noise timelines, then the outputs will be **different**, and
you will not be able to re-obtain these results again. If, instead,
you are interested in the reproducibility of your results, you can set
``random_seed`` to an integer number. With this choice, if you run a
function or method multiple times using an RNG, then the outputs will
be **the same**, and you will obtain these results again by re-running
your script, as the random numbers produced by the generator will be
the same.

How should you set the ``random_seed``? This parameter **must** be
passed to the constructor of a :class:`.Simulation` class. If you
create a :class:`.Simulation` instance without passing the seed, the
constructor will raise an error, and your script will fail. We
implemented this feature to avoid automatic settings of the seed and
unclear behavior of the generation of random numbers. If you run a
parallel script using MPI, you do not have to worry about setting a
different seed for different MPI ranks. The random number generator
ensures that the random numbers generated by the ranks will produce
orthogonal sequences. We want this behavior as we do not want
repetitions of, e.g., the same noise TOD if we split their computation
on different MPI ranks. For example, in this way, if you split the TOD
matrix of an :class:`.Observation` class by the time, you will not
encounter the same noise after the samples generated by a certain
rank; if you split the TOD matrix of an :class:`.Observation` class by
the detectors, each one will have a different noise timestream.

Regarding the reproducibility of the results in a parallel code, there
is an **important thing** to bear in mind. If you set the seed to an
integer number but run your script with a different number of MPI
ranks, the outputs will be **different**! Think about a noise time
stream of 4 samples. If you use 2 MPI ranks, then the first two
samples will be generated by one RNG (rank 0), while the last two
samples will be generated by a different RNG (rank 1). If you then run
the same script with the same seed but with 4 MPI ranks, each of the
samples will be generated by a different RNG, and only the first
sample will be the same for the two runs, as it is always the first
one generated by rank 0s RNG.

The setting of the ``random_seed`` is as simple as this::

Expand All @@ -64,12 +64,12 @@ The setting of the ``random_seed`` is as simple as this::
random_seed=12345, # Here the seed for the random number generator is set
)

During the execution of the :class:`.Simulation` constructor, the
:meth:`.Simulation.init_random` method is run. There, the RNG is
built and seeded with ``random_seed``. You can then use this RNG
by calling ``sim.random``. There is also the possibility to
change the random seed after creatinga :class:`.Simulation` instance.
This is achieved by calling :meth:`.Simulation.init_random`::
The :class:`.Simulation` constructor runs the
:meth:`.Simulation.init_random` method, which builds the RNG and seeds
it with ``random_seed``. You can then use this RNG by calling
``sim.random``. There is also the possibility to change the random
seed after creating a :class:`.Simulation` instance. You can achieve
this by calling :meth:`.Simulation.init_random`::

sim = lbs.Simulation(random_seed=12345)
[...]
Expand Down

0 comments on commit 350a619

Please sign in to comment.