Skip to content

Input module

Input(schema=None, data_model=None, optional=False, name=None)

Used to instantiate a SymbolicDataModel.

A SymbolicDataModel is a symbolic data_model-like object, which we augment with certain attributes that allow us to build a Synalinks Program just by knowing the inputs and outputs of the program.

Example:

import synalinks

class Query(synalinks.DataModel):
    query: str

inputs = synalinks.Input(data_model=Query)

# You can also create it using a JSON schema like this:

inputs = synalinks.Input(schema=Query.schema())

# Or using a symbolic datamodel:

inputs = synalinks.Input(data_model=Query.to_symbolic_data_model())

Parameters:

Name Type Description Default
schema dict

A Json schema of the data_model. If not provided uses the data_model argument.

None
data_model DataModel

Optional existing data model to wrap into the Input layer. If set, the module will use this data_model rather than creating a new placeholder data model.

None
optional bool

Whether the input is optional or not. An optional input can accept None values.

False
name string

Optional name string for the module. Should be unique in a program (do not reuse the same name twice). It will be autogenerated if it isn't provided.

None

Returns:

Type Description
SymbolicDataModel

The symbolic data model corresponding to the given data model/schema.

Source code in synalinks/src/modules/core/input_module.py
@synalinks_export(["synalinks.modules.Input", "synalinks.Input"])
def Input(
    schema=None,
    data_model=None,
    optional=False,
    name=None,
):
    """Used to instantiate a `SymbolicDataModel`.

    A `SymbolicDataModel` is a symbolic data_model-like object, which we augment with
    certain attributes that allow us to build a Synalinks `Program` just by knowing the
    inputs and outputs of the program.

    Example:

    ```python
    import synalinks

    class Query(synalinks.DataModel):
        query: str

    inputs = synalinks.Input(data_model=Query)

    # You can also create it using a JSON schema like this:

    inputs = synalinks.Input(schema=Query.schema())

    # Or using a symbolic datamodel:

    inputs = synalinks.Input(data_model=Query.to_symbolic_data_model())
    ```

    Args:
        schema (dict): A Json schema of the data_model.
            If not provided uses the `data_model` argument.
        data_model (DataModel): Optional existing data model to wrap into
            the `Input` layer. If set, the module will use this data_model rather
            than creating a new placeholder data model.
        optional (bool): Whether the input is optional or not.
            An optional input can accept `None` values.
        name (string): Optional name string for the module.
            Should be unique in a program (do not reuse the same name twice).
            It will be autogenerated if it isn't provided.

    Returns:
        (SymbolicDataModel): The symbolic data model corresponding to
            the given data model/schema.
    """
    module = InputModule(
        schema=schema,
        input_data_model=data_model.to_symbolic_data_model() if data_model else None,
        optional=optional,
        name=name,
    )
    return module.output