Ops
API for implementing LynxKite operations.
LongStr
module-attribute
¤
LongStr is a string type for parameters that will be displayed as a multiline text area in the UI.
Op
¤
Parameter
¤
Bases: BaseConfig
Defines a parameter for an operation.
ParameterGroup
¤
Bases: BaseConfig
Defines a group of parameters for an operation.
Position
¤
Result
dataclass
¤
Represents the result of an operation.
The output
attribute is what will be used as input for other operations.
The display
attribute is used to send data to display on the UI. The value has to be
JSON-serializable.
input_metadata
is a list of JSON objects describing each input.
get_optional_type
¤
For a type like int | None
, returns int
. Returns None
otherwise.
input_position
¤
Decorator for specifying unusual positions for the inputs.
Example usage:
@input_position(a="bottom", b="bottom")
@op("test", "maybe add")
def maybe_add(a: list[int], b: list[int] | None = None):
return [a + b for a, b in zip(a, b)] if b else a
load_user_scripts
¤
Reloads the *.py in the workspace's directory and higher-level directories.
make_async
¤
Decorator for slow, blocking operations. Turns them into separate threads.
matplotlib_to_image
¤
Decorator for converting a matplotlib figure to an image.
op
¤
op(env: str, *names: str, view: str = 'basic', outputs: list[str] | None = None, params: list[Parameter] | None = None, slow: bool = False, color: str | None = None, cache: bool | None = None, dir: str = 'left-to-right')
Decorator for defining an operation.
PARAMETER | DESCRIPTION |
---|---|
env
|
The environment (workspace type) to which the operation belongs.
TYPE:
|
names
|
The list of categories this operation belongs to, followed by the name of the operation.
TYPE:
|
view
|
How the operation will be displayed in the UI. One of "basic", "visualization", "table_view", "graph_creation_view", "image", "molecule", "matplotlib".
TYPE:
|
outputs
|
A list of output names. If not provided, defaults to ["output"] for "basic" view.
TYPE:
|
params
|
Normally the parameters are taken from the function signature. Use "params" to override this.
TYPE:
|
slow
|
If True, the operation results will be cached. If the function is not async, it will be run in a separate thread.
TYPE:
|
color
|
The color of the operation in the UI. Defaults to "orange".
TYPE:
|
cache
|
Set to False to disable caching for a slow operation. You may need this for slow operations with parameters/outputs that can't be serialized.
TYPE:
|
dir
|
Sets the default input and output positions. The default is "left-to-right", meaning inputs are on the left and outputs are on the right. Other options are "right-to-left", "top-to-bottom", and "bottom-to-top".
TYPE:
|
op_registration
¤
Returns a decorator that can be used for registering functions as operations.
output_position
¤
Decorator for specifying unusual positions for the outputs.
Example usage:
@output_position(output="top")
@op("test", "maybe add")
def maybe_add(a: list[int], b: list[int] | None = None):
return [a + b for a, b in zip(a, b)] if b else a
parse_doc
cached
¤
Griffe is an optional dependency. When available, we return the parsed docstring.
passive_op_registration
¤
Returns a function that can be used to register operations without associated code.
register_executor
¤
Decorator for registering an executor.
The executor is a function that takes a workspace and executes the operations in it.
When it starts executing an operation, it should call node.publish_started()
to indicate
the status on the UI. When the execution is finished, it should call node.publish_result()
.
This will update the UI with the result of the operation.
register_passive_op
¤
register_passive_op(env: str, *names: str, inputs=[], outputs=['output'], params=[], dir='left-to-right', **kwargs)
A passive operation has no associated code.