<!-- Source: https://docs.biosimulant.com/how-to/library/compose-nested-labs -->

# How to Compose Nested Labs

Nested labs let you treat a composed subgraph as a reusable child with explicit external ports.

## Step 1: expose child lab I/O

```yaml
schema_version: "2.0"
title: "E/I Microcircuit"

models:
  - path: ../../models/excitatory
    alias: exc
  - path: ../../models/inhibitory
    alias: inh

wiring:
  - from: exc.spikes
    to:
      - inh.input_spikes

runtime:
  duration: 1.0
  communication_step: 0.001

io:
  inputs:
    - name: external_current
      maps_to: exc.current
  outputs:
    - name: exc_spikes
      maps_to: exc.spikes
```

Without `io`, the child lab has no external ports for parent wiring.

## Step 2: reference the child from a parent

```yaml
children:
  - path: ../ei-microcircuit
    alias: circuit_a
    parameters: {}

wiring:
  - from: stim.current
    to:
      - circuit_a.external_current
```

## Child references

Supported child locators:

- `path`
- `package` + `version`

The old `lab_id` form is not part of the current manifest schema.

## Notes

- Parent wiring addresses child ports as `child_alias.external_port_name`.
- Child labs can themselves contain `children`, so composition can be recursive.

**Info:**

  For self-contained packaged labs, prefer path-based children so the full graph can be bundled into one archive.

## Next steps

- [Write a lab.yaml](/how-to/library/write-lab-manifest)
- [lab.yaml Schema Reference](/references/library/lab-manifest)
