# SUB_ENTRY

Editor-only blocks (SUBMODEL, SUB_ENTRY, SUB_EXIT) that group blocks into a reusable sub-model with named ports, expanded away before the run.

Editor-only placeholder shared by three types, never run directly -- `core/submodels.flatten()` expands them away before the engine builds any process. SUB_ENTRY: an input port of a submodel definition (`port` names it; exactly one outgoing link inside the definition, none incoming). SUB_EXIT: an output port of a definition (`port` names it; incoming links only). SUBMODEL: an instance of a definition dropped on the canvas (`definition` names it, `arguments` binds its parameters).

Family: source. Python builder: `m.sub_entry(...)`. Editor-only: the engine flattens it away before a run.

## Typical uses

Use SUB_ENTRY inside a submodel definition to mark where entities come in. Each input port of the definition has one. Outside, the links that reach the [SUBMODEL](submodel.md) instance on that port continue from the block that SUB_ENTRY links to.

## Behaviour and rules

The `port` names the input. A SUB_ENTRY has exactly one outgoing link inside the definition and no incoming link. Port names must be unique within a definition, and a duplicate is an error.

The block never runs. Before a run, the engine removes it and joins the instance's incoming link directly to the block behind the port. It takes no time and adds no results. A link that names a port the definition does not have is reported by a check.

## Ports

- Inputs: none: a flow starts here.
- Outputs: one outgoing link.

## Parameters

| Parameter | Type | Default | Required | Quantity | Unit key | Description |
|---|---|---|---|---|---|---|
| `port` | str | `'in'` |  |  |  | Input port name of the definition |

## Statistics

Every run fills `system` and `entity_summary` (see the [KPI reference](../kpis.md)). The example below also fills:

| Frame | Columns |
|---|---|
| [`resource_summary`](../kpis.md#resource_summary) | `Run`, `Resource`, `Total Seizes`, `Usage % (snapshot)`, `Idle %`, `Scheduled Capacity Avg`, `Down %`, `Busy Cost`, `Idle Cost`, `Usage Cost`, `Total Cost`, `Queue Length Avg`, `Queue Length Max`, `Queue Length at End`, `Queue Length Mode`, `Queue Length Mode %`, `Queue Len P95`, `Queue Len P99`, `Queue Len Std`, `Time in Queue Avg`, `Time in Queue Avg (incl. waiting)`, `Time in Queue Max`, `Time in Queue Mode`, `Time in Queue Mode %`, `Wait P95`, `Wait P99`, `Wait Std`, `Bottleneck Score`, `Bottleneck %` |
| `material_flow_summary` | `Run`, `From`, `To`, `Entities` |

## Problem codes

A check of the model reports these about this block:

| Code | Meaning |
|---|---|
| `E_SUBMODEL_SCOPE` | SUB_ENTRY/SUB_EXIT used outside a submodel definition. |

## Example

The snippet seeds itself; its output is from a run made when this page was generated. `SUB_ENTRY` and `SUB_EXIT` are the ports of a definition, `SUBMODEL` an instance of it.

```python
from nagasim import build as nb

m = nb.Model(time_limit=200)
m.add_resource(name="Lathe")
cell = m.definition("Cell")                     # a reusable group: SUB_ENTRY -> blocks -> SUB_EXIT
cell.sub_entry("in") >> cell.process(resource_name="Lathe", distribution=nb.Constant(value=2)) >> cell.sub_exit("out")
m.create(distribution=nb.Constant(value=5)) >> m.submodel(definition="Cell") >> m.dispose()

results = m.run(seed=1)
print(int(results.kpi("resource/Lathe/Total Seizes")), "parts went through the Cell submodel")
```

```text
41 parts went through the Cell submodel
```

## Used in

Bundled models: [Berth: shore power](../../gallery/energy.md), [Biogas plant (library assets)](../../gallery/energy.md), [Hub day: electrifying the ground support equipment](../../gallery/logistics.md), [Container terminal: electrification](../../gallery/logistics.md), [Container terminal: quay to yard](../../gallery/logistics.md), [Hub day: turnaround workload (crews, ground equipment, on-time departures)](../../gallery/logistics.md) and 9 more.

Guides: [Submodels](../../modelling-guide/submodels.md).

## See also

- [All blocks](index.md), [KPI reference](../kpis.md), [Model file keys](../schema.md), [Model file format](../../model-file-format.md)
- Same family (source): [CREATE](create.md)
