<!-- Source: https://docs.biosimulant.com/how-to/library/use-biomodule -->

# How to Use a BioModule

This guide shows how to instantiate an existing module, inspect its typed ports, wire it into a world, and read back outputs or snapshots.

## Import and instantiate

```python
from your_biomodule_package.population import PopulationCounter

population = PopulationCounter(initial_count=100, growth_rate=0.05)
```

## Inspect ports

```python
print(population.inputs())
print(population.outputs())
```

Current-kernel modules should expose `dict[str, SignalSpec]` mappings, not sets of port names.

## Wire into a world

```python

from your_biomodule_package.monitoring import PopulationMonitor

world = biosim.BioWorld(communication_step=1.0)
builder = biosim.WiringBuilder(world)

builder.add("population", population)
builder.add("monitor", PopulationMonitor())
builder.connect("population.population_state", ["monitor.population_state"])
builder.apply()
```

## Run and inspect outputs

```python
world.run(duration=10.0)

outputs = population.get_outputs()
signal = outputs["population_state"]
print(signal.value)
print(signal.emitted_at)
```

Signals are typed runtime objects such as `ScalarSignal`, `ArraySignal`, `RecordSignal`, or `EventSignal`.

## Snapshots

```python
snapshot = population.snapshot()
print(snapshot)
```

Use snapshots for deterministic reruns and branching. Do not assume a kernel-level reset API exists.

## Visualizations

```python
visuals = world.collect_visuals()
for entry in visuals:
    print(entry["module"], entry["visuals"])
```

**Info:**

  If you are working from a packaged model, the manifest's `io` block should match the runtime ports returned by `inputs()` and `outputs()`.

## Next steps

- [Use a BioWorld](/how-to/library/use-bioworld)
- [Create a BioModule](/how-to/library/create-biomodule)
- [BioModule API Reference](/references/library/biomodule-api)
