Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kwargs to .compute() #103

Merged
merged 2 commits into from
Jan 18, 2024
Merged
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
12 changes: 7 additions & 5 deletions src/sciline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,18 +661,18 @@ def _build_series(
return graph

@overload
def compute(self, tp: Type[T]) -> T:
def compute(self, tp: Type[T], **kwargs: Any) -> T:
...

@overload
def compute(self, tp: Iterable[Type[T]]) -> Dict[Type[T], T]:
def compute(self, tp: Iterable[Type[T]], **kwargs: Any) -> Dict[Type[T], T]:
...

@overload
def compute(self, tp: Item[T]) -> T:
def compute(self, tp: Item[T], **kwargs: Any) -> T:
...

def compute(self, tp: type | Iterable[type] | Item[T]) -> Any:
def compute(self, tp: type | Iterable[type] | Item[T], **kwargs: Any) -> Any:
"""
Compute result for the given keys.

Expand All @@ -683,8 +683,10 @@ def compute(self, tp: type | Iterable[type] | Item[T]) -> Any:
tp:
Type to compute the result for.
Can be a single type or an iterable of types.
kwargs:
Keyword arguments passed to the ``.get()`` method.
"""
return self.get(tp).compute()
return self.get(tp, **kwargs).compute()

def visualize(
self, tp: type | Iterable[type], **kwargs: Any
Expand Down
6 changes: 6 additions & 0 deletions tests/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,12 @@ def test_get_with_NaiveScheduler() -> None:
assert task.compute() == 1.5


def test_compute_with_NaiveScheduler() -> None:
pipeline = sl.Pipeline([int_to_float, make_int])
res = pipeline.compute(float, scheduler=sl.scheduler.NaiveScheduler())
assert res == 1.5


def test_bind_and_call_no_function() -> None:
pipeline = sl.Pipeline([make_int])
assert pipeline.bind_and_call(()) == ()
Expand Down