{
  "node": {
    "id": "block:native-state-writer",
    "type": "Block",
    "label": "Scoped state writer",
    "properties": {
      "id": "native-state-writer",
      "name": "Scoped state writer",
      "kind": "studio",
      "summary": "Replaces a declared discrete state-space child state on an enabled write, then evaluates output and advances that state at the accepted sample.",
      "behavior": "Replaces a declared discrete state-space child state on an enabled write, then evaluates output and advances that state at the accepted sample. Trial evaluations read the held output without mutating state.",
      "ports": [
        {
          "name": "in0",
          "direction": "input",
          "unit": "—",
          "description": "Input; real scalar."
        },
        {
          "name": "in1",
          "direction": "input",
          "unit": "—",
          "description": "Replacement state; real vector [1]."
        },
        {
          "name": "in2",
          "direction": "input",
          "unit": "—",
          "description": "Write enabled; bool scalar."
        },
        {
          "name": "out0",
          "direction": "output",
          "unit": "—",
          "description": "Output; real scalar."
        },
        {
          "name": "out1",
          "direction": "output",
          "unit": "—",
          "description": "State before update; real vector [1]."
        },
        {
          "name": "out2",
          "direction": "output",
          "unit": "—",
          "description": "State after update; real vector [1]."
        },
        {
          "name": "out3",
          "direction": "output",
          "unit": "—",
          "description": "Write accepted; bool scalar."
        }
      ],
      "parameters": [
        {
          "key": "sampleTimeS",
          "label": "Sample period",
          "unit": "s",
          "default": 1,
          "description": "Positive period between accepted updates; outputs hold between updates."
        },
        {
          "key": "tables[0]",
          "label": "Initial held output",
          "unit": "—",
          "default": [
            0
          ],
          "description": "Output held before the first accepted update, with one value per output lane."
        },
        {
          "key": "nested",
          "label": "Declared child operation",
          "unit": "—",
          "default": "Discrete state space",
          "description": "The locally owned target operation. Its parameters, initial state, and typed ports are configured explicitly."
        },
        {
          "key": "nested.parameters.config.tables[0]",
          "label": "State transition matrix",
          "unit": "—",
          "default": [
            0.5
          ],
          "description": "Matrix A in x_next = A x + B u."
        },
        {
          "key": "nested.parameters.config.tables[1]",
          "label": "Input matrix",
          "unit": "—",
          "default": [
            1
          ],
          "description": "Matrix B in x_next = A x + B u."
        },
        {
          "key": "nested.parameters.config.tables[2]",
          "label": "Output matrix",
          "unit": "—",
          "default": [
            2
          ],
          "description": "Matrix C in y = C x + D u."
        },
        {
          "key": "nested.parameters.config.tables[3]",
          "label": "Direct input matrix",
          "unit": "—",
          "default": [
            3
          ],
          "description": "Matrix D in y = C x + D u."
        },
        {
          "key": "nested.parameters.config.tables[4]",
          "label": "Initial state",
          "unit": "—",
          "default": [
            4
          ],
          "description": "Initial internal coordinates before an optional enabled replacement."
        }
      ],
      "equations": [
        "If write enabled: internal child state ← replacement state",
        "Observe x_before; then y = C x_before + D u",
        "Commit x_after = A x_before + B u only after the full update succeeds"
      ],
      "example": {
        "title": "Scoped state writer worked example",
        "text": "For A=0.5, B=1, C=2, D=3 and input 1, replacing the state with 10 before execution yields output 23 and next state 6.",
        "url": "https://design.lemonergy.com/cosim.html?example=block-native-state-writer",
        "label": "Open Studio example",
        "inputs": [
          {
            "port": "in0",
            "label": "Input",
            "value": 1,
            "unit": "—"
          },
          {
            "port": "in1",
            "label": "Replacement state",
            "value": [
              10
            ],
            "unit": "—"
          },
          {
            "port": "in2",
            "label": "Write enabled",
            "value": 1,
            "unit": "—"
          }
        ],
        "checks": [
          {
            "port": "out0",
            "label": "Output",
            "atS": 0,
            "value": 23,
            "unit": "—",
            "tolerance": 1e-08
          },
          {
            "port": "out1",
            "label": "State before update",
            "atS": 0,
            "value": [
              10
            ],
            "unit": "—",
            "tolerance": 1e-08
          },
          {
            "port": "out2",
            "label": "State after update",
            "atS": 0,
            "value": [
              6
            ],
            "unit": "—",
            "tolerance": 1e-08
          },
          {
            "port": "out3",
            "label": "Write accepted",
            "atS": 0,
            "value": 1,
            "unit": "—",
            "tolerance": 1e-08
          }
        ]
      },
      "limits": [
        "One declared discrete linear state-space child, with 1–128 real state coordinates. No arbitrary external-block, continuous-state, or history-buffer writes.",
        "Replacement is applied before output evaluation and state advancement. A failed or nonfinite update commits no partial state. Separate block instances own separate state."
      ],
      "references": [
        "control-discrete-state-space"
      ],
      "availability": {
        "status": "released",
        "label": "Available in Lemonergy Studio",
        "detail": "The bundled example is available in the production release verified on 28 October 2026. The parameters and examples here are synthetic teaching fixtures, not a characterized cell or a validated operating limit."
      },
      "evidence": [
        "docs/glossary/native-block-verification.json"
      ],
      "sourceRepository": "Lemonergy Studio public contract",
      "sourceRevision": "verification-2026-10-27",
      "caseIds": [
        "native-native-state-writer"
      ],
      "exampleTraces": [
        {
          "id": "native-state-writer",
          "url": "https://lemonergy.com/learn/glossary/api/traces/native-state-writer.json?v=706fb9b80e13",
          "title": "Scoped state writer recorded example",
          "exampleId": "block-native-state-writer",
          "source": "Executed synthetic Lemonergy Studio example",
          "recordedOn": "2026-10-28",
          "points": 3,
          "channels": 4,
          "omittedChannels": 0,
          "interpolation": "step",
          "solver": {
            "method": "dormand-prince-45",
            "reason": "no-continuous-states"
          }
        }
      ],
      "type": "native-state-writer",
      "implementationId": "native-state-writer",
      "url": "https://lemonergy.com/learn/glossary/blocks/native-state-writer/",
      "documentationUrl": "https://lemonergy.com/learn/glossary/blocks/native-state-writer/",
      "sourceFile": "block-library.json",
      "reviewed": "2026-10-27",
      "releaseEvidence": {
        "environment": "production",
        "status": "verified",
        "revision": "e76cadfc203e15eb41f3478d8b1044a5b851953d",
        "verifiedOn": "2026-10-28",
        "exampleUrls": [
          "https://design.lemonergy.com/cosim.html?example=block-native-state-writer"
        ]
      }
    }
  },
  "incoming": [
    {
      "id": "edge:usesBlock/native-native-state-writer/0",
      "type": "usesBlock",
      "source": "workflow:native-native-state-writer",
      "target": "block:native-state-writer",
      "properties": {
        "sourceFile": "wiki-blocks.json",
        "position": 0,
        "name": "Scoped state writer",
        "type": "native-state-writer",
        "role": "Replaces a declared discrete state-space child state on an enabled write, then evaluates output and advances that state at the accepted sample. Trial evaluations read the held output without mutating state.",
        "settings": [
          "Use the block reference for settings and connections.",
          "Bundled example verified on the production release of 28 October 2026."
        ]
      }
    }
  ],
  "outgoing": [
    {
      "id": "edge:cites/block:native-state-writer/reference:control-discrete-state-space",
      "type": "cites",
      "source": "block:native-state-writer",
      "target": "reference:control-discrete-state-space",
      "properties": {
        "sourceFile": "block-library.json",
        "scope": "Scientific or mathematical background; implementation scope is stated by the block contract"
      }
    }
  ],
  "neighbors": [
    {
      "id": "workflow:native-native-state-writer",
      "type": "Workflow",
      "label": "Scoped state writer worked example",
      "properties": {
        "id": "native-native-state-writer",
        "title": "Scoped state writer worked example",
        "kind": "studio",
        "summary": "Replaces a declared discrete state-space child state on an enabled write, then evaluates output and advances that state at the accepted sample.",
        "steps": [
          "Review the interface, units and model limits.",
          "Open the Studio example and run its bundled model.",
          "Compare outputs with the numerical checks; change one input and run again."
        ],
        "example": "For A=0.5, B=1, C=2, D=3 and input 1, replacing the state with 10 before execution yields output 23 and next state 6.",
        "observe": "Inspect the output channels and checks on the block reference page.",
        "limits": "One declared discrete linear state-space child, with 1–128 real state coordinates. No arbitrary external-block, continuous-state, or history-buffer writes. Replacement is applied before output evaluation and state advancement. A failed or nonfinite update commits no partial state. Separate block instances own separate state.",
        "url": "https://design.lemonergy.com/cosim.html?example=block-native-state-writer",
        "label": "Open Studio example",
        "evidence": [
          "docs/glossary/native-block-verification.json"
        ]
      }
    },
    {
      "id": "reference:control-discrete-state-space",
      "type": "Reference",
      "label": "Feedback Systems: System Modeling, Section 2.1, discrete-time systems",
      "properties": {
        "title": "Feedback Systems: System Modeling, Section 2.1, discrete-time systems",
        "authors": [
          "Karl Johan Åström",
          "Richard M. Murray"
        ],
        "publisher": "Princeton University Press; author-hosted chapter, California Institute of Technology",
        "url": "https://www.cds.caltech.edu/~murray/books/AM08/pdf/am08-modeling_10Aug12.pdf",
        "type": "Textbook chapter",
        "scope": "Discrete state-space equations and the distinction between internal state and output. Scoped write ordering is a separate Lemonergy contract.",
        "accessed": "2026-10-28"
      }
    }
  ]
}
