This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from flojoy-ai/dyanmic-parameter-doc
Dynamic parameter documentation
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Flojoy Dynamic Parameters - for hiding unneeded parameters | ||
|
||
In some cases, there are parameters inputs that are not used or unneeded. A great example could be the `RAND` node, where different distrubution requires different parameters. | ||
|
||
The unneeded parameters can be hidden by specifying them and the conditions which they appear in the node source code through the @display decorator. | ||
|
||
## Using Flojoy's `display` Decorator | ||
Flojoy's `display` decorator allows you to specify the conditions when the parameters would be displayed. | ||
Please note that the function name always have to be `OVERLOAD` regardless of node name and the output is always `None`. | ||
The last function parameter and their default value in the would indicate what condition the other parameters would be displayed. | ||
Note that ONLY the parameters indicated within the `OVERLOAD` function with a `@display` decorator will be displayed. | ||
|
||
### Example | ||
|
||
Consider the following example: | ||
```python | ||
import random | ||
import numpy as np | ||
from flojoy import flojoy, OrderedPair, Scalar, Vector | ||
from flojoy import flojoy, OrderedPair, Scalar, Vector, display | ||
from typing import Literal, Optional | ||
|
||
|
||
@flojoy | ||
def RAND( | ||
default: Optional[OrderedPair | Vector] = None, | ||
distribution: Literal["normal", "uniform", "poisson"] = "normal", | ||
lower_bound: float = 0, | ||
upper_bound: float = 1, | ||
normal_mean: float = 0, | ||
normal_standard_deviation: float = 1, | ||
poisson_events: float = 1, | ||
) -> OrderedPair | Scalar: | ||
... | ||
Return Scalar(c=y) | ||
|
||
@display | ||
def OVERLOAD(lower_bound, upper_bound, distribution="uniform") -> None: | ||
return None | ||
|
||
|
||
@display | ||
def OVERLOAD(normal_mean, normal_standard_deviation, distribution="normal") -> None: | ||
return None | ||
|
||
|
||
@display | ||
def OVERLOAD(poisson_events, distribution="poisson") -> None: | ||
return None | ||
``` | ||
In this example, `lower_bound` and `upper_bound` would be the ONLY displayed parameters in the UI when the `distribution` field is equal to "uniform", | ||
`normal_mean` and `normal_standard_deviation` would be the ONLY displayed parameters in the UI when `distribution` is "normal", and so forth. | ||
|
||
Note that currently, Flojoy does not support two or more parameter conditions, but is planned in a future release. | ||
|
||
<SectionBreak /> | ||
|
||
[//]: # (Edit page on GitHub) | ||
|
||
#### Edit page on GitHub | ||
|
||
[Edit page here](https://github.com/flojoy-ai/docs/blob/main/docs/advanced-usage/dynamic-parameter.md) |