Main
****

class psynet.trial.main.GenericTrialNetwork(*args, **kwargs)

   Bases: "TrialNetwork"

   The network holding a module's nodes for trials made by
   "Trial.cue()".

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   classmethod for_module(module_id, experiment)

      Return the module's network, creating it if needed.

   full

      Whether the network is currently full

   id

      a unique number for every entry. 1, 2, 3 and so on...

   max_size

      How big the network can get, this number is used by the full()
      method to decide whether the network is full

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   role

      The role of the network. By default dallinger initializes all
      networks as either "practice" or "experiment"

   time_of_death

      the time at which failing occurred

   type

      A String giving the name of the class. Defaults to "network".
      This allows subclassing.

   vars

class psynet.trial.main.GenericTrialNode(*args, **kwargs)

   Bases: "TrialNode"

   A node for trials made by "Trial.cue()", which have no trial maker.

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   get_default_network(module_id, experiment)

      Return the module's network for cued trials, creating it if
      needed.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   network

      the network the node is in

   network_id

      the id of the network that this node is a part of

   participant

      the participant the node is associated with

   participant_id

      the id of the participant whose node this is

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   time_of_death

      the time at which failing occurred

   type

      A String giving the name of the class. Defaults to "node". This
      allows subclassing.

   vars

class psynet.trial.main.NetworkTrialMaker(*, id_, trial_class, network_class, expected_trials_per_participant, check_performance_at_end, check_performance_every_trial, fail_trials_on_participant_performance_check, propagate_failure, recruit_mode, target_n_participants, n_repeat_trials, wait_for_networks, fail_trials_on_premature_exit=False, assets=None, sync_group_type=None, sync_group_max_wait_time=<class 'psynet.utils.NoArgumentProvided'>, sync_group_max_wait_action='fail', sync_group_late_after=None, sync_group_late_action=None, sync_group_also_leave=None, sync_group_waiting_message=None, sync_group_newcomer_max_wait=None, n_participants_completion='experiment')

   Bases: "TrialMaker"

   Trial maker for network-based experiments. These experiments are
   organised around networks in an analogous way to the network-based
   experiments in Dallinger. A "Network" comprises a collection of
   "Node" objects organised in some kind of structure. Here the role
   of "Node" objects is to generate "Trial" objects. Typically the
   "Node" object represents some kind of current experiment state,
   such as the last datum in a transmission chain. In some cases, a
   "Network" or a "Node" will be owned by a given participant; in
   other cases they will be shared between participants.

   An important feature of these networks is that their structure can
   change over time. This typically involves adding new nodes that
   somehow respond to the trials that have been submitted previously.

   This is an infrastructure base class. Concrete trial makers
   implement domain-specific discovery and selection hooks, then
   return the final node from "_select_trial_node()". The managed
   "prepare_trial()" implementation creates exactly one trial from
   that node.

   The trial is then administered to the participant, and a response
   elicited. Once the trial is finished, the network is given another
   opportunity to grow.

   The implementation also provides support for asynchronous
   processing, for example to prepare the stimuli available at a given
   node, or to postprocess trials submitted to a given node. There is
   some sophisticated logic to make sure that a participant is not
   assigned to a "Node" object if that object is still waiting for an
   async job, and likewise a trial won't contribute to a growing
   network if it is still pending the outcome of an async job.

   Experiment authors should use the public hooks on concrete classes
   such as "StaticTrialMaker" and "ChainTrialMaker", and should not
   override "prepare_trial".

   Parameters:
      * **trial_class** -- The class object for trials administered by
        this maker.

      * **network_class** -- The class object for the networks used by
        this maker. This should subclass
        :class`~psynet.trial.main.TrialNetwork`.

      * **expected_trials_per_participant** -- Expected number of
        trials that the participant will take, including repeat trials
        (used for progress estimation).

      * **check_performance_at_end** -- If "True", the participant's
        performance is evaluated at the end of the series of trials.

      * **check_performance_every_trial** -- If "True", the
        participant's performance is evaluated after each trial.

      * **fail_trials_on_premature_exit** ("bool") -- See
        "TrialMaker".

      * **fail_trials_on_participant_performance_check** -- See
        "TrialMaker".

      * **propagate_failure** -- If "True", the failure of a trial is
        propagated to other parts of the experiment (the nature of
        this propagation is left up to the implementation).

      * **recruit_mode** -- Selects a recruitment criterion for
        determining whether to recruit another participant. The built-
        in criteria are ""n_participants"" and ""n_trials"", though
        the latter requires overriding of "n_trials_still_required".
        Custom criteria can be added to "recruit_criteria". "None"
        leaves recruitment to the rest of the experiment.

      * **target_n_participants** -- Target number of participants to
        recruit for the experiment. Requires
        "recruit_mode="n_participants""; passing it with "None" or
        ""n_trials"" raises an error. Which completions fill the quota
        is controlled by "n_participants_completion".

      * **n_participants_completion** ("Literal"["'experiment'",
        "'trial_maker'"]) -- Which kind of completion counts toward
        "target_n_participants". ""experiment"" (default) counts
        participants who successfully finish the whole experiment.
        ""trial_maker"" counts participants who finish this
        TrialMaker, even if they later leave before the experiment end
        page. In-progress participants still occupy a slot in both
        cases, including people who have not yet reached this
        TrialMaker, so PsyNet does not immediately recruit a
        replacement. ""trial_maker"" raises an error with
        "recruit_mode=None" or ""n_trials"".

      * **n_repeat_trials** ("int") -- Number of repeat trials to
        present to the participant. These trials are typically used to
        estimate the reliability of the participant's responses.
        Defaults to "0".

      * **wait_for_networks** ("bool") -- If "True", then the
        participant will be made to wait if there are still more
        networks to participate in, but these networks are pending
        async jobs.

      * **sync_group_type** ("Optional"["str"]) -- Optional SyncGroup
        type to use for synchronizing participant allocation to nodes.
        When this is set, then the ordinary node allocation logic will
        only apply to the 'leader' of each SyncGroup. The other
        members of this SyncGroup will follow that leader around, so
        that in every given trial the SyncGroup works on the same node
        together. The other "sync_group_*" options raise an error
        without it.

      * **sync_group_max_wait_time** ("Union"["float", "Callable",
        "None"]) -- Acts on members waiting for their group at the
        trial maker's own barriers: the longest each may wait, in
        seconds, counted from their arrival, before
        "sync_group_max_wait_action" is applied to them. Defaults to
        45 seconds, or to no limit with "sync_group_late_after", which
        then moves slow members on; passing a number or a function
        together with "sync_group_late_after" raises an error, for the
        reason given under "max_wait_time" in "GroupBarrier". "None"
        means no limit.

      * **sync_group_max_wait_action** ("Literal"["'fail'",
        "'leave_group'"]) -- What happens to a member who waits longer
        than "sync_group_max_wait_time": ""fail"" (default) fails them
        and sends them to the end of the experiment; ""leave_group""
        removes them from the group, and they get no more trials from
        this trial maker, or skip the rest of it if they haven't
        finished a trial (see After leaving a group).

      * **sync_group_late_after** ("Optional"["float"]) -- Acts on
        members who haven't reached the trial maker's barrier yet: the
        longest each may take to reach it, in seconds, counted from
        the group's previous barrier pass or from when the group
        admitted them, whichever is later, before
        "sync_group_late_action" is applied to them. "None" (default)
        never treats anyone as late. See "late_after" in
        "GroupBarrier".

      * **sync_group_late_action** ("Optional"["Literal"["'fail'",
        "'leave_group'"]]) -- What happens to a member who is later
        than "sync_group_late_after", which requires it: ""fail""
        fails them; ""leave_group"" removes them from the group, so
        the rest can go on without them (see After leaving a group).
        See "late_action" in "GroupBarrier".

      * **sync_group_also_leave** ("Optional"["Sequence"["str"]]) --
        With "sync_group_late_action="leave_group"", the other group
        types a late member also leaves, for example "["cohort"]". See
        "also_leave" in "GroupBarrier".

      * **sync_group_waiting_message** -- Message on the waiting
        indicator at the trial maker's own sync-group wait (trial
        preparation). If omitted, participants see "Waiting for other
        participants…". "Grouper" and "GroupBarrier" elements use
        their own "waiting_message"; pass the same text to them if the
        messages should match.

      * **sync_group_newcomer_max_wait** ("Optional"["float"]) -- See
        "TrialMaker".

   check_timeout_interval_sec

      How often to check for trials that have timed out, in seconds
      (default = 30). Users are invited to override this.

      Type:
         float

   response_timeout_sec

      How long until a trial's response times out, in seconds (default
      = 300) (i.e. how long PsyNet will wait for the participant's
      response to a trial). This is a lower bound on the actual
      timeout time, which depends on when the timeout daemon next
      runs, which in turn depends on "check_timeout_interval_sec".
      Users are invited to override this.

      Type:
         float

   async_timeout_sec

      How long an async job may run before it times out, in seconds
      (default = 300), counted from when the job starts running, not
      from when it is queued. This is a lower bound on the actual
      timeout time, which depends on when the timeout daemon next
      runs, which in turn depends on "check_timeout_interval_sec".
      Users are invited to override this.

      Type:
         float

   network_query

      An SQLAlchemy query for retrieving all networks owned by the
      current trial maker. Can be used for operations such as the
      following: "self.network_query.count()".

      Type:
         sqlalchemy.orm.Query

   n_networks

      Returns the number of networks owned by the trial maker.

      Type:
         int

   networks

      Returns the networks owned by the trial maker.

      Type:
         list

   end_performance_check_waits

      If "True" (default), then the final performance check waits
      until all trials no longer have any pending async jobs, and
      until trials that are ready to finalize have been finalized (so
      their scores are set).

      Type:
         bool

   performance_threshold

      Threshold for the built-in performance check chosen by
      "performance_check_type". The participant passes when the score
      (the summed trial scores, the proportion of non-failed trials,
      or the consistency) is at least this value. This is used in
      "performance_check()".

      Type:
         float (default = -1.0)

   check_initialization()

      Validate trial-maker hooks after construction.

   compute_performance_reward(score, passed)

      Computes the performance reward to allocate to the participant
      at the end of a trial maker on the basis of the results of the
      final performance check. Note: if *check_performance_at_end =
      False*, then this function will not be run and the performance
      reward will not be assigned.

   get_trial_class(node, participant, experiment)

      Returns the class of trial to be used for this trial maker.

      This must return a trial class for every eligible selection.
      Filter unavailable values in the concrete trial maker's
      eligibility hooks instead of returning "None" here. Synchronized
      follower trials reuse the leader trial's concrete class and do
      not call this hook again.

   grow_network(network, experiment)

      Extends the network if necessary by adding one or more nodes.
      Returns "True" if any nodes were added.

      Parameters:
         * **network** -- The network to be potentially extended.

         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

   on_trial_created(trial, experiment, participant, selection_context=None)

      Run after a selected network trial is fully prepared.

      Override this hook to create records that must correspond to the
      exact trial assignment, such as an adaptive-selection decision.
      The trial and any related records are committed in the same
      transaction; its database ID may therefore remain unset until
      the session is flushed. This hook runs for primary trials
      created through the managed network-selection pipeline, not for
      repeat trials or synchronized follower copies.

      Trial-specific definition and assets belong in
      "finalize_definition()". Those assets are deposited and
      snapshotted before this hook runs.

      Parameters:
         * **trial** -- The newly created "Trial".

         * **experiment** -- The current "Experiment".

         * **participant** -- The participant to whom the trial was
           assigned.

         * **selection_context** -- Request-local information returned
           with a "Selection", or "None" when the selection hook
           returned its value directly.

   performance_check(experiment, participant, participant_trials)

      Defines an automated check for evaluating the participant's
      current performance. The default behaviour is to take the sum of
      the trial 'scores' (as computed by the Trial.score_answer), but
      this can be overridden if desired.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

         * **participant_trials** -- A list of all trials completed so
           far by the participant.

      Returns:
         * *dict* -- The dictionary should include the following
           values:

           * "score", expressed as a "float" or "None".

           * "passed" (Boolean), identifying whether the participant
             passed the check.

   prepare_trial(experiment, participant)

      Prepares and returns a trial to administer the participant.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** ("Participant") -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

      Returns:
         * A tuple of ("Trial", "str"), where the first is a Trial
           object,

         * *and the second is a status string.*

   state_class

      alias of "NetworkTrialMakerState"

class psynet.trial.main.NetworkTrialMakerState(*args, **kwargs)

   Bases: "TrialMakerState"

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   run_index

      Counts the participant's visits to the module, from 1, as when a
      loop repeats it.

   time_of_death

      the time at which failing occurred

   type

   vars

class psynet.trial.main.Selection(value, context=None)

   Bases: "object"

   A selected value together with optional request-local context.

class psynet.trial.main.Trial(*args, **kwargs)

   Bases: "Base", "SQLMixin", "AssetParentMixin"

   Represents a trial in the experiment. The user is expected to
   override the following methods:

   * "make_definition()", responsible for deciding on the content of
     the trial.

   * "show_trial()", determines how the trial is turned into a webpage
     for presentation to the participant.

   * "show_feedback()", defines an optional feedback page to be
     displayed after the trial.

   The user must also override the "time_estimate" class attribute,
   providing the estimated duration of the trial in seconds. This is
   used for predicting the participant's performance reward and for
   constructing the progress bar.

   The user may also wish to override the "async_post_trial()" method
   if they wish to implement asynchronous trial processing.

   They may also override the "score_answer()" method if they wish to
   implement trial-level scoring; for scoring methods that work by
   analyzing multiple trials at the same time (e.g., test-retest
   correlations), see the trial maker method "performance_check()".

   Trials are stored in the physical "trial" table. Custom trial
   classes use single-table polymorphism within that table.

   Instances can be retrieved using *SQLAlchemy*; for example, the
   following command retrieves the "Trial" object with an ID of 1:

      Trial.query.filter_by(id=1).one()

   Parameters:
      * **experiment** -- An instantiation of
        "psynet.experiment.Experiment", corresponding to the current
        experiment.

      * **node** -- An object of class "dallinger.models.Node" to
        which the "Trial" object should be attached. Complex
        experiments are often organised around networks of nodes, but
        in the simplest case one could just make one "Network" for
        each type of trial and one "Node" for each participant, and
        then assign the "Trial" to this "Node". Ask us if you want to
        use this simple use case - it would be worth adding it as a
        default to this implementation, but we haven't done that yet,
        because most people are using more complex designs.

      * **participant** -- An instantiation of
        "psynet.participant.Participant", corresponding to the current
        participant.

      * **propagate_failure** (*bool*) -- Whether failure of a trial
        should be propagated to other parts of the experiment
        depending on that trial (for example, subsequent parts of a
        transmission chain).

   time_estimate

      The estimated duration of the trial (including any feedback), in
      seconds. This should generally correspond to the (sum of the)
      "time_estimate" parameters in the page(s) generated by
      "show_trial", plus the "time_estimate" parameter in the page
      generated by "show_feedback" (if defined). This is used for
      predicting the participant's performance reward and for
      constructing the progress bar.

      Type:
         numeric

   participant_id

      The ID of the associated participant. The user should not
      typically change this directly.

      Type:
         int

   node

      The "dallinger.models.Node" to which the "Trial" belongs.

   finalized

      Whether the trial has been finalized. This is a stronger
      condition than "complete"; in particular, a trial is only marked
      as finalized once its async jobs have completed (if it has any).
      One day we might extend this to include arbitrary conditions,
      for example waiting for another user to evaluate that trial, or
      similar.

      Type:
         bool

   answer

      The response returned by the participant. This is serialised to
      JSON, so it shouldn't be too big. The user should not typically
      change this directly. While the trial's pages are being
      answered, it holds the answer so far, as it would be in
      "participant.answer", so that for example a "GroupBarrier"
      inside "show_trial()" can read it in "on_release": with
      "accumulate_answers", a dict that starts empty, and otherwise
      "None" until the first page is answered. When the trial ends, it
      is set to the result of "format_answer()".

      Type:
         Object

   parent_trial_id

      If the trial is a repeat trial, this attribute corresponds to
      the ID of the trial from which that repeat trial was cloned.

      Type:
         int

   propagate_failure

      Whether failure of a trial should be propagated to other parts
      of the experiment depending on that trial (for example,
      subsequent parts of a transmission chain).

      Type:
         bool

   var

      A repository for arbitrary variables; see "VarStore" for
      details.

      Type:
         "VarStore"

   definition

      An arbitrary Python object that somehow defines the content of a
      trial. Often this will be a dictionary comprising a few named
      parameters. The user should not typically change this directly,
      as it is instead determined by "make_definition()".

      Type:
         Object

   run_async_post_trial

      Set this to "False" if you want to disable "async_post_trial()".
      This is only included for back-compatibility.

      Type:
         bool

   wait_for_feedback

      By default, feedback waits until the trial is finalized or
      failed, so that "show_feedback()" sees the results of async jobs
      and "on_finalized()". Set this class attribute to "False" to
      give feedback straight away; "show_feedback" may then see a
      trial whose async jobs are still running and whose "score" is
      not yet set.

      Type:
         bool

   async_post_trial_priority

      Priority of the "async_post_trial()" job, ""high"" or ""low"";
      see "WorkerAsyncJob". If "None" (default), it is ""high"" when a
      participant may wait for the result, i.e. when the trial maker
      checks performance, when it is a within-participant chain trial
      maker ("chain_type="within""), whose next trial waits for this
      one to be finalized, or when the trial overrides
      "show_feedback()" or "gives_feedback()" with "wait_for_feedback"
      set; it is ""low"" otherwise.

      Type:
         str or None

   accumulate_answers

      Set this class attribute to "True" if the trial contains
      multiple pages and you want the answers to all of these pages to
      be stored as a dict in "participant.answer", keyed by page
      label. The dict fills up as each page is submitted, so later
      pages can read earlier answers. Otherwise, the default behaviour
      is to only store the answer from the final page.

      Type:
         bool

   sync_group_type

      Set this class attribute to a group type to make "cue()" play
      the trial with the participant's group of that type: the trials
      that the group's members cue in one round share one
      "SyncGroupRound" ("group_round"), and each trial records the
      group, the participant's role and the round. Only used by
      "cue()"; trial makers take "sync_group_type" as an argument
      instead, and make one round each time they prepare the group's
      trials.

      Type:
         str or None

   sync_group_optional

      With "sync_group_type", set this class attribute to "True" to
      let "cue()" give a participant who is in no such group, for
      example because they left it, an ungrouped trial on the module's
      default node. "False" (default) raises an error instead, which
      usually means the cue needs a "conditional()" on
      "participant.in_sync_group(...)".

      Type:
         bool

   time_credit_before_trial

      Reports the amount of time credit that the participant had
      before they started the trial (in seconds).

      Type:
         float

   time_credit_after_trial

      Reports the amount of time credit that the participant had after
      they finished the trial (in seconds).

      Type:
         float

   time_credit_from_trial

      Reports the amount of time credit that was allocated to the
      participant on the basis of this trial (in seconds). This should
      be equal to "time_credit_after_trial -
      time_credit_before_trial".

      Type:
         float

   progress_before_trial

      Reports the progress that the participant had before they
      started the trial. Mainly useful for debugging.

      Type:
         float

   progress_after_trial

      Reports the progress that the participant had after they
      finished the trial. Mainly useful for debugging.

      Type:
         float

   check_time_credit_received

      If "True" (default), PsyNet will check at the end of the trial
      whether the participant received the expected amount of time
      credit. If the received amount is inconsistent with the amount
      specified by "time_estimate", then a warning message will be
      delivered, suggesting a revised value for "time_estimate".
      Trials played in a group (with "sync_group_id") are not checked,
      because by default their barriers credit the time actually spent
      waiting for the others.

      Type:
         bool

   response_id

      ID of "response".

      Type:
         int

   response

      The "Response" from the last accepted page of "show_trial()"
      (normally the one that completed the trial), which records in
      detail what the participant's web browser sent. With several
      pages (for example with "accumulate_answers"), find every
      response of the trial, including rejected submissions, through
      "psynet.timeline.Response.trial_id". Equals "None" until the
      participant submits a trial page.

   time_taken

      Time in seconds that the participant spent on the pages of
      "show_trial()", summed over its pages. Each page counts from
      when it loaded to when its answer was accepted, so a submission
      rejected by validation adds nothing of its own, and a page that
      submits itself (for example when a recording or countdown ends)
      counts up to that submission. Feedback pages are not included. A
      trial failed by "response_timeout_sec" keeps the time of the
      pages answered so far, and of any the participant answers
      afterwards. Pages submitted after the participant fails, such as
      the unsuccessful-end page, are not included. Bots report each
      page's "time_estimate". A page that reports no time, such as
      "UnityPage", adds nothing, so a trial whose pages are all of
      that kind keeps "None". Equals "None" until the participant
      submits a trial page.

      Type:
         float

   time_limit_reached

      Whether the "time_limit" of the trial's latest timed page ran
      out before it was answered, as in
      "psynet.timeline.Response.time_limit_reached". It is set when a
      page of "show_trial()" with a "time_limit" is accepted, and kept
      through later untimed pages, barrier waits and feedback; timed
      pages shown while the participant waits at a barrier don't set
      it either. So for example a "GroupBarrier"'s "on_release" can
      read it after a waiting page. Equals "None" until a timed page
      of the trial is answered.

      Type:
         bool or None

   async_post_trial()

      Optional function to be run after a trial is completed by the
      participant. Will only run if "run_async_post_trial" is set to
      "True".

   async_post_trial_blocks_finalization

      Whether async post-trial prevents finalization.

      Stricter than "async_post_trial_pending": if async was
      requested, it must have *succeeded*
      ("async_post_trial_complete") before the trial may finalize.
      Failed async therefore blocks finalization even though it is no
      longer "pending".

   async_post_trial_pending

      Whether async post-trial work is still in flight.

      Used for feedback / wait loops. This is *not* the finalize gate:
      finalize requires async success when requested (see
      "async_post_trial_blocks_finalization"), so a failed async does
      not count as pending here but still blocks finalization.

   property async_processes

      Deprecated alias of "async_jobs".

   check_if_can_mark_as_finalized()

      Finalize the trial when complete and no blockers remain.

      Intermediate waiting states log at debug; callers and the
      finalize backstop poller re-check as preconditions clear.

      Async post-trial is a success gate, not merely a pending check:
      if async was requested, it must have completed successfully
      before finalization (failed async must not finalize).

   complete

      Whether the trial has been completed (i.e. received a response
      from the participant). It is set once all of "show_trial()"'s
      pages have ended, before "show_feedback()", and also when a
      barrier's release ends the trial's page in "waiting_logic"
      before it is answered, in which case the trial is failed with
      "failed_reason="interrupted_by_release"", not finalized, and
      gets no "show_feedback()". The user should not typically change
      this directly.

   compute_performance_reward(score)

      Computes a performance reward to allocate to the participant as
      a reward for the current trial. By default, no performance
      reward is given. Note: this trial-level performance reward
      system is complementary to the trial-maker-level performance
      reward system, which computes an overall performance reward for
      the participant at the end of a trial maker. It is possible to
      use these two performance reward systems independently or
      simultaneously. See "compute_performance_reward()" for more
      details.

      Parameters:
         **score** -- The score achieved by the participant, as
         computed by "score_answer()".

      Returns:
         * *The resulting performance reward, typically in dollars.*

   creation_time

      the time at which the Network was created.

   classmethod cue(definition=None, assets=None, on_trial_created=None, creation_context=None, *, round=None)

      Use this method to add a trial directly into a timeline, without
      needing to create a corresponding trial maker.

      If the trial class sets "sync_group_type", the trial is played
      with the participant's group of that type: the trials that the
      group's members cue in one module and round share one
      "SyncGroupRound" ("group_round"), whose "var" holds the group's
      results for the round. Grouped trials use the module's default
      node, like ungrouped ones. "cue" numbers each group's rounds
      from 0 by itself: a cue joins the group's newest round while it
      is open, that is until a barrier of that round releases the
      group, and otherwise starts the next. Newcomers take part from
      an admission point (see Admission points), so put one before the
      round, such as a "GroupBarrier(admission_point=True)" at the
      start of each round; a pending member who reaches a cue raises
      an error. Each trial records "sync_group_id", "sync_group_role"
      and "sync_group_round"; see Rounds of cued trials for the rules.
      In short:

      * Put a "GroupBarrier" in "show_trial()", so that members stay
        in step and the round closes; a grouped trial whose
        "show_trial" has none raises an error.

      * The barriers' "on_release" can read each member's answer so
        far from "trial.answer", and whether their timed page ran out
        of time from "time_limit_reached". With several answer pages
        before a barrier, set "accumulate_answers" to get them all.

      * In a loop of rounds played by a fixed group, pass the loop
        value as "round", so that a definition can come from the loop.
        Otherwise a grouped cue's definition must not depend on the
        player's own position in a loop; pass a function taking
        "round" or "group".

      * Each cued trial's "position" counts the participant's earlier
        trials in the current module from 0, grouped or not; it is
        "None" outside a module.

      * A participant who is in no group of that type raises an error,
        unless the trial class sets "sync_group_optional", when they
        get an ungrouped trial on the module's default node. Otherwise
        put the cue in a "conditional()" on
        "participant.in_sync_group(...)". Once started, the trial runs
        to its end even if they leave the group, so "show_feedback()"
        can explain every outcome.

      * "sync_group_outcome" records how the round ended for the
        player: ""stayed"" once a barrier in the trial's pages
        releases the group with them in it, after which it doesn't
        change; before that, why they left the group. A partner's is
        on their trial in "self.group_round.trials".

      Parameters:
         * **definition** -- This can be a "dict" object of plain
           JSON-like values, which will then be saved to the trial's
           "definition" slot. Alternatively, it can be a "ChainNode",
           which will be saved to "trial.node", and whose "definition"
           will be saved to "trial.definition". It can also be a
           function returning the "dict", taking any of "group",
           "round", "participant" and "experiment". With
           "sync_group_type", the round's first cue sets the round's
           definition, which every trial in the round gets: a function
           is only called then, with "participant" set to that first
           member, and a later cue with a different "dict" raises a
           "ValueError". Otherwise a function is called for each
           trial, with "group=None". Defaults to "{}", for a trial
           whose pages need no content from it, for example
           "PickTrial.cue(round=i)".

         * **assets** -- Optional dictionary of assets to add to the
           trial (in addition to any provided by providing a "Source"
           containing assets to the "definition" parameter).

         * **on_trial_created** -- Optional callback executed after
           the trial and its assets have been created. The callback
           runs in the same transaction as trial creation and may
           accept "trial", "experiment", "participant", and
           "creation_context" arguments. It should add related records
           to the current session without committing. Prefer a module-
           level function so the callback remains straightforward to
           serialize.

         * **creation_context** -- Optional request-local value passed
           to "on_trial_created". This is useful for recording
           adaptive-selection provenance without adding it to the
           participant-facing trial definition.

         * **round** -- The group's round to put this trial in, a non-
           negative integer, instead of the automatic one. Pass the
           loop value when a fixed group plays a loop of rounds, or
           the same value to the cues of two trial classes played one
           after the other in one round. A round closes when a
           "GroupBarrier" releases the group there, so "show_trial"
           must contain one; building a grouped trial's pages without
           one raises an error. Cueing a closed round in which the
           participant has no trial raises an error: members admitted
           at an admission point before the round are always in it.
           Rounds are ordered by when the group first plays them, not
           by number. A module whose cues pass "round" runs once per
           participant, so give each run of it its own module id: its
           cues raise an error if the participant has run the module
           before. Cueing a round again after a later one, or a trial
           class again in the same round, also raises an error. Only
           for a trial class that sets "sync_group_type", and not with
           a regrouper, whose groups mix players at different loop
           positions. For a participant without a group (with
           "sync_group_optional"), "round" doesn't select a round:
           they get an ungrouped trial. See a fixed group's loop.

      -[ Examples ]-

         class PickTrial(Trial):
             sync_group_type = "room"
             time_estimate = 15

             def show_trial(self, experiment, participant):
                 return join(
                     ModularPage(
                         "pick",
                         "Pick a number.",
                         PushButtonControl([1, 2, 3, 4, 5]),
                         time_estimate=5,
                     ),
                     GroupBarrier(
                         id_="round_finished",
                         group_type="room",
                         on_release=self.score_room,
                     ),
                 )

             @classmethod
             def score_room(cls, trials, group_round):
                 group_round.var.picks = [t.answer for t in trials]

         # A fixed room plays rounds 0, 1 and 2; PickTrial would need
         # sync_group_optional = True for a player who leaves it to play
         # the remaining rounds alone. The Module gives the rounds a
         # module_id, for example to find them by with group.rounds().
         join(
             SimpleGrouper("room", initial_group_size=4),
             Module(
                 "game",
                 for_loop(
                     label="rounds",
                     iterate_over=range(3),
                     logic=lambda i: PickTrial.cue(
                         {"numbers": [1, 2, 3, 4, 5], "round": i}, round=i
                     ),
                     time_estimate_per_iteration=20,
                 ),
             ),
         )

   details = None

      a generic column for storing structured JSON data

   fail(reason=None)

      Fail this object, and potentially its related objects.

      Set "failed" to "True" and "time_of_death" to now.

      If a *reason* argument is passed, this will be stored in
      "failed_reason".

      Failure will then be propagated to related objects as defined by
      the *failure_cascade* property.

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   finalize_definition(definition, experiment, participant)

      This can be overridden to add additional randomized trial
      properties. For example:

         definition["bass_note"] = random.sample(10)

      It can also be used to add OnDemandAsset:

         self.add_assets({
             "audio": OnDemandAsset(
                 function=synth_stimulus,
                 extension=".wav",
             )

   classmethod finalize_pending_trials()

      Backstop for missed event-driven finalize checks.

      The participant response path, asset deposit callbacks, and
      async post-trial completion remain the fast path. This method
      recovers trials that became ready without those callbacks
      running.

      Failures are isolated per trial (same idea as network growth):
      one bad "on_finalized" must not leave the whole candidate set
      retrying forever. Each trial runs in a savepoint, so a failure
      undoes only that trial's work, and the trial is marked failed.

   format_answer(raw_answer, **kwargs)

      Optional function to be run after a trial is completed by the
      participant.

   classmethod get_default_parent_node(participant, experiment)

      Return the module's shared node for ungrouped cued trials,
      creating it if needed.

   classmethod get_for_participant(participant_id, trial_maker_id=None)

      Returns all trials for a given participant.

   classmethod get_trials_ready_to_finalize()

      Return trials that appear ready to finalize, locking them for
      update.

      Known blockers (undeposited assets, pending async post-trial)
      are excluded in SQL so the steady-state result is empty.

      Locks participants "FOR NO KEY UPDATE" and then trials "FOR
      UPDATE", both "SKIP LOCKED", so the poller does not block when
      participant requests or async workers already hold a lock on the
      trial or its participant.

   group_round

      The "SyncGroupRound" this trial was played in, shared with the
      trials of the other members in the round, or "None" for
      ungrouped trials. Its "var" holds the group's results for the
      round, and "group_round.trials" the partners' trials.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   json_data()

      Returns a JSON serializable "dict" ("datetime" values allowed)
      to describe this object. This method can be overridden by sub-
      classes to extend the default model data used for display in the
      Dashboard Network Monitor and Database views.

      Returns:
         "dict" with JSON serializable data

   make_definition(experiment, participant)

      Creates and returns a definition for the trial, which will be
      later stored in the "definition" attribute. This can be an
      arbitrary object as long as it is serialisable to JSON.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

   position

      Zero-based creation position among all trials from this trial
      maker for the participant, or, for trials made by "Trial.cue()",
      among the participant's trials in the same module.

   property1 = None

      a generic column that can be used to store experiment-specific
      details in String form.

   property2 = None

      a generic column that can be used to store experiment-specific
      details in String form.

   property3 = None

      a generic column that can be used to store experiment-specific
      details in String form.

   property4 = None

      a generic column that can be used to store experiment-specific
      details in String form.

   property5 = None

      a generic column that can be used to store experiment-specific
      details in String form.

   property ready_for_feedback

      Whether the trial is ready to give feedback to the participant.

      With "wait_for_feedback", feedback waits until the trial is
      finalized (so "on_finalized()" has run and "score" is set) or
      failed, so "show_feedback()" sees one of those two states.

   classmethod ready_to_finalize_id_select()

      Select IDs of trials that appear ready to finalize.

   classmethod recheck_finalization(trial_id)

      Lock a trial, reload it, and finalize it if it is now ready.

      Finalize checks inside a transaction read attributes cached when
      the trial was loaded, so two transactions that each clear one
      blocker (e.g. the participant response and "async_post_trial")
      can both miss the other's change. Async workers call this in a
      fresh transaction after committing, so the last committer
      finalizes the trial without waiting for
      "finalize_pending_trials()". Leaves committing to the caller.

   score_answer(answer, definition)

      Scores the participant's answer. At the point that this method
      is called, any pending async jobs should already have been
      completed.

      Parameters:
         * **answer** -- The answer provided to the trial.

         * **definition** -- The trial's definition

      Returns:
         * *A numeric score quantifying the participant's success.*

         * *The experimenter is free to decide the directionality*

         * *(whether high scores are better than low scores, or vice
           versa).*

         * Alternatively, "None" indicating no score.

   show_feedback(experiment, participant)

      Returns a Page object displaying feedback (or None, which means
      no feedback).

      Unless "wait_for_feedback" is "False", the trial is either
      finalized, so "on_finalized()" has run and "score" is set, or
      failed, in which case "score" may be unset. Check "self.failed"
      and "self.failed_reason" to give feedback on a failed trial, for
      example a recording that the analysis rejected.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

   show_trial(experiment, participant)

      Returns a "Page" object, or alternatively a list of such
      objects, that solicits an answer from the participant.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

   property sync_group: SyncGroup | None

      The "SyncGroup" that the trial was played in ("sync_group_id"),
      or "None" if the trial is not synchronised or the participant
      was in no group of that type when the trial was created. The
      group is returned even if the participant has left it since.

   sync_group_id

      The group of the trial maker's (or, for cued trials, the trial
      class's) "sync_group_type" that the participant was in when the
      trial was created, kept after the group ends.

   sync_group_outcome

      when the trial maker prepares the group's next trials,
      ""stayed"" is written on the complete trials of the members
      still in the group. "None" while nothing has happened yet, and
      for ungrouped trials.

      Type:
         How the group's round ended for this player, for a trial in a
         group's round ("group_round"), one of "SyncGroupOutcome". It
         is written during the trial's pages, that is, before
         "complete" is set

      Type:
         ""stayed"" once a "GroupBarrier" in those pages, such as in
         "show_trial()", releases the group with the player in it,
         after which it doesn't change. Before that, why the player
         left the group, one of the reasons of "remove_participant()",
         such as ""late"", ""waited_too_long"", ""left_experiment"" or
         ""group_dissolved"" or ""removed_by_experimenter"". Leaving
         after a release, for example by being late at a later
         barrier, shows in "sync_group_removal_reason()" and in the
         "left" of the next barrier's "on_release" instead. Barriers
         and departures after the trial's pages, such as in
         "show_feedback()" or between rounds, write nothing. The
         exception is a trial maker's round that no barrier in the
         trial's pages released

   sync_group_role

      The participant's role in "sync_group_id", if a Regrouper gave
      one.

   sync_group_round

      Which round of "sync_group_id" this trial belongs to, counted
      from 0. A member who joined the group late shares the group's
      numbers. In a trial maker, a leader told to wait gives the group
      no trials, so the followers wait too and no number is used up.
      It equals the "number" of "group_round".

   sync_group_round_id

      ID of "group_round".

   time_of_death

      the time at which failing occurred

   to_dict()

      Determines the information that is shown for this object in the
      dashboard.

   type

   vars

   property visualization_html

      str(object='') -> str str(bytes_or_buffer[, encoding[, errors]])
      -> str

      Create a new string object from the given object. If encoding or
      errors is specified, then the object must expose a data buffer
      that will be decoded using the given encoding and error handler.
      Otherwise, returns the result of object.__str__() (if defined)
      or repr(object). encoding defaults to 'utf-8'. errors defaults
      to 'strict'.

class psynet.trial.main.TrialMaker(*, id_, trial_class, expected_trials_per_participant, check_performance_at_end, check_performance_every_trial, fail_trials_on_participant_performance_check, propagate_failure, recruit_mode, target_n_participants, n_repeat_trials, assets, fail_trials_on_premature_exit=False, sync_group_type=None, sync_group_max_wait_time=<class 'psynet.utils.NoArgumentProvided'>, sync_group_max_wait_action='fail', sync_group_late_after=None, sync_group_late_action=None, sync_group_also_leave=None, sync_group_waiting_message=None, sync_group_newcomer_max_wait=None, n_participants_completion='experiment')

   Bases: "Module"

   Generic trial generation module, to be inserted in an experiment
   timeline. It is responsible for organising the administration of
   trials to the participant.

   Users are invited to override the following abstract
   methods/attributes:

   * "prepare_trial()", which prepares the next trial to administer to
     the participant.

   * "pre_deploy_routine()" (optional), which defines a routine that
     sets up the experiment in advance of deployment (for example
     initialising and seeding networks).

   * "init_participant()" (optional), a function that is run when the
     participant begins this sequence of trials, intended to
     initialize the participant's state. With "sync_group_type", it
     runs when the trial preparation first releases the participant
     with their group, just before their first trial. Make sure you
     call "super().init_participant" when overriding this.

   * "finalize_trial()" (optional), which finalizes the trial after
     the participant has given their response.

   * "on_complete()" (optional), run once the sequence of trials is
     complete.

   * "performance_check()" (optional), which checks the performance of
     the participant with a view to rejecting poor-performing
     participants.

   * "compute_performance_reward()"; computes the final performance
     reward to assign to the participant.

   * "n_trials_still_required" (optional), which is used to estimate
     how many more participants are still required in the case that
     "recruit_mode="n_trials"".

   * "give_end_feedback_passed" (default = "False"); if "True", then
     participants who pass the final performance check will be given
     feedback. This feedback can be customised by overriding
     "get_end_feedback_passed_page()".

   Users are also invited to add new recruitment criteria for
   selection with the "recruit_mode" argument. This may be achieved
   using a custom subclass of "TrialMaker" as follows:

      class CustomTrialMaker(TrialMaker):
          def new_recruit(self, experiment):
              if experiment.my_condition:
                  return True # True means recruit more
              else:
                  return False # False means don't recruit any more (for now)

          recruit_criteria = {
              **TrialMaker.recruit_criteria,
              "new_recruit": new_recruit
          }

   With the above code, you'd then be able to use
   "recruit_mode="new_recruit"". If you're subclassing a subclass of
   "TrialMaker", then just replace that subclass wherever "TrialMaker"
   occurs in the above code.

   Parameters:
      * **trial_class** -- The class object for trials administered by
        this maker.

      * **expected_trials_per_participant** ("Union"["int", "float"])
        -- Expected number of trials that the participant will take,
        including repeat trials (used for progress estimation).

      * **check_performance_at_end** ("bool") -- If "True", the
        participant's performance is evaluated at the end of the
        series of trials.

      * **check_performance_every_trial** ("bool") -- If "True", the
        participant's performance is evaluated after each trial.

      * **fail_trials_on_premature_exit** ("bool") -- Deprecated.
        Premature exit no longer fails completed trials. Incomplete
        trials are always failed when the participant fails or exits.
        This argument is accepted for backwards compatibility and
        ignored. It is not stored on the trial maker.

      * **fail_trials_on_participant_performance_check** ("bool") --
        If "True", a participant's completed trials for this
        TrialMaker are marked as failed when the participant fails a
        performance check, because those responses are treated as
        unusable. Incomplete trials are always failed on any
        participant failure, regardless of this setting. Subclasses
        document their own defaults.

      * **propagate_failure** ("bool") -- If "True", the failure of a
        trial is propagated to other parts of the experiment (the
        nature of this propagation is left up to the implementation).

      * **recruit_mode** ("str") -- Selects a recruitment criterion
        for determining whether to recruit another participant. The
        built-in criteria are ""n_participants"" and ""n_trials"",
        though the latter requires overriding of
        "n_trials_still_required". Custom criteria can be added to
        "recruit_criteria". "None" leaves recruitment to the rest of
        the experiment.

      * **target_n_participants** ("Optional"["int"]) -- Target number
        of participants to recruit for the experiment. Requires
        "recruit_mode="n_participants""; passing it with "None" or
        ""n_trials"" raises an error. Which completions fill the quota
        is controlled by "n_participants_completion".

      * **n_participants_completion** ("Literal"["'experiment'",
        "'trial_maker'"]) -- Which kind of completion counts toward
        "target_n_participants". ""experiment"" (default) counts
        participants who successfully finish the whole experiment.
        ""trial_maker"" counts participants who finish this
        TrialMaker, even if they later leave before the experiment end
        page. In-progress participants still occupy a slot in both
        cases, including people who have not yet reached this
        TrialMaker, so PsyNet does not immediately recruit a
        replacement. ""trial_maker"" raises an error with
        "recruit_mode=None" or ""n_trials"".

      * **n_repeat_trials** ("int") -- Number of repeat trials to
        present to the participant. These trials are typically used to
        estimate the reliability of the participant's responses.
        Defaults to "0".

   check_timeout_interval_sec

      How often to check for timeouts, in seconds (default = 30).
      Users are invited to override this.

      Type:
         float

   response_timeout_sec

      How long until a trial's response times out, in seconds (default
      = 300) (i.e. how long PsyNet will wait for the participant's
      response to a trial). This is a lower bound on the actual
      timeout time, which depends on when the timeout daemon next
      runs, which in turn depends on "check_timeout_interval_sec".
      Users are invited to override this.

      Type:
         float

   async_timeout_sec

      How long an async job may run before it times out, in seconds
      (default = 300), counted from when the job starts running, not
      from when it is queued. This is a lower bound on the actual
      timeout time, which depends on when the timeout daemon next
      runs, which in turn depends on "check_timeout_interval_sec".
      Users are invited to override this.

      Type:
         float

   introduction

      An optional event or list of elts to execute prior to beginning
      the trial loop.

   give_end_feedback_passed

      If "True", then participants who pass the final performance
      check are given feedback. This feedback can be customised by
      overriding "get_end_feedback_passed_page()".

      Type:
         bool

   performance_threshold

      Threshold for the default performance check, defaults to 0.0.
      The participant passes when the sum of trial scores exceeds this
      value.

      Type:
         float

   end_performance_check_waits

      If "True" (default), then the final performance check waits
      until all trials no longer have any pending async jobs, and
      until trials that are ready to finalize have been finalized (so
      their scores are set).

      Type:
         bool

   sync_group_type

      Optional SyncGroup type to use for synchronizing participant
      allocation to nodes. When this is set, then the ordinary node
      allocation logic will only apply to the 'leader' of each
      SyncGroup. The other members of this SyncGroup will follow that
      leader around, so that in every given trial the SyncGroup works
      on the same node together. The other "sync_group_*" options
      raise an error without it.

   sync_group_max_wait_time

      Acts on members waiting for their group at the trial maker's own
      barriers: the longest each may wait, in seconds, counted from
      their arrival, before "sync_group_max_wait_action" is applied to
      them. Defaults to 45 seconds, or to no limit with
      "sync_group_late_after", which then moves slow members on;
      passing a number or a function together with
      "sync_group_late_after" raises an error, for the reason given
      under "max_wait_time" in "GroupBarrier". "None" means no limit.

   sync_group_max_wait_action

      What happens to a member who waits longer than
      "sync_group_max_wait_time": ""fail"" (default) fails them and
      sends them to the end of the experiment; ""leave_group"" removes
      them from the group, and they get no more trials from this trial
      maker, or skip the rest of it if they haven't finished a trial
      (see After leaving a group).

   sync_group_late_after

      Acts on members who haven't reached the trial maker's barrier
      yet: the longest each may take to reach it, in seconds, counted
      from the group's previous barrier pass or from when the group
      admitted them, whichever is later, before
      "sync_group_late_action" is applied to them. "None" (default)
      never treats anyone as late. See "late_after" in "GroupBarrier".

   sync_group_late_action

      What happens to a member who is later than
      "sync_group_late_after", which requires it: ""fail"" fails them;
      ""leave_group"" removes them from the group, so the rest can go
      on without them (see After leaving a group). See "late_action"
      in "GroupBarrier".

   sync_group_also_leave

      With "sync_group_late_action="leave_group"", the other group
      types a late member also leaves, for example "["cohort"]". See
      "also_leave" in "GroupBarrier".

   sync_group_waiting_message

      Message on the waiting indicator at the trial maker's own sync-
      group wait (trial preparation). If omitted, participants see
      "Waiting for other participants…". "Grouper" and "GroupBarrier"
      elements use their own "waiting_message"; pass the same text to
      them if the messages should match.

   check_fail_logic()

      Determines the timeline logic for when a participant fails the
      performance check. By default, the participant is shown an
      "UnsuccessfulEndPage".

      Returns:
         * An "Elt" or a list of "Elt" s.

   cue_trial()

      You can use this in combination with init_participant to
      administer trials outside of a trialmaker.

   fail_participant_trials(participant, reason=None)

      Fail this TrialMaker's non-failed trials for a participant.

      Parameters:
         * **participant** -- The participant whose trials should be
           failed.

         * **reason** -- Optional failure reason stored on each trial.

   finalize_trial(answer, trial, experiment, participant)

      This function is run after the participant completes the trial.
      It can be optionally customised, for example to add some more
      postprocessing. If you override this, make sure you call
      "super().finalize_trial(...)" somewhere in your new method.

      Parameters:
         * **answer** -- The "answer" object provided by the trial.

         * **trial** -- The "Trial" object representing the trial.

         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

   get_end_feedback_passed_page(score)

      Defines the feedback given to participants who pass the final
      performance check. This feedback is only given if
      "give_end_feedback_passed" is set to "True".

      Parameters:
         **score** -- The participant's score on the performance
         check.

      Returns:
         * "Page" -- A feedback page.

   get_participant_trials(participant)

      Returns all trials (complete and incomplete) owned by the
      current participant, including repeat trials. Not intended for
      overriding.

      Parameters:
         **participant** -- An instantiation of
         "psynet.participant.Participant", corresponding to the
         current participant.

   init_participant(experiment, participant)

      Initializes the participant at the beginning of the sequence of
      trials. If you override this, make sure you call
      "super().init_particiant(...)" somewhere in your new method.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

   init_participant_group(experiment, participant)

      Set the participant's group for this trial maker.

      In a synchronized trial maker, members copy it from their
      group's current run, so newcomers and a promoted leader keep the
      group's; otherwise, or for the run's first member,
      "choose_participant_group" chooses it. A group already set on
      the participant is kept, and recorded as the run's if the run
      has none yet.

   property n_complete_participants

      Number of participants who count as complete for this
      TrialMaker's quota.

   property n_working_participants

      Number of in-progress participants occupying a slot in this
      TrialMaker's quota.

   on_complete(experiment, participant)

      An optional function run once the participant completes their
      sequence of trials.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

   on_first_launch(experiment)

      Defines a routine to run when the experiment is launched for the
      first time.

      Parameters:
         **experiment** -- An instantiation of
         "psynet.experiment.Experiment", corresponding to the current
         experiment.

   performance_check(experiment, participant, participant_trials)

      Defines an automated check for evaluating the participant's
      current performance. The default behaviour is to take the sum of
      the trial 'scores' (as computed by the Trial.score_answer), but
      this can be overridden if desired.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

         * **participant_trials** -- A list of all trials completed so
           far by the participant.

      Returns:
         * *dict* -- The dictionary should include the following
           values:

           * "score", expressed as a "float" or "None".

           * "passed" (Boolean), identifying whether the participant
             passed the check.

   pre_deploy_routine(experiment)

      Defines a routine for setting up the experiment prior to
      deployment. This is a good place to prepare networks etc.

      Parameters:
         **experiment** -- An instantiation of
         "psynet.experiment.Experiment", corresponding to the current
         experiment.

   prepare_trial(experiment, participant)

      Prepares and returns a trial to administer the participant.

      Parameters:
         * **experiment** -- An instantiation of
           "psynet.experiment.Experiment", corresponding to the
           current experiment.

         * **participant** -- An instantiation of
           "psynet.participant.Participant", corresponding to the
           current participant.

      Returns:
         * A tuple of ("Trial", "str"), where the first is a Trial
           object,

         * *and the second is a status string.*

   state_class

      alias of "TrialMakerState"

class psynet.trial.main.TrialMakerState(*args, **kwargs)

   Bases: "ModuleState"

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   id

      a unique number for every entry. 1, 2, 3 and so on...

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   run_index

      Counts the participant's visits to the module, from 1, as when a
      loop repeats it.

   time_of_death

      the time at which failing occurred

   type

   vars

class psynet.trial.main.TrialNetwork(*args, **kwargs)

   Bases: "SQLMixinDallinger", "Network", "AssetParentMixin"

   A network class to be used by "NetworkTrialMaker". The user must
   override the abstract method "add_node()". The user may also wish
   to override the "async_post_grow_network()" method if they wish to
   implement asynchronous network processing.

   Parameters:
      **experiment** -- An instantiation of
      "psynet.experiment.Experiment", corresponding to the current
      experiment.

   target_n_trials

      Indicates the target number of trials for that network. Left
      empty by default, but can be set by custom "__init__" functions.
      Stored as the field "property2" in the database.

      Type:
         int or None

   participant

      Returns the network's "Participant", or "None" if none can be
      found.

      Type:
         Optional[Participant]

   sync_group_type

      The "sync_group_type" attribute of the trial maker that owns
      this network.

      Type:
         Optional[str]

   sync_group

      The SyncGroup that owns this network (normally only relevant for
      within-style chains).

      Type:
         Optional[SyncGroup]

   sync_group_id

      The ID of the SyncGroup that owns this network (normally only
      relevant for within-style chains).

      Type:
         Optional[int]

   all_trials

      A list of all trials owned by that network.

      Type:
         list

   alive_trials

      A list of all non-failed trials owned by that network.

      Type:
         list

   failed_trials

      A list of all failed trials owned by that network.

      Type:
         list

   var

      A repository for arbitrary variables; see "VarStore" for
      details.

      Type:
         "VarStore"

   run_async_post_grow_network

      Set this to "True" if you want the "async_post_grow_network()"
      method to run after the network is grown.

      Type:
         bool

   add_node(node)

      Adds a node to the network. This method is responsible for
      setting "self.full = True" if the network is full as a result.

   async_post_grow_network()

      Optional function to be run after the network is grown. Will
      only run if "run_async_post_grow_network" is set to "True".

   property async_processes

      Deprecated alias of "async_jobs".

   calculate_full()

      Set whether the network is full.

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   fail(reason=None)

      Fail this object, and potentially its related objects.

      Set "failed" to "True" and "time_of_death" to now.

      If a *reason* argument is passed, this will be stored in
      "failed_reason".

      Failure will then be propagated to related objects as defined by
      the *failure_cascade* property.

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   full

      Whether the network is currently full

   id

      a unique number for every entry. 1, 2, 3 and so on...

   max_size

      How big the network can get, this number is used by the full()
      method to decide whether the network is full

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   role

      The role of the network. By default dallinger initializes all
      networks as either "practice" or "experiment"

   time_of_death

      the time at which failing occurred

   type

      A String giving the name of the class. Defaults to "network".
      This allows subclassing.

   vars

class psynet.trial.main.TrialNode(*args, **kwargs)

   Bases: "SQLMixinDallinger", "Node", "AssetParentMixin"

   async_on_deploy()

      Called when the node is deployed to the remote server. This
      includes both deploying nodes from the local machine to the
      remote machine (e.g. when we have static stimuli that are
      preregistered in the database) and creating new nodes on the
      remote machine (e.g. when we have a chain experiment).

   property async_processes

      Deprecated alias of "async_jobs".

   creation_time

      the time at which the Network was created.

   details

      a generic column for storing structured JSON data

   fail(reason=None)

      Fail this object, and potentially its related objects.

      Set "failed" to "True" and "time_of_death" to now.

      If a *reason* argument is passed, this will be stored in
      "failed_reason".

      Failure will then be propagated to related objects as defined by
      the *failure_cascade* property.

   failed

      boolean indicating whether the Network has failed which prompts
      Dallinger to ignore it unless specified otherwise. Objects are
      usually failed to indicate something has gone wrong.

   failed_reason

      an optional reason the object was failed. If the object is
      failed as part of a cascading failure triggered from another
      object, the chain of objects will be captured in this field.

   property failure_cascade

      List of callables to determine which related objects to fail
      when "fail()" is called on this object.

      By default, no related objects are failed, but subclasses can
      provide a list of functions (typically bound instance methods)
      which will be called in order to retrieve additional objects on
      which to call "fail()".

      Example: The following implentation would cause "fail()" to be
      called on each value returned by "self.nodes()", and then on
      each value returned by "self.questions()":

      >>> @property
      >>> def failure_cascade(self):
      >>>     return [self.nodes, self.questions]

   id

      a unique number for every entry. 1, 2, 3 and so on...

   n_viable_trials

      Return the current viable-trial count for a node.

   network

      the network the node is in

   network_id

      the id of the network that this node is a part of

   participant

      the participant the node is associated with

   participant_id

      the id of the participant whose node this is

   property1

      a generic column that can be used to store experiment-specific
      details in String form.

   property2

      a generic column that can be used to store experiment-specific
      details in String form.

   property3

      a generic column that can be used to store experiment-specific
      details in String form.

   property4

      a generic column that can be used to store experiment-specific
      details in String form.

   property5

      a generic column that can be used to store experiment-specific
      details in String form.

   time_of_death

      the time at which failing occurred

   type

      A String giving the name of the class. Defaults to "node". This
      allows subclassing.

   update_status()

      Hook method called when the node's status may need updating.

      This method is called when trials associated with the node are
      finalized or fail. Subclasses can override this to update
      derived status attributes. For example, "ChainNode" uses this to
      check whether the node is ready to spawn a child node.

   vars
