Skip to content

Mapping non-source nodes #174

@jl-wynen

Description

@jl-wynen

It can be useful to map over nodes that have inputs but Sciline / Cyclebane do not allow this. For example, in ESSreflectometry, we want to map over filenames and sample angles. However, the sample angle is by default read from a file. So its provider has inputs and Sciline refuses to map over it.

Here is a simplified example:

import sciline as sl


def foo(i: int) -> float:
    return 10.0 * i


def bar(f: float) -> str:
    return str(f)


pl = sl.Pipeline([foo, bar])
pl = pl.map({float: [2.0, 3.0]})

This fails with ValueError: Mapped node '<class 'float'>' is not a source node.

It can be circumvented using

pl = sl.Pipeline([foo, bar])
pl[float] = 0.0
pl = pl.map({float: [2.0, 3.0]})

but this is not great.

Mapping nodes corresponds to assigning values to them. So it is analogous to setting a parameter value. And since this is allowed for non-source nodes, mapping should also be allowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions