Skip to content

refactor: use parameter models from esslivedata#654

Draft
jokasimr wants to merge 6 commits into
mainfrom
refactor-widget-models
Draft

refactor: use parameter models from esslivedata#654
jokasimr wants to merge 6 commits into
mainfrom
refactor-widget-models

Conversation

@jokasimr

Copy link
Copy Markdown
Contributor

Fixes #653

This is a codex rewrite of the parameter / workflow widget system using the models from esslivedata.

@jokasimr jokasimr requested a review from SimonHeybrock June 26, 2026 13:14
@github-actions github-actions Bot added essdiffraction Issues for essdiffraction. essreduce Issues for essreduce. esssans Issues for esssans. labels Jun 26, 2026
Comment on lines +52 to +67
DetectorBank.south: {'y': 200, 'x': 500},
DetectorBank.north: {'y': 200, 'x': 500},
},
KeepEvents[RunType]: KeepEvents(False),
TwoThetaMask: lambda two_theta: (
(two_theta < sc.scalar(float('inf'), unit=two_theta.unit))
| (two_theta > sc.scalar(float('-inf'), unit=two_theta.unit))
),
TofMask: None,
WavelengthMask: None,
MaskedDetectorIDs: MaskedDetectorIDs({}),
NeXusDetectorName: "detector",
DetectorBank: DetectorBank.south,
Filename[SampleRun]: str(mcstas_powder_silicon_in_vanadium_can()),
Filename[VanadiumRun]: str(mcstas_powder_vanadium()),
Filename[EmptyCanRun]: str(mcstas_powder_empty_can()),

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.

These changes will be revisited or removed.

They were added mainly for debugging purposes.

stop=self.stop,
num=self.num_bins + 1,
unit=self.unit.value,
)

@jokasimr jokasimr Jun 26, 2026

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.

Why does this have to be re-implemented here?
Looks like only the dim and descriptions should need to be specified.

# TODO: for now, we leave the mapping over detector banks out, because we do not have a
# method to merge the I(Q) of different banks, and we thus cannot compute a single
# result from the workflow. So only a single detector bank can be processed at a time.
# parameter_mappers[NeXusDetectorName] = with_banks

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.

Comment should not be removed.

Comment on lines +20 to +27
@dataclass(frozen=True)
class WorkflowSpec:
"""Metadata needed to generate interfaces for a workflow."""

name: str
title: str | None = None
description: str | None = None
version: str | None = None

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.

Why does the WorkflowSpec not hold models for workflow inputs and outputs, or the param-specs you defined?

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.

Updated it so that now it does. I agree that makes more sense.

Comment on lines +23 to +36
@dataclass(frozen=True)
class ParameterSpec(Generic[T]):
"""Specification for configuring a Sciline workflow key."""

model: Any
category: str
title: str | None = None
description: str | None = None
default: T | KeepDefaultType = keep_default
transform: Callable[[T], Any] | None = None
apply: Callable[[Pipeline, T], Pipeline] | None = None
filter_keys: tuple[Key, ...] = ()
use_workflow_default: bool = True
key: Key | None = None

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.

This seems like a central part we should talk about. It seems like the idea is that a set of ParameterSpec would/could take the role of the input-params-model (and output-params-model)? One concern I have is that this ties the spec to the implementation (transforms, key, ...), which would force full dependencies in UI packages that do not run code. title, description, and default we'd get for free as field attributes if we used a model holding all params. On the other hand, storing them in this param spec seems like it has the advantage in composability, as we can provide multiple workflows with different subsets of param specs (exposed inputs).

@jokasimr jokasimr Jun 29, 2026

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 think there are some suspect fields that were added by codex for quite hacky reasons, for example filter_keys. I'll try to iterate a bit on this to make it leaner.

But I don't really understand what you mean, how could the input params model not hold a reference to the sciline Key that it intends to represent? Or do you mean that the input parameters is another separate layer of input parameters that are then mapped to sciline keys in a separate stage? Or did you mean something different?

It's probably best to talk in chat. Do you have time at 13?

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.

In ESSlivedata the workflow factory is responsible for this. Only it know the implementation and how to map model fields to workflow keys (there may even be non 1:1 mappings), the model does not.


# TODO: the mask parameters (TofMask, TwoThetaMask, WavelengthMask) need a new widget
# that allows to define a python function in the notebook and pass it to the workflow.
# We defer this to later; the masks are set to None by default in the workflow for now.

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.

Comment should be preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

essdiffraction Issues for essdiffraction. essreduce Issues for essreduce. esssans Issues for esssans.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate workflow specifications, parameter models, and metadata mechanisms

2 participants