Skip to content

docs: architecture review + Rust-suitability analysis with SVG diagrams#1136

Open
yijunyu wants to merge 1 commit into
hw-native-sys:mainfrom
yijunyu:docs/architecture-rust-svg
Open

docs: architecture review + Rust-suitability analysis with SVG diagrams#1136
yijunyu wants to merge 1 commit into
hw-native-sys:mainfrom
yijunyu:docs/architecture-rust-svg

Conversation

@yijunyu

@yijunyu yijunyu commented Jun 24, 2026

Copy link
Copy Markdown

Add an external review of the runtime architecture:

  • the L0-L6 7-layer level model and the L2 chip-level three-program model
  • the Orchestrator / Scheduler / Worker engine composition
  • a component-by-component Rust-suitability map, each with the single dominant reason to use or avoid Rust (concurrency-safety, lifetime-safety, parsing-safety vs ffi-cost, toolchain, no-backend)

Diagrams render to docs/diagrams/architecture.svg via a stdlib generator (docs/diagrams/make_diagrams.py); the doc embeds the SVG and keeps inline ASCII equivalents. Review only -- no code changes.

Add an external review of the runtime architecture:
- the L0-L6 7-layer level model and the L2 chip-level three-program model
- the Orchestrator / Scheduler / Worker engine composition
- a component-by-component Rust-suitability map, each with the single
  dominant reason to use or avoid Rust (concurrency-safety, lifetime-safety,
  parsing-safety vs ffi-cost, toolchain, no-backend)

Diagrams render to docs/diagrams/architecture.svg via a stdlib generator
(docs/diagrams/make_diagrams.py); the doc embeds the SVG and keeps inline
ASCII equivalents. Review only -- no code changes.
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds two new files to the docs/ directory: a Markdown architecture review analyzing SIMPLER's 7-layer (L0–L6) model, Orchestrator/Scheduler/Worker engine components, and a component-by-component Rust suitability assessment with a migration recommendation; and a pure-stdlib Python script that generates a self-contained three-panel SVG diagram illustrating those same structures.

Changes

Architecture Documentation and SVG Generator

Layer / File(s) Summary
Architecture review and Rust suitability document
docs/architecture-review-and-rust-analysis.md
Introduces the SIMPLER project context and L0–L6 level model, describes the Orchestrator/Scheduler/Worker engine components and L2 chip boundary, provides a tabular component-to-Rust-applicability mapping with labeled reasons (concurrency, lifetime, parsing, FFI/toolchain), and concludes with a host-side migration recommendation.
SVG diagram generator script
docs/diagrams/make_diagrams.py
Defines global layout constants and SVG primitive helpers (esc, box, label, arrow), implements three panel builders (panel_level for the 7-layer hierarchy, panel_engine for the three-program model, panel_rust for the suitability matrix), and assembles all panels into a single architecture.svg file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop through layers L0 to six,
Where Rust meets C++ in the mix!
A script draws boxes, arrows, and lines,
While Markdown maps the architecture's designs.
The rabbit reads the docs with glee—
Host-side Rust, as clear as can be! 🦀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: an architecture review, Rust-suitability analysis, and SVG diagrams.
Description check ✅ Passed The description is directly related to the documented architecture review and diagram generator changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds documentation for the SIMPLER / PTO Runtime architecture review and Rust-suitability analysis, along with an SVG diagram and a Python script to generate it. The review feedback suggests a robust file-writing pattern in the Python script by using a context manager and specifying UTF-8 encoding to prevent potential Unicode encoding errors on systems where UTF-8 is not the default.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

parts.append("</svg>")

out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "architecture.svg")
open(out, "w").write("\n".join(parts))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Writing a file containing Unicode characters (such as ·, , , , , ──) without specifying an explicit encoding can lead to a UnicodeEncodeError on systems where the default encoding is not UTF-8 (e.g., Windows). Additionally, using a with statement is recommended to ensure the file descriptor is reliably closed.

Suggested change
open(out, "w").write("\n".join(parts))
with open(out, "w", encoding="utf-8") as f:
f.write("\n".join(parts))

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
docs/diagrams/make_diagrams.py (1)

158-177: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Guard execution and make file output encoding explicit.

Move generation into main() and write with encoding="utf-8" via a context manager to avoid import-time side effects and locale-dependent output.

Suggested refactor
-panels = [panel_level(), panel_engine(), panel_rust()]
-gap = 28
-total_h = sum(h for _, h in panels) + gap * (len(panels) + 1)
-
-parts = [
-    f'<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{total_h}" viewBox="0 0 {W} {total_h}" font-family="DejaVu Sans, sans-serif">',
-    f'<defs><marker id="arr" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto"><path d="M0,0 L9,4.5 L0,9 z" fill="{MUTE}"/></marker></defs>',
-    f'<rect width="{W}" height="{total_h}" fill="{BG}"/>',
-    f'<text x="30" y="-6" fill="{INK}"></text>',
-]
-cy = gap
-for frag, hh in panels:
-    parts.append(f'<rect x="14" y="{cy-10}" width="{W-28}" height="{hh+18}" rx="10" fill="{PANEL}" opacity="0.35"/>')
-    parts.append(f'<g transform="translate(0,{cy})">{frag}</g>')
-    cy += hh + gap
-parts.append("</svg>")
-
-out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "architecture.svg")
-open(out, "w").write("\n".join(parts))
-print("wrote", out, f"({total_h}px tall)")
+def main():
+    panels = [panel_level(), panel_engine(), panel_rust()]
+    gap = 28
+    total_h = sum(h for _, h in panels) + gap * (len(panels) + 1)
+
+    parts = [
+        f'<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{total_h}" viewBox="0 0 {W} {total_h}" font-family="DejaVu Sans, sans-serif">',
+        f'<defs><marker id="arr" markerWidth="9" markerHeight="9" refX="7" refY="4.5" orient="auto"><path d="M0,0 L9,4.5 L0,9 z" fill="{MUTE}"/></marker></defs>',
+        f'<rect width="{W}" height="{total_h}" fill="{BG}"/>',
+        f'<text x="30" y="-6" fill="{INK}"></text>',
+    ]
+    cy = gap
+    for frag, hh in panels:
+        parts.append(f'<rect x="14" y="{cy-10}" width="{W-28}" height="{hh+18}" rx="10" fill="{PANEL}" opacity="0.35"/>')
+        parts.append(f'<g transform="translate(0,{cy})">{frag}</g>')
+        cy += hh + gap
+    parts.append("</svg>")
+
+    out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "architecture.svg")
+    with open(out, "w", encoding="utf-8") as f:
+        f.write("\n".join(parts))
+    print("wrote", out, f"({total_h}px tall)")
+
+
+if __name__ == "__main__":
+    main()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/diagrams/make_diagrams.py` around lines 158 - 177, The SVG generation
logic in make_diagrams.py currently runs at import time and writes the output
file without an explicit encoding. Move the panel assembly, SVG construction,
and file write into a main() entry point guarded by a __name__ == "__main__"
check, and use a context manager with encoding="utf-8" when writing the
architecture.svg file to keep side effects out of imports and make output
encoding explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/architecture-review-and-rust-analysis.md`:
- Line 252: Remove the accidental standalone fenced-block opener at the end of
the markdown document to satisfy markdownlint MD040. Locate the trailing
markdown content in docs/architecture-review-and-rust-analysis.md and delete the
stray code fence so the file ends cleanly without an unmatched fence.

In `@docs/diagrams/make_diagrams.py`:
- Line 15: The module-level constant assignments in make_diagrams.py are joined
with semicolons, which triggers Ruff E702. Split the combined assignments for
the palette constants (such as BG, PANEL, INK, MUTE, and the later pair on the
other flagged line) into separate statements so each assignment appears on its
own line and the lint gate passes.

---

Nitpick comments:
In `@docs/diagrams/make_diagrams.py`:
- Around line 158-177: The SVG generation logic in make_diagrams.py currently
runs at import time and writes the output file without an explicit encoding.
Move the panel assembly, SVG construction, and file write into a main() entry
point guarded by a __name__ == "__main__" check, and use a context manager with
encoding="utf-8" when writing the architecture.svg file to keep side effects out
of imports and make output encoding explicit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a764021e-b934-45b0-b1e7-44b415a4cf82

📥 Commits

Reviewing files that changed from the base of the PR and between 6dd8a5d and 3d0e9c7.

⛔ Files ignored due to path filters (1)
  • docs/diagrams/architecture.svg is excluded by !**/*.svg
📒 Files selected for processing (2)
  • docs/architecture-review-and-rust-analysis.md
  • docs/diagrams/make_diagrams.py

(scheduler + orchestrator + ring/tensormap/scope + remote_wire), exposed to the
existing Python via PyO3 — leaving the CANN FFI host runtime and the device
kernels in C++.
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the accidental fenced-block opener at EOF.

Line 252 adds a standalone code fence, which triggers markdownlint MD040 and can affect markdown rendering consistency.

Suggested fix
-```
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 252-252: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/architecture-review-and-rust-analysis.md` at line 252, Remove the
accidental standalone fenced-block opener at the end of the markdown document to
satisfy markdownlint MD040. Locate the trailing markdown content in
docs/architecture-review-and-rust-analysis.md and delete the stray code fence so
the file ends cleanly without an unmatched fence.

Source: Linters/SAST tools

PADDED = [] # (svg fragment, height) appended per panel

# ---- palette ----
BG = "#0e1116"; PANEL = "#161b22"; INK = "#e6edf3"; MUTE = "#8b949e"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Split semicolon-joined assignments to satisfy Ruff E702.

Ruff flags Lines 15 and 22 as errors (E702), so this will fail lint gates.

Suggested fix
-BG = "`#0e1116`"; PANEL = "`#161b22`"; INK = "`#e6edf3`"; MUTE = "`#8b949e`"
+BG = "`#0e1116`"
+PANEL = "`#161b22`"
+INK = "`#e6edf3`"
+MUTE = "`#8b949e`"
@@
-ORCH = "`#b7791f`"; SCHED = "`#2f6f4f`"; WORK = "`#3a5f8a`"
+ORCH = "`#b7791f`"
+SCHED = "`#2f6f4f`"
+WORK = "`#3a5f8a`"

Also applies to: 22-22

🧰 Tools
🪛 Ruff (0.15.18)

[error] 15-15: Multiple statements on one line (semicolon)

(E702)


[error] 15-15: Multiple statements on one line (semicolon)

(E702)


[error] 15-15: Multiple statements on one line (semicolon)

(E702)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/diagrams/make_diagrams.py` at line 15, The module-level constant
assignments in make_diagrams.py are joined with semicolons, which triggers Ruff
E702. Split the combined assignments for the palette constants (such as BG,
PANEL, INK, MUTE, and the later pair on the other flagged line) into separate
statements so each assignment appears on its own line and the lint gate passes.

Source: Linters/SAST tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant