The view in Model Explorer¶
Summary
explore(stage) opens the four graphs of a stage version in Model Explorer, Google's viewer of large graphs, which runs in the browser: its two initial diagrams, the fields of the stage file in the boxes of their perches, related by its blocks, and its two builders graphs. In a builders graph each builder is a box that opens to its sub-builders and its primitive operators, each operator a box that names its kind above its symbol, every wire is an edge whose two ends hold its perch and its type, and a selected operation shows the rows of its card, its kernel and the method bound to it, each on its own line. The package writes the view as two files and serves the graph file to the viewer; a trellis is viewed in the same way, with a box for each period and for each stage occurrence inside it, a stage occurrence being one use of a stage file in a period (The Bellman factory §1), and the fill of a box names its level, from a period to a sub-builder. The view writes no mathematics of its own: an operator's symbol is the one the drawing prints, with each law of motion named as the operator's card names it and without the arguments of a law or an aggregator written out at a policy, (·, 𝑐) and (·, ·, 𝑐); every port's label is one the drawing prints; and the drawing that diagram() answers remains the figure of a page or a lesson. The examples are from applications/portfolio-choice/declaration/stages/cons/cons.bl where no other file is named.
Relationship with other documents
Builds on — The builders graphs: the two graphs and their grains, which the view draws as boxes inside boxes; A builder: the operations of a builder and their cards, which the side panel shows row by row. See also — Methods and places: the methods whose tags the boxes of §4.2 carry; The trellis factory: the trellises that §5 views.
Key terminology
| Term | What it names |
|---|---|
| Model Explorer | Google's viewer of large graphs, the Python package ai-edge-model-explorer: a server on the reader's machine and a page in the browser. |
| Layer | A box of the view that is drawn closed and opens with a click to show what it holds: a builder or a sub-builder, and in a trellis a period or a stage occurrence. |
| Node | A box of the view that opens to nothing: a primitive operator, or one of the two nodes that hold a graph's own inputs and outputs. |
| Port | One input or one output of a node, the end of one wire. |
| Side panel | The pane at the right of the page, which lists the attributes of the node or the layer selected and the ports of a node. |
| Overlay | A set of lines in one color that the reader turns on and off: each line joins the two nodes of an edge of the graph (§4.1). |
1 What a user writes¶
The view is written by two functions that stand in bellman.stage and in bellman.trellis, explore and write_model_explorer, defined in the module bellman.factory.model_explorer of the Bellman factory, and by no verb of the stage:
from bellman.stage import elaborate_stage, explore, load_stage, write_model_explorer
stage = elaborate_stage(load_stage("applications/portfolio-choice/declaration/stages/cons/cons.bl"))
paths, address = explore(stage)
explore(stage) writes the two files of §2 into the folder model-explorer/ beside the stage file, starts the viewer's server unless a server already answers at port 8080, and opens the page in the default browser with the layers of the builders open; port 8080 is a network port of the machine, not a port of a node. It prints the address and a reminder of the one setting of §6, and answers the paths of the two files and the address. The call that starts the server, the first explore of a notebook's kernel or of a script where no other process serves the port, also prints the viewer's own start-up lines, among them a second address and "Press Ctrl+C to stop.", which the reader may ignore. folder= names another folder for the files and port= another port; open_browser=False writes the files alone and answers the address None. explore(trellis) does the same for a trellis, the dictionary that elaborate_trellis returns, opens the layers of its periods and locates the page on the first period after the terminal one (§5).
write_model_explorer(stage, folder) writes the two files alone and answers their paths, the graph file first. serve, which answers the address of a page on the viewer's server that shows a graph file and opens no browser, is imported from the module:
from bellman.factory.model_explorer import serve
graph, overlays = write_model_explorer(stage, "model-explorer")
address = serve(graph, port=8080, layers=("cntn_to_dcsn", "policy"))
The page opens on the graph that graph_id= names, one of the four of §3.1, or, where none is named, on the backward builders graph backward, and on the file's first graph where it holds none, with the layers that layers names open, and fitted to the whole graph unless located= names a layer, located="periods[1]", which the page then selects and fits to its window. serve starts a server only where none answers on the port. A server that another Python process started, the kernel of another notebook for instance, serves the page as well, since the address names the graph file by its path on the machine; a port at which something other than the viewer answers is refused in one sentence. The server runs in a background thread of the process that started it and stops when that process ends. One server serves any number of pages at once, and each page stays independent of the others.
to_model_explorer and perch_overlays, functions of bellman.factory.model_explorer, answer for a stage or a trellis the same graphs and overlays as the viewer's own Python objects, without writing a file.
The viewer is installed with the package's extra explore, from the root of the repository:
Without it, a function of the module that needs the viewer raises an ImportError whose one sentence names the extra and the commands that install it.
2 The two files¶
The two files are named by the view's label: the stage's name, followed by a word for each binding the version holds, calibrated, methodized and configured, with a hyphen in place of each space; a trellis is labeled trellis. The symbolic version of cons writes two files:
cons.graph.json, the four graphs of §3.1,backward initial diagram,forward initial diagram,backwardandforward, which the viewer opens as a model file;cons.edge-overlays.json, the three perch overlays of §4.1, each holding every edge of the four graphs whose wire stands at its perch, which a reader loads through the viewer's panel of edge overlays.
cons methodized alone writes cons-methodized.graph.json and cons-methodized.edge-overlays.json, and the specified version, calibrated, methodized and configured, writes cons-calibrated-methodized-configured.graph.json and the file of overlays beside it. The viewer shows the label with its spaces, cons methodized, at the top of the page. The files are JSON in ASCII alone: every other character is written as its JSON escape, so that 𝑉≻ stands in a file as \ud835\udc49\u227b, which the viewer reads back as 𝑉≻. The viewer's server reads a file in the system's default encoding, which on some machines is not UTF-8, and a file in ASCII is read alike under any code page.
3 What the view shows¶
3.1 The graphs and their layers¶
The viewer shows one graph at a time, chosen at the top of the page, where four are listed: backward initial diagram and forward initial diagram, the two initial diagrams, the fields of the stage file at their perches, related by the blocks that read and write them; then backward, the builders a solution applies, on value functions, the policy builder among them, and forward, the builders a simulation applies, on measures (The builders graphs §3). explore(stage) opens the page on backward. The viewer lays out each graph itself, a builders graph from top to bottom and an initial diagram from left to right.
In an initial diagram the fields are the nodes and the blocks relate them, as the field diagram of the calculus is drawn (Fields, functions and types §2). Each perch that holds a field of the diagram is a layer named by the perch's word, arvl, dcsn or cntn, and the layers stand in the order the direction reads the perches, so that the forward diagram reads arrival, decision, continuation from left to right and the backward one continuation, decision, arrival. Each field is a node inside the layer of its perch, named by the field's identity, cons:dcsn:m_d, labeled as the drawing labels the field, V≻, m_d, a≻, and filled white; the fields of one perch stand one under another. A shock, which belongs to no perch, stands outside the layers. Each block is a node outside the layers, named and labeled by its id and filled white, with an edge from each field it reads and an edge into each field it writes, so that it stands between the perches it joins; the diagram opens no further layer, since a block's lines stand in its attributes (§3.3). The diagram has no nodes Inputs and Outputs: a field no block writes is one the diagram takes, and a field no block reads one it gives. The backward initial diagram of cons holds V≻ in the layer cntn, V and c in dcsn and V≺ in arvl, related by the three blocks cntn_to_dcsn, dcsn_to_arvl and policy, and the forward one m≺, m_d and a≻, one in each layer, related by arvl_to_dcsn and dcsn_to_cntn.
Each builder is a layer named by the id of its block: cntn_to_dcsn, dcsn_to_arvl and policy in the backward graph of cons. A builder's layer opens to its sub-builders, each a layer named by its builder and its key, such as cntn_to_dcsn/risk_ce in the savings stage applications/smooth-ambiguity-savings/declaration/stages/sa_savings/sa_savings.bl, and to its primitive operators, the finest boxes the construction makes (The builders graphs §4). These are the three grains a reader reaches from the stage, and the view shows no other. An operator formed by a line that is no sub-builder, such as the aggregation of the policy builder's candidate line, stands directly in its builder's layer.
Each primitive operator is a node. Its id is its whole name, cntn_to_dcsn:Aggregation, the key that reads it at the primitive grain, and its label is two lines. The first is the kind of its operator, as the attribute kind writes it (§3.3), followed, where the operator is stated at a policy (Operations §3), by at and the policies it is stated at, separated by commas: Pullback at 𝑐 in cons, and Pullback at 𝑐, ℎ_choice in the durables model's adjuster stage applications/durables/declaration/stages/adjuster_cons/adjuster_cons.bl, whose policy chooses consumption and housing together. The second is the symbol the drawing shows for the operator, without the arguments of a law or an aggregator written out at a policy, the (·, 𝑐) of the drawing's 𝑉≻ ∘ 𝑔(·, 𝑐) and the (·, ·, 𝑐) of its 𝐺(·, ·, 𝑐), which the operator's rules state in full (§3.3). The pullback of the decision builder is labeled Pullback at 𝑐 over 𝑉≻ ∘ 𝑔≻ and its aggregation Aggregation at 𝑐 over 𝐺; the objective and the maximization of the policy builder, formed by the line optimality, are labeled Aggregation over 𝐺 · optimality and Argmax over argmax · optimality, and on a version methodized by the stage's methods file the candidate line and the identification that stand in their place are labeled Aggregation over 𝐺 · InvEuler and Pullback over 𝑐 ∘ 𝑚_d≻ (§4.2); and an evaluation names the outputs it produces, as the drawing does, so that the evaluation of the decision builder is labeled Evaluation over 𝑉(m_d). An evaluation with three or more outputs names the first two and counts the others, ending its label with and 1 more where it has three, and its rule rows and its output ports name them all (§3.2 and §3.3). A law of motion is named as the operator's card names it, so that the operators that read one law name it alike: the pullback of cntn_to_dcsn and the push-forward of dcsn_to_cntn both name 𝑔≻, the law from the decision perch to the continuation perch, 𝑉≻ ∘ 𝑔≻ and 𝑔≻∗μ, and the pullback of dcsn_to_arvl and the push-forward of arvl_to_dcsn both name 𝑔≺, the law from the arrival perch to the decision perch, 𝑉 ∘ 𝑔≺ and 𝑔≺∗μ, where the drawing that diagram() answers writes the letter 𝑔 for both laws. Where a method is bound within the operator, the second line ends with its tag (§4.2). Inputs, Outputs and the fields and blocks of an initial diagram, which apply no operator, have labels of one line.
The view takes its colors from the project's site, and they tell apart the levels a reader opens and what each builder gives: navy for borders and labels, white and three pale blues for the fills, ultramarine for a builder's outputs, and orange for a refusal (§3.5). A node is white with a navy border and a navy label, and its border turns ultramarine under the pointer. The node of an operator that writes a wire read outside its builder's layer, by another builder, by Outputs or, in a trellis, by a join (§5), has an ultramarine border instead, which turns navy under the pointer, so that what each builder gives is seen at a glance: in the view of cons, the three evaluations of the backward graph and the two push-forwards of the forward graph. Each layer has a navy border and a navy label, and its fill names its level, one shade darker at each level a reader opens: in a trellis a period is white and a stage occurrence stands on the lightest of the three blues (§5), a builder stands on the second and a sub-builder on the third, the darkest. The perch layers of an initial diagram stand on the lightest blue, the shade of the stage they divide. The viewer draws no dashed border, by which the drawing marks an evaluation and a policy insertion; the first line of a label names the kind of every operator, and a kind has no color. The drawing that diagram() answers keeps its own colors.
Two further nodes, Inputs and Outputs, white with a navy border, stand in no layer and hold the graph's own inputs and outputs. The backward graph of cons takes the continuation value, 𝑉≻(a), from Inputs, and gives the arrival value and the policy, 𝑉≺(m) and 𝑐(m_d), to Outputs.
3.2 Wires and ports¶
Every wire of a builders graph is an edge from the node that writes it to each node that reads it; in an initial diagram a field is a node (§3.1), and an edge joins it to each block that writes or reads it. The ports of a node stand in the order of the wires its operator reads and writes, and the id of a port is the identity of its wire, such as cons:function:cntn:V, the same at both ends of an edge. The two ends of a wire hold the same attributes, and an attribute that would hold nothing is not written:
label, the wire's label as the drawing prints it, such as𝑉≻(a)orμ≺;perch, the perch the wire stands at,arvl,dcsnorcntn; a wire at no perch, such as the result of an aggregation, has none;role, the role of the object the wire carries, such asvalue,control,stateormeasure;type, the wire's type as a builder'ssignature()prints it, such asXm → [−∞, ∞)orfinite measure on Xm; on a field wire of an initial diagram,setinstead, the field's declared set as the fields table prints it,[-inf, inf), where the header declares one.
The side panel lists the ports of a selected node, each with these attributes, and under an input also namespace, which the viewer adds. An input is headed by the wire's label followed, in parentheses, by the label of the node that writes the wire, whose two lines the panel prints on one: on cntn_to_dcsn:Aggregation, 𝑉≻(𝑔(m_d, 𝑐(m_d))) (Pullback at 𝑐 𝑉≻ ∘ 𝑔≻). An output is headed by the label of the node that reads it, printed in the same way, or by output where several nodes read it, and its attribute label names the wire: the one output of Inputs is read by Pullback at 𝑐 𝑉≻ ∘ 𝑔≻ of the decision builder and by Pullback 𝑉≻ ∘ 𝑔≻ of the policy builder, so it is headed output and lists label 𝑉≻(a).
A parameter and the policy a builder is stated at are no wires: they stand in the rows of an operation's card, as the stage holds them, and each parameter stands with its declared set in the attributes of the layer of every builder whose operations read it (§3.3).
The edges that cross the border of a layer are the wires its operators read and write. A wire of a builder's signature that none of its operators reads is therefore no edge of its layer, and the whole signature stands in the attributes of the layer (§3.3).
3.3 The side panel¶
Selecting a primitive operator lists its attributes in the side panel, each on one line and in this order: the kind of the operator, the rules of the Rule section of its card, one attribute to a rule and numbered only where there are several, the lines of its kernel, the method bound within it where one is (§4.2), and the numbers of the lines of the stage file it realizes (A builder §1). A value wider than the panel is cut with an ellipsis, and a control at the end of its row expands it to the whole value. A rule that the card breaks over several lines stands on one line, and the region a rule holds on, which the card sets at the right margin or on a line of its own, follows the rule after two spaces, as one attribute: 𝑐(𝑚_d≻(a)) = 𝑐≻(a) on 𝑚_d≻(Xa) on policy.identification:Pullback of the methodized cons. On cntn_to_dcsn:Aggregation of cons:
| Attribute | What it holds | On cntn_to_dcsn:Aggregation |
|---|---|---|
kind |
the kind of the operator (Operations) | Aggregation |
rule, or rule 1, rule 2, … |
the rules of the card's Rule section |
rule: 𝑉(m_d) = 𝑢(𝑐(m_d)) + 𝑉≻(𝑔≻(m_d, 𝑐(m_d))) |
kernel, or kernel 1, kernel 2, … |
the lines its kernel() prints (A piece §2) |
kernel 1: 𝐺 of cntn_to_dcsn: 𝐺(V≻, m_d, c) = 𝑢(c) + V≻kernel 2: outputs (V); unused m_d; V reads V≻, c |
lines |
the stage file and the numbers of the lines the card's Source section quotes, a run of consecutive lines by its first and its last, house_choice.bl 18–19, 22; the address the operator is born at is the first segment of its id, and the text of the lines is not repeated, since the rules state it |
cons.bl 22 |
An evaluation, whose kernel is the identity, lists under rule only the rows that type its outputs, 𝑉 : Xm → [−∞, ∞) on cntn_to_dcsn:Evaluation, and none of the rules of the operation before it, which that operation lists. The stated derivative of the value, D_{m_d}𝑉(m_d) = 𝑑𝑢(𝑐(m_d)), stands at cntn_to_dcsn:Evaluation with its source line cntn_to_dcsn.marginal and the obligation marginal-reading, beside the method bound there, and adds no edge. An operation that quotes no line of the stage file, such as the evaluation of dcsn_to_arvl, has no lines. The rows of the card's Where section, the local abbreviations its rules write, stand on the layer of the operation's builder, and those of its Conditions are not shown. Where a method is bound within the operator, the panel also lists method, handler, option and setting, the last two numbered in the same way (§4.2).
Selecting a layer lists inputs and outputs, the two sides of its builder's signature as signature() prints them, each on one line. On policy they are 𝑉≻ : Xa → [−∞, ∞) and 𝑐(m_d) : 𝒫({c ∈ (Xm → ℝ₊₊) | c(m_d) ∈ Γ(m_d)}). The layer of a builder, and not of a sub-builder, also lists what the builder's operations share, each on one line and numbered only where there are several. On the layer policy of cons:
| Attribute | What it holds | On policy |
|---|---|---|
where, or where 1, where 2, … |
the rows of the Where section of the builder's card, the local abbreviations the rules of its operations write, each once, such as the law of motion at a branch in applications/housing-frictions/declaration/stages/house_choice/house_choice.bl, 𝑔_keep≻ : ℝ₊₊ × ℝ₊₊ → ℝ₊₊ × ℝ₊₊, 𝑔_keep≻(m_f, m_h) = 𝑔≻(m_f, m_h, keep) |
none |
feasible set, or feasible set 1, … |
on the layer of the policy builder, the definition of each feasible set its policy names, as the stage's definitions hold it | Γ(x : ℝ₊₊) := (0, x] |
parameter, or parameter 1, … |
each parameter the builder's operations read, directly or through a function such as 𝑢, in the order the file declares them, as stage.par prints it: its declared set, and on a calibrated version its value (Parameters and settings §1) |
ρ : [1, inf), unbound; on the calibrated cons, ρ = 6.0 : [1, inf) |
setting, or setting 1, … |
every setting the version binds, as stage.settings prints it, whether or not a method names it (Parameters and settings §2) |
none; on the configured cons, six, from n_a = 800 : ℕ, read at policy by !egm for its grid !Cartesian to m_max = 10.0 : Xm, read at cntn_to_dcsn.evaluate by !Linear for its grid !Cartesian |
The settings are the version's, so every builder's layer of a configured version lists all of them. A sub-builder's layer lists its signature alone. Selecting Inputs or Outputs of a builders graph lists the graph's own signature as signature() prints it, under inputs or outputs, the wires as one object, which on the Inputs of the backward graph of cons is the one wire 𝑉≻ : Xa → [−∞, ∞); their ports give the wires one by one. An initial diagram has neither node and lists its signature on no layer: the fields it takes and gives are the nodes no block writes and no block reads (§3.1), and the signature's line for a field, V≻ : {V≻}, restates the field's label.
Selecting a block of an initial diagram lists kind, which is block; header, the block's header as the file writes it after the id; statement, or statement 1, statement 2, …, each line of the block as the card's Source section quotes it, with its line number; and lines, the file and the numbers of the header's line and the quoted lines. On cntn_to_dcsn of cons the header is (V[>] : [-inf, inf) @ !vlu, c) : !cntn -> (V : [-inf, inf) @ !vlu) : !dcsn, the statements 21 V = 𝑢(c) + V[>] :: [id=value] and 22 D_{m_d}V = 𝑑𝑢(c) :: [id=marginal], and the lines cons.bl 20–22. A block carries no method; the method bound within a line stands on the operator the line forms, in the builders graph.
Selecting a field of an initial diagram lists kind, which is field; perch, the perch the field belongs to, or, for a shock, which belongs to none, edge, the pair of perches of the transition that draws it as the fields table prints it, ∼→≻; role, where the field has one; set, its declared set as the fields table prints it, where a header declares one; and lines, the file and the line of the header that first lists the field, the order in which the fields table lists them (The stage §5). On V≻ of cons the rows are field, cntn, value, [-inf, inf) and cons.bl 20, the line of the header of cntn_to_dcsn; on c, which the header of the forward block dcsn_to_cntn lists at line 16, among the inputs the block is read at, before the header of policy writes it at line 29, lines is cons.bl 16. The ports of a field's node carry its label, perch, role and set, as every port does (§3.2).
3.4 The search box¶
The search box at the top left of the page takes a regular expression and finds every node and layer whose label, or one of whose attributes, matches it; an attribute is read as key=value, and the id of a node counts among its attributes. kind=Aggregation finds the aggregations, and method=!egm every operator and every layer that lists !egm as its method. Expressions separated by spaces must all match.
3.5 A refused graph¶
Where the construction refused a direction, its graph is one node with an orange border, forward:refused or backward:refused, labeled with the direction and the rule the refusal names, with the refusal's whole text in its attribute refusal; the other graph is drawn as usual, and an initial diagram the construction refused is one node in the same way, backward initial diagram:refused. The forward graph of the retiree stage applications/cagetti-denardi-2006/declaration/stages/retiree_death/retiree_death.bl is the one node forward builders graph refused (not-constructed), since the distribution of its shock y_n is written with a family whose set of results is not declared.
4 Perches and methods¶
4.1 The perches¶
The three perch overlays, arrival, decision and continuation, stand in the second file of §2, cons.edge-overlays.json, and the view opens without them. The viewer draws an overlay edge as a straight line from the border of one node to the border of the other, not along the edge of the graph, and neither an overlay nor its edges has a setting that makes it follow that edge; the perch of every wire stands on its ports (§3.2). A reader who wants the overlays opens the panel of edge overlays from the toolbar above the graph and loads the file with its button Upload. Each overlay is drawn in the color the project's site gives its perch, navy for arrival, a dark orange for decision and ultramarine for continuation, while a node it touches is selected, and paints every edge whose wire stands at its perch, with no label. The viewer also outlines the nodes a selected node reads from in green and those it writes to in orange, with the edges between them in the same colors; these colors are the viewer's own, which the two files do not set, and an edge they draw carries no label. Bellman Workbench, the editor that draws the same graph beside the stage file, marks the selected box and the wires that enter or leave it in a bright blue and outlines no other box, and its legend lists the color of each perch while its overlays are on (Bellman Workbench §2).
4.2 The methods¶
A method typed at a primitive operator is shown on the operator's node by one mark: the second line of its label ends with · and the method's word, written with its ! as the methods file writes it. On cons methodized by its methods file, applications/portfolio-choice/declaration/stages/cons/methods.bl, cntn_to_dcsn:Evaluation is labeled Evaluation over 𝑉(m_d) · !Linear, and no other node carries a word: the endogenous grid method is typed at the policy builder, a layer, and not at the Evaluation that closes it, which stays labeled 𝑐(m_d) (§3.3). The ! tells a word apart from the id of a statement, which a symbol may write after the same ·, 𝐺 · InvEuler. No color stands for a method: the method is named by its word, by which the search box finds it, method=!egm (§3.4), and the operation it realizes is stated in Method types. A version within which no method is typed, such as the symbolic cons, shows no mark.
The side panel of such a node lists the components typed at it: method, the word with its keyword arguments; grid, the grid as the methods file writes it; handler, the routine the methods file names (handler); and, on a configured version, setting, each setting the grid and the method name, as the version's settings print it (Parameters and settings §2), numbered where there are several, setting 1, setting 2. On the specified cons, calibrated by applications/portfolio-choice/declaration/calibration/portfolio.yml, methodized as above and configured by applications/portfolio-choice/declaration/settings/cons.yml, cntn_to_dcsn:Evaluation lists, among its attributes, method !Linear, grid !Cartesian(m_d=(m_min, m_max, n_m)), handler cons-port:_make_interp and setting 1 m_min = 0.01 : Xm, read at cntn_to_dcsn.evaluate by !Linear for its grid !Cartesian. A method typed at a builder, and at none of its operators, stands in the attributes of the builder's layer, and no label carries its word: in the backward graph of the methodized cons, the layer policy lists method !egm, grid !Cartesian(a=(a_min, a_max, n_a)) and handler cons-port:egm, and in the forward graph the layer arvl_to_dcsn lists method !deterministic and the layer dcsn_to_cntn handler cons-port:transition_fwd. The builder's layer lists every setting of a configured version (§3.3). The legend of Bellman Workbench lists each method typed in the graph it shows with its place, an operator's id or a layer's name, !egm policy and !Linear cntn_to_dcsn:Evaluation in the backward graph and !deterministic arvl_to_dcsn in the forward graph (Bellman Workbench §2).
5 A trellis¶
explore(trellis) and write_model_explorer(trellis, folder) take the dictionary that elaborate_trellis returns, or a version the trellis verbs bound (The trellis factory §§3 and 4), and write one collection of two graphs, the backward and the forward trellis and no initial diagram, labeled trellis: the files are trellis.graph.json and trellis.edge-overlays.json, which explore(trellis) writes into model-explorer/ in the working directory unless folder= names another. Where the construction refused one direction of a stage occurrence, the trellis's graph of that direction is one node labeled as in §3.5, whose attribute refusal opens with the occurrence's address. explore(trellis) opens the backward graph with its periods open and located on periods[1], the first period after the terminal one: the page selects that period's layer, lists its attributes, and fits the window to it, and the other periods stand beside it, a scroll away. A trellis of one period is fitted to the window whole.
Each period is a layer periods[h], white with a navy border, h being its index in the dictionary and periods[0] the terminal period; the position stands in the layer's name and in no attribute. The viewer receives no terminal age data and displays no value of an age. An age that the stages send backward is drawn as a field of the backward graph, like every other field. Each stage occurrence is a layer inside its period, named by its key, periods[0]/cons, whose attribute stage shows the stage's name and bindings; it holds that occurrence's builders exactly as the view of the stage does. Every node id and port id is the id in the stage's own view, prefixed by its occurrence, periods[0]/cons/cntn_to_dcsn:Aggregation, so that two occurrences of one stage are told apart. The viewer lays out the periods side by side and the stages of a period next to one another, each graph in the direction its wires pass, and the builders of an occurrence from top to bottom. In the forward graph economic time runs from left to right, with the terminal period at the right and the stages of a period in their forward order, as in the drawing of diagram_trellis; the backward graph, laid out in the direction its value functions pass, from the terminal period back, stands the other way round.
A join, which connects a continuation field of one stage occurrence to an arrival field of another (The Bellman factory §7), is drawn at the grain of the wires, from the node that writes a wire of one occurrence to each node that reads the joined wire of the other: forward, from the continuation measure of one occurrence to the arrival measure of the next; backward, from the value-type fields the later occurrence sends back to those the earlier occurrence takes in. The reading port holds the attribute join, the text the drawing writes on the wire: a for a field joined by its name, m_next → m where a connector renames it, and inter_connectors[0] a → k for a join between periods; in the backward graph it also holds paired by, the rule that paired the wire with the one that supplies it, the reason given by the connection selection, such as equal name. A joined wire that no operator of its occurrence reads is a port of a node Inputs inside the occurrence's layer, so that its join is drawn. The policy of each occurrence, which no join reads, ends at a node Outputs inside the occurrence's layer, periods[0]/cons/GraphOutputs, so that no edge of a policy crosses the periods.
A trellis has no Inputs and no Outputs of its own. A wire that no join supplies enters the graph at a boundary node, and a wire that no join reads leaves it at one: a node at the graph's root, outside every layer, that holds the wire's one port and is joined by the wire's edge to the operator that reads or writes it. Its attribute kind names its role, start where the wire enters and end where it leaves, and its label, which its attribute label repeats, is a word for that role followed by the wire's own label: in the forward graph, starting data where the arrival measure of the first occurrence in time enters and terminal where the measure of the last one leaves; in the backward graph, terminal condition where the terminal value enters and result where the value of the first stage in time leaves. Its id is its kind followed by the id of the wire's port. In the trellis applications/cons-port/declaration/trellis.port-cons.yml, six periods of three stages, the forward graph begins at starting data μ≺, the node start:periods[5]/port/port:measure:arvl, and ends at terminal μ≻; the backward graph takes the continuation value of periods[0]/disc, the last stage of the terminal period, at terminal condition 𝑉≻(a), and gives the arrival value of periods[5]/port, the first stage in time, at result 𝑉≺(k).
Each edge of a join carries, under its attribute route, the record of the route that establishes it: the connection from one branch of the source occurrence into the destination occurrence, as connection_report answers it (The trellis factory §9). The record holds branch, the label of the source's branch, or null for a stage without branches; source and destination, the addresses of the two occurrences, periods[5]/port; source_fields and destination_fields, the continuation fields of the source and the arrival fields of the destination, in the route's order; pairs, one entry for each field joined, in the route's order, with source_field, destination_field, origin, authored for a pair a connector writes and inferred for one joined by equal names, and address, the entry that writes an authored pair, periods[5].connectors[0], or the period of an inferred one; status, certified or uncertified; and law, the joint measure the source's branch writes, port:measure:cntn. Every value is read from the route and none is computed by the view, so that the edge and the report agree; an edge that no route establishes, inside an occurrence or at a boundary node, has no attributes. Unlike the attributes of a node, those of an edge are not shown by the viewer's page, which reads no attribute of an edge; Bellman Workbench reads them.
The backward graph uses the value-type pairs of the connection selection. This includes authored pairs, equal names after removing perch marks, and a single remaining pair where the earlier field is not kept. Constants can be paired with zero state coordinates. An unresolved required pair leaves a diagnostic in the report and can refuse the backward graph. A reader loads the trellises of the pension, durables and housing models through their registries and recipes, load_recipe("applications/pension-retirement/declaration", "spec.yml"), load_recipe("applications/durables/declaration", "spec.yml") and load_recipe("applications/housing-frictions/declaration", "spec.yml") (Recipe functions §2), and gives explore the dictionary that elaborate_trellis returns for each. load_trellis refuses their files trellis.yml under the rule trellis-file-shape, since the periods of those files name each stage by its key alone and the recipe supplies its source and mappings (The trellis factory §1).
Building the view of a trellis takes a few seconds for the eighteen stage occurrences of trellis.port-cons.yml and tens of seconds for a hundred occurrences, since the graphs of each occurrence are built when first asked for.
A view of part of a trellis is asked for by the periods and the stage keys it holds, to_model_explorer(trellis, periods=range(0, 2), stages=["cons"]), the periods selected as diagram_trellis selects them: the view holds the occurrences of those periods whose keys are given, every period or every key where one of the two is not given, and the joins between them as above. A join that leaves the occurrences held is no edge between them: the wire it carries enters or leaves the graph at a boundary node of kind outside, one for each occurrence outside the view that such joins reach, labeled with that occurrence's address, which its attribute target repeats, periods[1]/disc, and named by its kind, the id of the wire's port and that address, outside:periods[1]/cons/cons:measure:cntn:periods[1]/disc; the wire's port names the join in join and those occurrences in outside, so that nothing is lost without a mark. An index the trellis does not hold, a key no period selected holds and a selection of no occurrence are refused under trellis-file-shape, each in one sentence.
unpaired_joins(trellis) answers the rows join 1, join 2, … of the refusing backward node as records, one UnpairedJoin for each join that leaves a wire unpaired, in the order of the rows: its label, the addresses of the two occurrences, the address in the trellis of the connector that makes it, inter_connectors[0] or periods[0].connectors[0], empty for a join by equal names, and each wire it leaves unpaired as an UnpairedWire, with its occurrence, its name as the stage file writes it, the stage file and the line of the header that first lists it. It takes periods and stages as to_model_explorer does, and answers no join where the graph is drawn.
6 The viewer's settings¶
The viewer's default text renderer cannot draw the mathematical letters of the labels on the canvas, and draws other characters in their place. The setting "Use SVG text renderer", among the advanced settings behind the gear icon at the top right of the page, draws every label exactly. The side panel draws every attribute exactly with either renderer. The browser keeps the setting in its local storage for the page's host and port, which is why every view is served from one port, 8080 unless port= names another: the setting is turned on once for that port, and a view served from another port needs it turned on again.
The view is an interactive reading of the stage and changes nothing in it. The drawing that diagram() answers (A builder §1) remains the recorded figure of a page and of a lesson, since a view opens only while a Python process serves it.