Skip to content

GraphManager

mdo_framework.db.graph_manager.GraphManager

Typed access to the study graph stored in FalkorDB.

Variables and tools are created from the models of mdo_framework.schema and read back as models. Each node carries a seq number, assigned at creation, that defines the order of every listing: design variable order is meaningful. The numbers may have gaps. Creating or replacing a node is one atomic query, so concurrent writers cannot duplicate a name; checks spanning several queries (role conflicts, duplicate producers) assume a single writer.

Attributes:

Name Type Description
graph

The FalkorDB graph that is queried.

Source code in src/mdo_framework/db/graph_manager.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
class GraphManager:
    """Typed access to the study graph stored in FalkorDB.

    Variables and tools are created from the models of ``mdo_framework.schema`` and
    read back as models. Each node carries a ``seq`` number, assigned at creation,
    that defines the order of every listing: design variable order is meaningful.
    The numbers may have gaps. Creating or replacing a node is one atomic query, so
    concurrent writers cannot duplicate a name; checks spanning several queries
    (role conflicts, duplicate producers) assume a single writer.

    Attributes:
        graph: The FalkorDB graph that is queried.
    """

    def __init__(self, graph: Any | None = None) -> None:
        """Bind the manager to a graph.

        Args:
            graph: Graph exposing ``query(text, params=...)``. Defaults to the graph
                of the shared ``FalkorDBClient``.
        """
        self.graph = graph if graph is not None else FalkorDBClient().get_graph()

    def clear_graph(self) -> None:
        """Delete every node and edge, and restart the ``seq`` numbering."""
        self._run(_CLEAR_GRAPH)

    # --- Variables ---

    def add_variable(self, variable: Variable) -> None:
        """Create a variable.

        Args:
            variable: The variable to store.

        Raises:
            NodeExistsError: If a variable with this name exists.

        Example:
            ```python
            gm.add_variable(RangeVar(name="x", lower=-10.0, upper=10.0))
            gm.add_variable(StateVar(name="f_xy"))
            ```
        """
        self._create(_VARIABLE_QUERIES, variable)

    def put_variable(self, variable: Variable) -> bool:
        """Create a variable, or replace every property of an existing one.

        The ``seq`` number, hence the position, and the edges are kept on replace.

        Args:
            variable: The variable to store.

        Returns:
            ``True`` if it was created, ``False`` if it replaced an existing one.

        Raises:
            RoleConflictError: If the existing variable is produced by a tool and
                the new kind is not ``"state"``.
        """
        if variable.kind != "state":
            producers = [
                row[0] for row in self._run(_PRODUCERS_OF_VARIABLE, name=variable.name)
            ]
            if producers:
                raise RoleConflictError(
                    variable.name,
                    f"Variable '{variable.name}' is produced by "
                    f"{', '.join(producers)} and must keep kind 'state', "
                    f"not '{variable.kind}'",
                )
        return self._put(_VARIABLE_QUERIES, variable)

    def delete_variable(self, name: str) -> None:
        """Delete a variable and its edges.

        Args:
            name: Variable name.

        Raises:
            NodeNotFoundError: If there is no such variable.
        """
        self._delete(_VARIABLE_QUERIES, name)

    def get_variables(self) -> list[Variable]:
        """List the variables in creation order.

        Returns:
            The stored variables.

        Raises:
            StudyValidationError: With a ``LEGACY_NODE`` finding for every variable
                node created without a ``kind`` by an older version.
        """
        variables: list[Variable] = []
        legacy: list[Finding] = []
        for (node,) in self._run(_VARIABLE_QUERIES.list_all):
            properties = _node_properties(node)
            if "kind" in properties:
                variables.append(_VARIABLE_ADAPTER.validate_python(properties))
                continue
            name = properties.get("name")
            legacy.append(
                Finding(
                    code="LEGACY_NODE",
                    message=(
                        f"Variable '{name}' has no 'kind'; "
                        "delete and recreate it with the typed API"
                    ),
                    names=(name,),
                )
            )
        if legacy:
            raise StudyValidationError(ValidationReport(errors=tuple(legacy)))
        return variables

    # --- Tools ---

    def add_tool(self, tool: ToolNode) -> None:
        """Create a tool.

        Args:
            tool: The tool to store.

        Raises:
            NodeExistsError: If a tool with this name exists.

        Example:
            ```python
            gm.add_tool(ToolNode(name="CFD_Solver", fidelity="high"))
            ```
        """
        self._create(_TOOL_QUERIES, tool)

    def put_tool(self, tool: ToolNode) -> bool:
        """Create a tool, or replace every property of an existing one.

        The ``seq`` number, hence the position, and the edges are kept on replace.

        Args:
            tool: The tool to store.

        Returns:
            ``True`` if it was created, ``False`` if it replaced an existing one.
        """
        return self._put(_TOOL_QUERIES, tool)

    def delete_tool(self, name: str) -> None:
        """Delete a tool and its edges.

        Args:
            name: Tool name.

        Raises:
            NodeNotFoundError: If there is no such tool.
        """
        self._delete(_TOOL_QUERIES, name)

    def get_tools(self) -> list[ToolNode]:
        """List the tools in creation order.

        Returns:
            The stored tools, without their connections.
        """
        return [_tool_from_node(node) for (node,) in self._run(_TOOL_QUERIES.list_all)]

    # --- Connections ---

    def connect_input_to_tool(self, variable_name: str, tool_name: str) -> None:
        """Connect a variable to a tool that consumes it (Variable -> Tool).

        Connecting twice is harmless.

        Args:
            variable_name: The consumed variable.
            tool_name: The consuming tool.

        Raises:
            NodeNotFoundError: If the variable or the tool does not exist. The hint
                suggests ``connect_tool_to_output`` when the arguments look swapped.
            RoleConflictError: If the variable is already an output of the tool.

        Example:
            ```python
            gm.connect_input_to_tool("x", "Paraboloid")
            ```
        """
        params = {"variable_name": variable_name, "tool_name": tool_name}
        if self._run(_IS_OUTPUT_OF_TOOL, **params)[0][0]:
            raise RoleConflictError(
                variable_name, _both_roles_message(variable_name, tool_name)
            )
        if not self._run(_CONNECT_INPUT, **params)[0][0]:
            raise self._not_found(
                (_VARIABLE, variable_name),
                (_TOOL, tool_name),
                other_direction="connect_tool_to_output(tool_name, variable_name)",
            )

    def connect_tool_to_output(self, tool_name: str, variable_name: str) -> None:
        """Connect a tool to a variable it produces (Tool -> Variable).

        Connecting twice is harmless.

        Args:
            tool_name: The producing tool.
            variable_name: The produced variable, which must be of kind ``"state"``.

        Raises:
            NodeNotFoundError: If the tool or the variable does not exist. The hint
                suggests ``connect_input_to_tool`` when the arguments look swapped.
            DuplicateProducerError: If another tool already produces the variable.
            RoleConflictError: If the variable is a design or fixed variable, or is
                already an input of the tool.

        Example:
            ```python
            gm.connect_tool_to_output("Paraboloid", "f_xy")
            ```
        """
        params = {"tool_name": tool_name, "variable_name": variable_name}
        for kind, producers, input_edges in self._run(_OUTPUT_CHECK, **params):
            others = [producer for producer in producers if producer != tool_name]
            if others:
                raise DuplicateProducerError(variable_name, (*others, tool_name))
            if kind in _DESIGN_OR_FIXED_KINDS:
                raise RoleConflictError(
                    variable_name,
                    f"Variable '{variable_name}' has kind '{kind}', so it cannot be "
                    "a tool output; declare it as kind 'state'",
                )
            if input_edges:
                raise RoleConflictError(
                    variable_name, _both_roles_message(variable_name, tool_name)
                )
        if not self._run(_CONNECT_OUTPUT, **params)[0][0]:
            raise self._not_found(
                (_TOOL, tool_name),
                (_VARIABLE, variable_name),
                other_direction="connect_input_to_tool(variable_name, tool_name)",
            )

    def get_tool_inputs(self, tool_name: str) -> list[str]:
        """List the variables a tool consumes, in variable creation order.

        Args:
            tool_name: Tool name.

        Returns:
            Variable names; empty for an unknown tool.
        """
        return self._ports(_INPUT_EDGES).get(tool_name, [])

    def get_tool_outputs(self, tool_name: str) -> list[str]:
        """List the variables a tool produces, in variable creation order.

        Args:
            tool_name: Tool name.

        Returns:
            Variable names; empty for an unknown tool.
        """
        return self._ports(_OUTPUT_EDGES).get(tool_name, [])

    # --- Study ---

    def get_study_schema(self) -> StudySchema:
        """Read the whole graph as a typed study.

        Returns:
            The variables and the tools with their inputs and outputs, in creation
            order.

        Raises:
            StudyValidationError: If a variable node is a legacy one without a
                ``kind``, or if the stored graph breaks a structural rule.
        """
        variables = self.get_variables()
        inputs = self._ports(_INPUT_EDGES)
        outputs = self._ports(_OUTPUT_EDGES)
        tools = [
            ToolSpec(
                **tool.model_dump(),
                inputs=inputs.get(tool.name, []),
                outputs=outputs.get(tool.name, []),
            )
            for tool in self.get_tools()
        ]
        try:
            return StudySchema(variables=variables, tools=tools)
        except ValidationError as exc:
            raise StudyValidationError(report_from_validation_error(exc)) from exc

    # --- Internals ---

    def _run(self, query: str, **params: Any) -> list[list[Any]]:
        # An empty parameter map would render an invalid ``CYPHER`` header
        return self.graph.query(query, params=params or None).result_set

    def _create(self, queries: _NodeQueries, model: Variable | ToolNode) -> None:
        # The number is drawn first, so a refused creation leaves a gap in ``seq``;
        # only the relative order matters
        seq = self._run(_NEXT_SEQ)[0][0]
        rows = self._run(queries.add, name=model.name, props=_node_props(model, seq))
        if rows[0][0] != seq:
            raise NodeExistsError(queries.label, model.name)

    def _put(self, queries: _NodeQueries, model: Variable | ToolNode) -> bool:
        seq = self._run(_NEXT_SEQ)[0][0]
        rows = self._run(
            queries.put, name=model.name, seq=seq, props=_node_props(model, seq)
        )
        return bool(rows[0][0])

    def _delete(self, queries: _NodeQueries, name: str) -> None:
        if not self._run(queries.exists, name=name):
            raise NodeNotFoundError([(queries.label, name)])
        self._run(queries.delete, name=name)

    def _ports(self, edge_query: str) -> dict[str, list[str]]:
        ports: dict[str, list[str]] = {}
        for tool_name, variable_name in self._run(edge_query):
            ports.setdefault(tool_name, []).append(variable_name)
        return ports

    def _not_found(
        self,
        first: tuple[str, str],
        second: tuple[str, str],
        other_direction: str,
    ) -> NodeNotFoundError:
        """Explain a connection that matched nothing, hinting at swapped arguments."""
        rows = self._run(_NODES_BY_NAME, names=[first[1], second[1]])
        present = {(label, name) for labels, name in rows for label in labels}
        missing = [node for node in (first, second) if node not in present]
        swapped = []
        for label, name in missing:
            actual = _TOOL if label == _VARIABLE else _VARIABLE
            if (actual, name) in present:
                swapped.append(f"'{name}' is a {actual.lower()}")
        hint = None
        if swapped:
            hint = (
                f"{' and '.join(swapped)}; the arguments look swapped, "
                f"use {other_direction} instead"
            )
        return NodeNotFoundError(missing, hint)

__init__(graph=None)

Bind the manager to a graph.

Parameters:

Name Type Description Default
graph Any | None

Graph exposing query(text, params=...). Defaults to the graph of the shared FalkorDBClient.

None
Source code in src/mdo_framework/db/graph_manager.py
190
191
192
193
194
195
196
197
def __init__(self, graph: Any | None = None) -> None:
    """Bind the manager to a graph.

    Args:
        graph: Graph exposing ``query(text, params=...)``. Defaults to the graph
            of the shared ``FalkorDBClient``.
    """
    self.graph = graph if graph is not None else FalkorDBClient().get_graph()

add_tool(tool)

Create a tool.

Parameters:

Name Type Description Default
tool ToolNode

The tool to store.

required

Raises:

Type Description
NodeExistsError

If a tool with this name exists.

Example
gm.add_tool(ToolNode(name="CFD_Solver", fidelity="high"))
Source code in src/mdo_framework/db/graph_manager.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
def add_tool(self, tool: ToolNode) -> None:
    """Create a tool.

    Args:
        tool: The tool to store.

    Raises:
        NodeExistsError: If a tool with this name exists.

    Example:
        ```python
        gm.add_tool(ToolNode(name="CFD_Solver", fidelity="high"))
        ```
    """
    self._create(_TOOL_QUERIES, tool)

add_variable(variable)

Create a variable.

Parameters:

Name Type Description Default
variable Variable

The variable to store.

required

Raises:

Type Description
NodeExistsError

If a variable with this name exists.

Example
gm.add_variable(RangeVar(name="x", lower=-10.0, upper=10.0))
gm.add_variable(StateVar(name="f_xy"))
Source code in src/mdo_framework/db/graph_manager.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def add_variable(self, variable: Variable) -> None:
    """Create a variable.

    Args:
        variable: The variable to store.

    Raises:
        NodeExistsError: If a variable with this name exists.

    Example:
        ```python
        gm.add_variable(RangeVar(name="x", lower=-10.0, upper=10.0))
        gm.add_variable(StateVar(name="f_xy"))
        ```
    """
    self._create(_VARIABLE_QUERIES, variable)

clear_graph()

Delete every node and edge, and restart the seq numbering.

Source code in src/mdo_framework/db/graph_manager.py
199
200
201
def clear_graph(self) -> None:
    """Delete every node and edge, and restart the ``seq`` numbering."""
    self._run(_CLEAR_GRAPH)

connect_input_to_tool(variable_name, tool_name)

Connect a variable to a tool that consumes it (Variable -> Tool).

Connecting twice is harmless.

Parameters:

Name Type Description Default
variable_name str

The consumed variable.

required
tool_name str

The consuming tool.

required

Raises:

Type Description
NodeNotFoundError

If the variable or the tool does not exist. The hint suggests connect_tool_to_output when the arguments look swapped.

RoleConflictError

If the variable is already an output of the tool.

Example
gm.connect_input_to_tool("x", "Paraboloid")
Source code in src/mdo_framework/db/graph_manager.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def connect_input_to_tool(self, variable_name: str, tool_name: str) -> None:
    """Connect a variable to a tool that consumes it (Variable -> Tool).

    Connecting twice is harmless.

    Args:
        variable_name: The consumed variable.
        tool_name: The consuming tool.

    Raises:
        NodeNotFoundError: If the variable or the tool does not exist. The hint
            suggests ``connect_tool_to_output`` when the arguments look swapped.
        RoleConflictError: If the variable is already an output of the tool.

    Example:
        ```python
        gm.connect_input_to_tool("x", "Paraboloid")
        ```
    """
    params = {"variable_name": variable_name, "tool_name": tool_name}
    if self._run(_IS_OUTPUT_OF_TOOL, **params)[0][0]:
        raise RoleConflictError(
            variable_name, _both_roles_message(variable_name, tool_name)
        )
    if not self._run(_CONNECT_INPUT, **params)[0][0]:
        raise self._not_found(
            (_VARIABLE, variable_name),
            (_TOOL, tool_name),
            other_direction="connect_tool_to_output(tool_name, variable_name)",
        )

connect_tool_to_output(tool_name, variable_name)

Connect a tool to a variable it produces (Tool -> Variable).

Connecting twice is harmless.

Parameters:

Name Type Description Default
tool_name str

The producing tool.

required
variable_name str

The produced variable, which must be of kind "state".

required

Raises:

Type Description
NodeNotFoundError

If the tool or the variable does not exist. The hint suggests connect_input_to_tool when the arguments look swapped.

DuplicateProducerError

If another tool already produces the variable.

RoleConflictError

If the variable is a design or fixed variable, or is already an input of the tool.

Example
gm.connect_tool_to_output("Paraboloid", "f_xy")
Source code in src/mdo_framework/db/graph_manager.py
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
def connect_tool_to_output(self, tool_name: str, variable_name: str) -> None:
    """Connect a tool to a variable it produces (Tool -> Variable).

    Connecting twice is harmless.

    Args:
        tool_name: The producing tool.
        variable_name: The produced variable, which must be of kind ``"state"``.

    Raises:
        NodeNotFoundError: If the tool or the variable does not exist. The hint
            suggests ``connect_input_to_tool`` when the arguments look swapped.
        DuplicateProducerError: If another tool already produces the variable.
        RoleConflictError: If the variable is a design or fixed variable, or is
            already an input of the tool.

    Example:
        ```python
        gm.connect_tool_to_output("Paraboloid", "f_xy")
        ```
    """
    params = {"tool_name": tool_name, "variable_name": variable_name}
    for kind, producers, input_edges in self._run(_OUTPUT_CHECK, **params):
        others = [producer for producer in producers if producer != tool_name]
        if others:
            raise DuplicateProducerError(variable_name, (*others, tool_name))
        if kind in _DESIGN_OR_FIXED_KINDS:
            raise RoleConflictError(
                variable_name,
                f"Variable '{variable_name}' has kind '{kind}', so it cannot be "
                "a tool output; declare it as kind 'state'",
            )
        if input_edges:
            raise RoleConflictError(
                variable_name, _both_roles_message(variable_name, tool_name)
            )
    if not self._run(_CONNECT_OUTPUT, **params)[0][0]:
        raise self._not_found(
            (_TOOL, tool_name),
            (_VARIABLE, variable_name),
            other_direction="connect_input_to_tool(variable_name, tool_name)",
        )

delete_tool(name)

Delete a tool and its edges.

Parameters:

Name Type Description Default
name str

Tool name.

required

Raises:

Type Description
NodeNotFoundError

If there is no such tool.

Source code in src/mdo_framework/db/graph_manager.py
324
325
326
327
328
329
330
331
332
333
def delete_tool(self, name: str) -> None:
    """Delete a tool and its edges.

    Args:
        name: Tool name.

    Raises:
        NodeNotFoundError: If there is no such tool.
    """
    self._delete(_TOOL_QUERIES, name)

delete_variable(name)

Delete a variable and its edges.

Parameters:

Name Type Description Default
name str

Variable name.

required

Raises:

Type Description
NodeNotFoundError

If there is no such variable.

Source code in src/mdo_framework/db/graph_manager.py
250
251
252
253
254
255
256
257
258
259
def delete_variable(self, name: str) -> None:
    """Delete a variable and its edges.

    Args:
        name: Variable name.

    Raises:
        NodeNotFoundError: If there is no such variable.
    """
    self._delete(_VARIABLE_QUERIES, name)

get_study_schema()

Read the whole graph as a typed study.

Returns:

Type Description
StudySchema

The variables and the tools with their inputs and outputs, in creation

StudySchema

order.

Raises:

Type Description
StudyValidationError

If a variable node is a legacy one without a kind, or if the stored graph breaks a structural rule.

Source code in src/mdo_framework/db/graph_manager.py
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
def get_study_schema(self) -> StudySchema:
    """Read the whole graph as a typed study.

    Returns:
        The variables and the tools with their inputs and outputs, in creation
        order.

    Raises:
        StudyValidationError: If a variable node is a legacy one without a
            ``kind``, or if the stored graph breaks a structural rule.
    """
    variables = self.get_variables()
    inputs = self._ports(_INPUT_EDGES)
    outputs = self._ports(_OUTPUT_EDGES)
    tools = [
        ToolSpec(
            **tool.model_dump(),
            inputs=inputs.get(tool.name, []),
            outputs=outputs.get(tool.name, []),
        )
        for tool in self.get_tools()
    ]
    try:
        return StudySchema(variables=variables, tools=tools)
    except ValidationError as exc:
        raise StudyValidationError(report_from_validation_error(exc)) from exc

get_tool_inputs(tool_name)

List the variables a tool consumes, in variable creation order.

Parameters:

Name Type Description Default
tool_name str

Tool name.

required

Returns:

Type Description
list[str]

Variable names; empty for an unknown tool.

Source code in src/mdo_framework/db/graph_manager.py
419
420
421
422
423
424
425
426
427
428
def get_tool_inputs(self, tool_name: str) -> list[str]:
    """List the variables a tool consumes, in variable creation order.

    Args:
        tool_name: Tool name.

    Returns:
        Variable names; empty for an unknown tool.
    """
    return self._ports(_INPUT_EDGES).get(tool_name, [])

get_tool_outputs(tool_name)

List the variables a tool produces, in variable creation order.

Parameters:

Name Type Description Default
tool_name str

Tool name.

required

Returns:

Type Description
list[str]

Variable names; empty for an unknown tool.

Source code in src/mdo_framework/db/graph_manager.py
430
431
432
433
434
435
436
437
438
439
def get_tool_outputs(self, tool_name: str) -> list[str]:
    """List the variables a tool produces, in variable creation order.

    Args:
        tool_name: Tool name.

    Returns:
        Variable names; empty for an unknown tool.
    """
    return self._ports(_OUTPUT_EDGES).get(tool_name, [])

get_tools()

List the tools in creation order.

Returns:

Type Description
list[ToolNode]

The stored tools, without their connections.

Source code in src/mdo_framework/db/graph_manager.py
335
336
337
338
339
340
341
def get_tools(self) -> list[ToolNode]:
    """List the tools in creation order.

    Returns:
        The stored tools, without their connections.
    """
    return [_tool_from_node(node) for (node,) in self._run(_TOOL_QUERIES.list_all)]

get_variables()

List the variables in creation order.

Returns:

Type Description
list[Variable]

The stored variables.

Raises:

Type Description
StudyValidationError

With a LEGACY_NODE finding for every variable node created without a kind by an older version.

Source code in src/mdo_framework/db/graph_manager.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
def get_variables(self) -> list[Variable]:
    """List the variables in creation order.

    Returns:
        The stored variables.

    Raises:
        StudyValidationError: With a ``LEGACY_NODE`` finding for every variable
            node created without a ``kind`` by an older version.
    """
    variables: list[Variable] = []
    legacy: list[Finding] = []
    for (node,) in self._run(_VARIABLE_QUERIES.list_all):
        properties = _node_properties(node)
        if "kind" in properties:
            variables.append(_VARIABLE_ADAPTER.validate_python(properties))
            continue
        name = properties.get("name")
        legacy.append(
            Finding(
                code="LEGACY_NODE",
                message=(
                    f"Variable '{name}' has no 'kind'; "
                    "delete and recreate it with the typed API"
                ),
                names=(name,),
            )
        )
    if legacy:
        raise StudyValidationError(ValidationReport(errors=tuple(legacy)))
    return variables

put_tool(tool)

Create a tool, or replace every property of an existing one.

The seq number, hence the position, and the edges are kept on replace.

Parameters:

Name Type Description Default
tool ToolNode

The tool to store.

required

Returns:

Type Description
bool

True if it was created, False if it replaced an existing one.

Source code in src/mdo_framework/db/graph_manager.py
311
312
313
314
315
316
317
318
319
320
321
322
def put_tool(self, tool: ToolNode) -> bool:
    """Create a tool, or replace every property of an existing one.

    The ``seq`` number, hence the position, and the edges are kept on replace.

    Args:
        tool: The tool to store.

    Returns:
        ``True`` if it was created, ``False`` if it replaced an existing one.
    """
    return self._put(_TOOL_QUERIES, tool)

put_variable(variable)

Create a variable, or replace every property of an existing one.

The seq number, hence the position, and the edges are kept on replace.

Parameters:

Name Type Description Default
variable Variable

The variable to store.

required

Returns:

Type Description
bool

True if it was created, False if it replaced an existing one.

Raises:

Type Description
RoleConflictError

If the existing variable is produced by a tool and the new kind is not "state".

Source code in src/mdo_framework/db/graph_manager.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def put_variable(self, variable: Variable) -> bool:
    """Create a variable, or replace every property of an existing one.

    The ``seq`` number, hence the position, and the edges are kept on replace.

    Args:
        variable: The variable to store.

    Returns:
        ``True`` if it was created, ``False`` if it replaced an existing one.

    Raises:
        RoleConflictError: If the existing variable is produced by a tool and
            the new kind is not ``"state"``.
    """
    if variable.kind != "state":
        producers = [
            row[0] for row in self._run(_PRODUCERS_OF_VARIABLE, name=variable.name)
        ]
        if producers:
            raise RoleConflictError(
                variable.name,
                f"Variable '{variable.name}' is produced by "
                f"{', '.join(producers)} and must keep kind 'state', "
                f"not '{variable.kind}'",
            )
    return self._put(_VARIABLE_QUERIES, variable)