Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions docs/source/guide/stages.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Stages
Comment thread
knoepfel marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@matclim We may want to explain what a stage is before getting into details about the stage name. For example, discuss how a Phlex execution happens in the context of workflow consisting of multiple stages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added an opening paragraph that places a stage in a multi-stage workflow before talking about stage names. I kept it short, since #1083 will settle the full definition

======

A Phlex job is usually one step of a larger processing workflow.
For example, a simulation job writes generated events to a file, a
digitization job reads that file and writes the simulated detector response,
and a reconstruction job reads the digitized data and writes reconstructed
objects.
Each of these steps is a *processing stage*, and each Phlex job runs one
stage.
A job can therefore see products from several stages: products read from
its input files, created by earlier stages, alongside the products it
creates itself.

A *stage name* identifies the processing stage that created a data product.
Examples of stage names include ``simulation``, ``digitization``, and
``reconstruction``.
Together with the creator, suffix, data layer and type, it is part of a
product's identity.
It allows Phlex to distinguish between products that otherwise look the same
but were created by different Phlex jobs, such as a ``hits`` product read
from a simulation file and a ``hits`` product recomputed in the current job.

Choose a name that stays the same when an equivalent job is rerun.
Timestamps, host names and batch-job IDs are poor stage names.

Naming the stage of a job
-------------------------

Every job must name its stage, either with the top-level ``stage`` key or
with the ``--stage`` option, which takes precedence:

.. code-block:: jsonnet

{
stage: 'reconstruction',
driver: { /* ... */ },
modules: { /* ... */ },
}

.. code-block:: console

phlex -c workflow.jsonnet --stage reconstruction

A job fails at startup if no stage is given, if it is empty, or if it is
``"CURRENT"``, which is reserved (see below).
The stage requirement was introduced in Phlex v0.4.0; configurations written
for earlier versions need a ``stage`` key added.

Stages of created products
--------------------------

Every product created by a transform, fold or unfold in the job carries the
job's stage.

Providers registered with ``PHLEX_REGISTER_PROVIDERS`` declare their
product with ``output_product(creator, suffix, layer, stage)``.
The ``stage`` argument defaults to ``"CURRENT"``, which Phlex replaces by the
job's stage name.
A provider that reads products written by an earlier job can instead pass
that job's stage name, so that its products keep their original identity.

Implicit providers, which a ``phlex::source`` returns from
``create_providers()``, must set ``provider_bundle::stage`` to a real stage
name.
Returning ``"CURRENT"`` is an error, because no substitution takes place for
implicit providers.

.. note::

In Phlex v0.4 a ``phlex::source`` has no access to the job's stage, so a
source that creates new products, such as an event generator, must take
the stage name from its own configuration.
Whether sources should support the ``"CURRENT"`` stage name is under
discussion in
`issue #957 <https://github.com/Framework-R-D/phlex/issues/957>`_.

Selecting products by stage
---------------------------

``product_selector`` has an optional ``stage`` field; in a configuration
file a selector object accepts a ``stage`` key.

Not specified
Products of any stage match.

``"CURRENT"``
Only products of the job's own stage match.
Sources are the exception for now: the selector reaches
``create_providers()`` with the literal ``"CURRENT"``, which a source that
checks candidates with ``selector.match(spec, layer, stage)`` will not
match (see issue #957).
To select a product that a source supplies, leave ``stage`` unspecified
or name the stage explicitly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you check if this is correct? When allowed, "CURRENT" should always resolve to the current stage name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had a look at the code: it’s correct as current behaviour, though it (probably) isn’t the intended design. For explicit providers and for products created in the job, "CURRENT" is replaced by the job’s stage (make_computational_edges.cpp l40, producer_catalog.cpp l34). Sources, though, receive the selector unchanged in create_providers(), so a source comparing against its own stage never matches the literal "CURRENT". I’ve marked this as an exception for now am now pointing to #957.

Any other name
Only products of that stage match.
If it is not the job's own stage, Phlex looks for the product only among
providers, because everything computed in the job carries the job's stage.

.. code-block:: cpp

m.transform("refit", refit, concurrency::unlimited)
.input_family(product_selector{
.creator = "tracks", .layer = "event", .stage = "reconstruction"});

Selectors written in Python cannot set ``stage`` yet.

An algorithm that takes a ``phlex::handle<T>`` can read the stage of the
product it received with ``handle::stage()``.
8 changes: 8 additions & 0 deletions phlex/core/registration_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ namespace phlex::detail {
{
}

/// @brief Declares the data product created by this provider.
///
/// @param creator Creator name recorded for the product, as matched by
/// @c product_selector::creator.
/// @param suffix Suffix recorded for the product.
/// @param output_layer Data layer whose data cells this provider is called for.
/// @param stage Stage recorded for the product. The default, @c "CURRENT",
/// is replaced by the stage configured for the job.
auto output_product(phlex::experimental::algorithm_name creator,
phlex::experimental::identifier suffix,
phlex::experimental::identifier output_layer,
Expand Down
3 changes: 3 additions & 0 deletions phlex/model/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ namespace phlex {
}
std::string_view suffix() const noexcept { return std::string_view(spec_->suffix()); }
std::string_view layer() const noexcept { return std::string_view(index_->layer_name()); }
/// @brief Name of the processing stage that created the product.
///
/// This is the job's configured stage for products created by transforms, folds, and unfolds.
std::string_view stage() const noexcept { return std::string_view(*stage_); }
std::string layer_path() const { return index_->layer_path().to_string(); }

Expand Down
Loading