# How to use a non-dynamic \`input\_namespace\`

**URL:** <https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511>\
**Category:** General Usage\
**Created:** [December 6, 2024, 11:12am UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511 "2024-12-06T11:12:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xing](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/xing/32/10_2.png) [@Xing](https://aiida.discourse.group/u/Xing)\
**Post date:** [December 6, 2024, 11:12am UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511/1 "2024-12-06T11:12:48Z")

</div>

The dynamic `input_namespace` is very useful and commonly used. But what’s the usage of a non-dynamic one?

Does anyone have an example on `input_namespace`, which is not dynamic? I looked at the [docs](https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/processes/usage.html#ports-and-port-namespaces), but it does not give an example of the usage.

---

<div class="post-metadata">

**Author:** ![sphuber](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/sphuber/32/6_2.png) [@sphuber](https://aiida.discourse.group/u/sphuber)\
**Post date:** [December 6, 2024, 11:26am UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511/2 "2024-12-06T11:26:08Z")

</div>

All namespaces are non-dynamic by default . The top-level inputs is a namespace itself and it is non-dynamic. The benefit is that if a wrong input is provided (for example by accident through a typo or something) a validation error is raised.

---

<div class="post-metadata">

**Author:** ![Xing](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/xing/32/10_2.png) [@Xing](https://aiida.discourse.group/u/Xing)\
**Post date:** [December 6, 2024, 11:52am UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511/3 "2024-12-06T11:52:40Z")

</div>

Hi @sphuber , thanks for the quick reply! The top-level namespace is non-dynamic; I forgot this. 😅

> The benefit is that if a wrong input is provided (for example by accident through a typo or something) a validation error is raised.

Yes, very clear, thanks!

in the docs, it says:

> This is where the `dynamic` attribute of the `PortNamespace` comes in. By default this is set to `False` , but by setting it to `True` , one indicates that that namespace can take a number of values that is unknown at the time of definition of the specification.

This confuses me. For a non-dynamic Port, the number of values it can take is also unknown, right?

For example, the `monitors` namespace in Calcjob

```python
spec.input_namespace(
            'monitors',
            valid_type=orm.Dict,
            required=False,
            validator=validate_monitors,
            help='Add monitoring functions that can inspect output files while the job is running and decide to '
            'prematurely terminate the job.',
        )

```

One can pass any number of monitors into it.

Now, I am also confused about how the top-level namespace validates the inputs. 😂

---

<div class="post-metadata">

**Author:** ![sphuber](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/sphuber/32/6_2.png) [@sphuber](https://aiida.discourse.group/u/sphuber)\
**Post date:** [December 6, 2024, 12:04pm UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511/4 "2024-12-06T12:04:22Z")

</div>

This because setting `valid_type` to a particular value, automatically makes the namespace dynamic:

> <https://github.com/aiidateam/plumpy/blob/55e05e956c9715fb69785d83d0194b65811b4720/src/plumpy/ports.py#L397>

Not sure if this is part of the `aiida-core` docs, but may be useful to add if not yet the case.

---

<div class="post-metadata">

**Author:** ![Xing](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/xing/32/10_2.png) [@Xing](https://aiida.discourse.group/u/Xing)\
**Post date:** [December 6, 2024, 12:18pm UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511/5 "2024-12-06T12:18:59Z")

</div>

> setting `valid_type` to a particular value, automatically makes the namespace dynamic:

That’s the trick part, and it’s not in the aiida-core docs yet. I made an [issue](https://github.com/aiidateam/aiida-core/issues/6655)

Thank! It is now clear to me.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/aiida/original/1X/c417197d3750949351575d03ed03f5e2ad32e649.png) [@system](https://aiida.discourse.group/u/system)\
**Post date:** [December 12, 2024, 8:19am UTC](https://aiida.discourse.group/t/how-to-use-a-non-dynamic-input-namespace/511/6 "2024-12-12T08:19:05Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
