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

Help: Clarify Routine's "inheritance" of clocks, times and RNGs [skip ci] #4326

Merged

Conversation

jamshark70
Copy link
Contributor

Purpose and Motivation

A mailing list discussion revealed that some of the documentation about routines "inheriting" state from the parent thread is unclear, and possibly misleading. This PR attempts to clarify a few points.

Types of changes

  • Documentation

To-do list

  • This PR is ready for review

@jamshark70 jamshark70 added the comp: help schelp documentation label Feb 23, 2019
all threads started within will inherit.
When a routine is created, it "inherits" its random number generator from the parent thread (link::Classes/Thread#.thisThread#thisThread::). If no particular randSeed is set (the normal case), it will tap the same stream of random number generators used by the parent.

The parent thread is whichever Routine is in force at the moment of creating a new Routine. If no Routine is evaluating at that moment, then the parent is the sclang process master link::Classes/Thread:: -- that is, the default from which all Routines inherit the random number generator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/master/main

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this last clause is a bit oddly worded -- consider "in other words, by default all Routines inherit their RNGs from the main thread". or just nixing it.

(see link::Classes/Thread#-parent::).
the Routine.

Time: Just before code::next:: is called, code::thisThread:: points either to another Routine, or the top-level Thread. During the code::next:: call, this becomes the "parent thread" (see link::Classes/Thread#-parent::). code::next:: then evaluates on the parent's clock, at the parent's logical time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scare quotes unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, 'at the parent's logical time' or 'on the parent's logical time'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll remove the quotes -- but I don't agree with the characterization as scare quotes. In technical writing, sometimes you have to introduce a phrase with a specific meaning that may not be obvious. It's fairly standard to highlight that in some way, either by emphasis or "quoting." (Or perhaps times have changed and quote marks are always "ironic" now.)

Definitely at a specific time.

I think I took care of all the changes now (hope I didn't miss one).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"scare quotes" also denote non-standard usage, while all of these usages (as far as i can tell) are consistent with their standard definition

In the SuperCollider application, a Routine can be played using a link::Classes/Clock::, as can any link::Classes/Stream::.
every time the Routine yields, it should do so with a float, the clock will interpret that, usually
pausing for that many seconds, and then resume the routine, passing it the clock's current time.
Schedules the Routine on the given link::Classes/Clock::, at a time specified by code::quant::. At that time, the routine will "awake," setting the clock and time and evaluating the routine. If the routine yields a number, this number of beats will be added to the current time and the routine will be rescheduled. (This behavior is compatible with scheduling a link::Classes/Stream:: or a link::Classes/Function::.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scare quotes unnecessary, parens unnecessary.

'wake up' is more standard terminology. Also would recommend capitalizing Routine throughout this paragraph

@@ -32,8 +32,11 @@ Array.fill(7, r);

subsection::Inheriting Seeds

Also it is possible to set the seed of the running thread that
all threads started within will inherit.
When a routine is created, it "inherits" its random number generator from the parent thread (link::Classes/Thread#.thisThread#thisThread::). If no particular randSeed is set (the normal case), it will tap the same stream of random number generators used by the parent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scare quotes unnecessary; capitalize Routine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is still unclear to me -- are the two routines sharing the same seed, or the same RNG object? i.e. if r1 spawns r2 and then each calls rand(), will they receive the same number?


The parent thread is whichever Routine is in force at the moment of creating a new Routine. If no Routine is evaluating at that moment, then the parent is the sclang process master link::Classes/Thread:: -- that is, the default from which all Routines inherit the random number generator.

To set the master random seed for the entire application, then, evaluate code::thisThread.randSeed = yourSeed:: outside of the context of any routine, as in the example below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/routine/Routine

@@ -52,6 +55,32 @@ thisThread.randSeed = 1923;
Array.fill(7, r.value);
::

When you set code::randSeed:: on a Routine, it switches to its own random number generator, independent of any other. Subsequently, routines created within the independent-RNG routine will inherit the separate random number generator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change first "it" to "Routine" for clarity. second sentence is a bit awkward, consider "Any new Routines created within the context of this Routine will inherit its unique RNG."

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@mossheim mossheim merged commit 36b5831 into supercollider:develop Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: help schelp documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants