{'fraction_non_alphanumeric': 0.03632488752071987, 'fraction_numerical': 0.004735969689793985, 'mean_word_length': 4.414358974358974, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Modeling Hierarchical System with Operads

This paper applies operads and functorial semantics to address the problem of failure diagnosis in complex systems. We start with a concrete example, developing a hierarchical interaction model for the Length Scale Interferometer, a high-precision measurement system operated by the US National Institute of Standards and Technology. The model is expressed in terms of combinatorial/diagrammatic structures called port-graphs, and we explain how to extract an operad LSI from a collection of these diagrams. Next we show how functors to the operad of probabilities organize and constrain the relative probabilities of component failure in the system. Finally, we show how to extend the analysis from general component failure to specific failure modes.


Introduction
Hierarchical systems are ubiquitous in nature, in engineering and in commerce. We draw trees to represent anatomic features, component breakdowns and command structures. Hierarchies use abstraction barriers and separation of concerns to analyze and simplify complex problems into manageable parts.
However, to represent a system as a tree involves abstracting away the interactions between its branches. An alternative viewpoint, exemplified by models called port-graphs, emphasizes the leaves of the tree (components) and the way that they are wired together to form a larger system. This additional information is critical for system analysis, but such diagrams quickly become unwieldy as the number of components grows.
Operads provide a nice mathematical formalism for interpolating between these two viewpoints. Our goal in this paper is to demonstrate, in concrete terms, the use of operads to organize both qualitative and quantitative descriptions of hierarchical systems. To that end, we begin by modeling a specific real-world system, the Length Scale Interferometer (LSI), a device for precise length calibration operated by the US National Institute for Standards and Technology.
We begin with a brief sketch of the LSI, its purpose and its design, followed by an informal review of operads. Next, we construct a specific operad LSI based on the architecture of the LSI system and expressed in terms of combinatorial/diagrammatic structures called port-graphs. This forms the basis for a functorial analysis of failure diagnosis. First, we can consider the relative probabilities of component and sub-component failure as a functor LSI → Prob. Finally, we show how to integrate component level probabilities with more specific information about specific failure modes.

The Length Scale Interferometer
The Length Scale Interferometer (LSI) [1] is a precision length-measurement system operated by the US National Institute for Standards and Technology (NIST). Customers from around the world send length scales, marked plates or rods ranging in size from a millimeter to a meter, to be calibrated at NIST's Gaithersburg, MD campus. Using laser interferometry, the device accurately measures lengths to better than one part in one million (0.7 µm error across a one meter length), and can resolve markings on a scale down to 0.1 µm.
More formally, a nominal length scale is defined by two distances: the total span D and the spacing d, where N = D d ∈ N; for example, a typical meter stick with millimeter hatch marks would have D = 1 m and d = 1 mm. The scale has N + 1 hatch marks located a 0, d, 2d, . . . Nd = D. For a real scale we can set our frame of reference Y by the first mark on the scale, but each of the others will exhibit an error ε i , and the purpose of the LSI system is to identify these errors.
The basic idea is simple enough. The scale is installed on a movable chassis, which also contains one mirror of an interferometer. The length of the laser's path changes as the scale and chassis move, allowing us to infer the scale's position from the fringe count of the interferometer.
A calibration starts from the initial mark at y 0 = 0 and records the current fringe count f 0 on the interferometer's readout. The machine scans to the next hatch mark y 1 , identified by an optical system, and locks the position of the chassis. The new fringe reading f 1 , along with the laser's wavelength λ 0 and the index of refraction n, determines the associated error We do the same for each of the rest of the marks, noting that all distances and errors are calculated relative to y 0 (rather than y i−1 ).
In practice, there are a number of complications, of which the most significant involve unavoidable fluctuations in the environment. Here we are concerned with two main effects. First, the index of refraction, which we use to calculate lengths and errors, depends on temperature. 1 Second, thermal expansion means that the relative positioning of system elements changes over time.
For example, the relative separation between (the first hatch mark of) the scale and the chassis' mirror will vary due to expansion of the metal that connects them. Similarly, the scale itself expands, so that the positions of the hatch marks and their errors will vary. Consequently, we should reformulate the goal of the LSI as measuring length scales at a standard temperature of 20 • C. This variation has two practical implications for the LSI system. First, we must apply temperaturedependent corrections to the gross measurements of the system (fringe counts). This is necessary both to calculate the true lengths that were measured and to convert from these to the desired (temperaturecorrected) values. Second, in order to minimize correction error, the LSI must maintain environmental values as close to the target as possible; to obtain the 0.7 µm accuracy mentioned above, the system must operate within .02 • C of the target value.

Operads
A (colored) operad is a mathematical structure for representing hierarchical (tree-structured) composition and decomposition. The fundamental element of an operad is an operation f ; every operation has an arity m, a tuple of input objects Y 1 , . . . ,Y m and a single output object X , which we usually indicate by writing α : Y 1 , . . . ,Y m → X (or more compactly, Y i → X ). When the input elements are not relevant, we may simply write f : X Given additional operations g i : Y i , operadic composition substitutes these for the "dummy variables" Y i to obtain a new operation f (g 1 , . . . , g m ) (or f g i ). If each g i has m i inputs, then the new composite has ∑ i m i . Operadic associativity guarantees a well-defined composite for more deeply nested terms. When it is unambiguous we may also write f (g) for composition along a single branch, rather than f (id, . . . , g, . . . , id). See [2] for a careful exposition.
We will be interested in a typed variant of Spivak's operad of wiring diagrams [3]. We begin with a set of interfaces I , which represent all the channels of interaction that occur within our system. These include both physical interactions (heat flow)) and digital signals (temp measurements). Formally, we specify I at the outset, although in practice it can be inferred from usage in system diagrams.
Given I , a boundary is a set of ports P together with a map (often left implicit) P → I . We draw an interface as a box with |P|-many terminals, each labeled by a type (distinguished, if necessary, by subscripts). For example, the bath used in the LSI's temperature regulation system has a boundary Bath This indicates that the bath has three main interactions: heat flow to the length measurement enclosure, chilled water provided from an outside system and a data stream that modifies the set point of an internal heating controller. For now our labels are just place-holders, but they will be refined as we elaborate the model.
In the PortGraph operad, an operation α : Q i → P is a system architecture, modeled as a port-graph, in which Q i are sub-component boundaries and P is an external system boundary. The ports in P and Q i can be connected via wires, which are also typed, and more properly described as "hyper-wires" given that a single wire can connect more than two ports.
For example the LSI's temperature control system, shown in Figure 1, has three subsystems: one controls the ambient lab temperature (±0.2 • C), another measures the internal temperature of the measurement enclosure (±.005 • C) and a third manages the chilled water bath used to control the system's temperature.
Physically, the bath and the lab environment both impact the enclosure through heat flow and this, in turn, affects the length measurement subsystem via refraction of the laser. Another physical input to the system, a chilled water source, is a shared resource controlled outside of the lab.
There are also digital flows involved in the system. Two streams of temperature data are produced by the lab and the enclosure. There is also a control interaction, with a variable set point for a heating element in the bath. Diagrammatically, it can be useful to distinguish between physical and informational flows; for example, the latter have only indirect effects on the temperature of the system, in contrast to the physical inputs. Formally, the use of different notations for different interaction types can be justified by "typing the types" via a function I → {physical, digital}.
We can succinctly represent a port-graph architecture α as a zig-zag of functions, two of which commute over types: Here C = comp(α) ∼ = {1, . . . , n} is the set of (black-box) components in the architecture, Q = ∏ i Q i is the set of internal ports, W is the set of wires and P is the set of external ports. Both ports and wires are typed, and the resulting triangles should commute.
Operadic composition acts by substituting one architecture into another. For example, Figure 2 shows the result of substituting a lower-level architecture composed of a mixer, a resevoir and a heater for the Bath component from Figure 1.
In the general case we may substitute for all Q i simultaneously, so suppose that we have a decomposition (suppressing types) Clearly the external ports P are unchanged by substitution inside Q i . The set of internal boundaries is given by D = ∏ i D i ; similarly the internal ports of the architecture will be R = ∏ i R i . Finally, we can compute the wire set for the aggregate by identifying an outer wire w with an inner wire v i whenever they share an intermediate port Q i . Formally, this corresponds to a pushout, and typing on the new wires exists by virtue of the associated mapping property: Equations 1 and 2 (along with the set I ) define an operad PortGraph.
One nice feature of operads is that, although they allow us to represent hierarchical information, they do not constrain us to work within a single hierarchy. In particular, different perspectives often suggest different decompositions for a system, and we can make sense of these distinctions using equations in the operad.
An example is shown in Figure 3. On one hand we can decompose the LSI system functionally (blue boundaries), separating the elements involved in length measurement from those used for temperature control. The second shows a more generic, control-theoretic perspective (red boundaries), separating out components that produce observations (sensors) from those which modify the state of the system (actuators). We could also consider a "geographic" decomposition based on the physical access to the components (e.g., inside/outside the system enclosure). An equation in the PortGraph operad indicates that two incompatible hierarchies (e.g., function vs. control) have a common refinement at a lower level of abstraction.
On first encounter, it can be easy to mix up port graph diagrams, which represent specific architectures, with the PortGraph operad, which represents all possible architectures. A specific system, as represented by a collection of diagrams, can be compiled into a "sub-operad" (faithful functor) LSI ⊆ PortGraph involving only the boundaries and architectures that appear in our diagrams. 2 A complete description of the LSI operad, compiled from Figures 1, 2 and 3, is given in the Appendix, Tables 3  & 4.

Component failure
In the last section we constructed an operad LSI whose operations are hierarchically organized architectures of the Length Scale Interferometer. Once we have laid out the architecture of the system, we can use it to structure system analyses.
The general principle of functorial semantics is that a model can be regarded as a mapping (called a functor) from architectural (syntactic) elements to computational (semantic) ones, but that this mapping must be assigned in a way that respects the compositional structure of the syntax. Probability provides a good example. A very simple model of component failure might conclude, based on historical data, that a failure in the LSI will be located in the temperature regulation subsystem 60% of the time, and in the length measurement subsystem the remaining 40% of the time. The probability distribution p = (ls → 40%,ts → 60%) is itself an operation in an operad, and we can think of the failure model as a mapping from the functional architecture ϕ to the distribution p.
Suppose, moreover, that we also know the probabilities of failures within the temperature regulation system, which can involve the bath (ba → 80%), the lab temperature system (lb → 10%) or enclosure (box) temperature measurement system (bx → 10%). Relative probabilities compose by multiplication (conditioning), so that given a fault somewhere in the LSI, there is a 80% × 60% = 48% chance that it involves the bath. This is an instance of functoriality: composite architectures map to composite distributions.
More precisely, there is an operad of probabilities called Prob. Prob is a "plain" operad, so that each operation has a fixed number of inputs (arity) m (in contrast to PortGraph, where each operation π has a "shape" Q i → P). An operation Prob is just a finite probability distribution p = i → p i i<m , and its arity is the size of the index set m. The operadic (tree-structured) composition of p with m-many additional distributions q i = j → q i j j<m i is defined by where the index set is the collection of pairs (i < m, j < m i ). This allows us to think of the simple failure model described above as a functor P : LSI → Prob. The data associated with a specific instance is shown in Table 1. It sends each architecture Q 1 , . . . , Q m → P to a probability distribution on m elements, which should be interpreted as the relative probability of a failure in Q i , given a failure in P.
In order to define a functor, these probability assignments should satisfy the LSI's composition equation ( Figure 3). This defines some global constraints on how probability can be apportioned between different systems. For example, from above we know that there 80% × 60% = 48% chance that a given failure occurs in the Bath. If we also know that problems with actuators are responsible for 72% of all faults in the LSI (κ : ac → 72%), then we can infer that the bath is twice as likely to malfunction as the chassis (third and fourth equations of Table 2). All in all, the LSI's coherence equation ϕ(λ , τ) = κ(σ , α) generates six probability equations, corresponding to the six components involved in the composed architecture.
Even in the absence of data we can represent these equations symbolically-the top line corresponds to ϕ(ls) · λ (in) = κ(sn) · σ (in)-and in this form we can view operadic coherence equations as data integrity constraints or rules of inference.

Requirements and behavior
Though the operadic structure of the LSI model is useful for organizing failure probabilities, our analysis so far is deficient in that it considers only the components that fail, and not what goes wrong with them. In this section we consider more specific failure modes for the LSI, and their analysis using the classical method of fault trees.
Failure modes are best understood in the context of requirements. For example, the key functional requirement of the TempSys subsystem is that the laser's temperature should stay within 0.02 degrees of In a similar fashion, we can associate a set of failure modes Err(P) with each boundary P ∈ LSI. Typically these should reference features of the associated boundary (i.e., laser is an element of the boundary TempSys).
If T laser is low, this may happen for a number of reasons. Either the Bath or the ambient Lab might be too cold, or the insulation of the Box might be leaking. However, we can say with confidence that a high Bath temperature is not the cause. For each failure mode at the lower level we ask whether or not it can lead to a high temp on laser. Repeating this procedure for each high-level failure, the "can cause" relation defines a functor M : LSI → Rel + .
Here Rel + is an operad of relations, in which the objects are sets, and an arrow Y i → X is a relation or, equivalently, a family of relations R i ⊆ X i ×Y . With the usual composition of relations, functoriality asserts the transitivity of causation: if a malfunctioning heater can cause a cold bath, and a cold bath can cause a low laser temp, then a malfunctioning heater can cause a low laser temp.

Synthesizing semantics
Intuitively, there should be some relationship between the failure probabilities from section 4 and the failure modes of the last section. At a minimum, if some component Y i does not cause any errors in X , then the associated probability should be zero. In this section we formalize this relationship functorially, as a joint lifting of P and M: LSI Given sets X and Y , a (stochastic) kernel p : X Y is an X -indexed set of probability distributions p x : Y → [0, 1]. We think of p as a stochastic mapping, which we emphasize by writing p x (y) = p(x → y). There is a category Stoch in which the objects are sets and two kernels p : X Y and q : Y Z compose by marginalization: Using essentially the same technique we can construct an operad Stoch + in which an arrow p : Y i → X is a kernel X ∏ i Y i . Every kernel defines a relation-its support {(x, y) | p(x → y) > 0}-providing a functor supp : Stoch + → Rel + . However, Stoch + is not good enough to provide a joint lifting, as it does not provide a functor to Prob. In Bayesian terms, a kernel represents a conditional probability, and to generate an absolute probability we need to combine this with a prior.
A single distribution over X can be represented as a kernel r : 1 X , also called a point in Stoch. There is a category Pt(Stoch) in which the objects are pairs X , r and an arrow Y, s → X , r is a kernel p : Y X forming a commutative triangle 1 s ? ? ? ?
Again, we can use coproducts to define an associated operad Pt(Stoch) + . As above, an arrow Y i , s i → X , r is a kernel p : X ∏ i Y i , yielding a forgetful functor forget : Pt(Stoch) + → Stoch + . However, the commutativity condition (6) must be tweaked to accommodate operations with higher arity: The lower path r.p weights the kernel p by the prior r. The upper path marginalizes r.p to obtain a distribution on the indices i ∈ n, and uses this to weight the prior distributions over Y i . Moreover, the top row in (7) defines a functor aggr : Pt(Stoch) + → Prob sending a kernel p : Y i , s i → X , r to the aggregate distribution |p| shown below: 3 This realizes our goal for the section. A synthesis of the probabilistic models from section 4 and the possibilistic failure modes of section 5 can be modeled as a joint lifting S : LSI → Pt(Stoch) + : 3 The following diagram shows that such kernels are closed under composition:

Conclusion
We close by noting, briefly, some limitations of the present paper. Though our model is based on a realworld system, it is much too coarse to use in practice. A true predictive model would require a much more detailed decomposition of the system. Similarly, the failure model presented in Section 4 is not based on real data, but rather selected to illustrate certain points. However, we intend to refine the model over time and, eventually, hope to produce a reference implementation for categorical systems modeling. Second, the models presented here are purely static, but it would be preferable to incorporate sensor observations into our failure predictions. Here we should be able to leverage existing work on the interpretation of port-graphs as behavioral constraints on dynamical systems. Our next goal is to develop a dynamical model of system and component behaviors including both functioning and malfunctioning components. By substituting malfunctioning component models into the larger dynamical system, we can estimate the likely sensor readings for each failure mode and use these to assess the relativized failure probabilities discussed in Section 5.
Disclaimer: Commercial products are identified in this article to adequately specify the material. This does not imply recommendation or endorsement by the National Institute of Standards and Technology, nor does it imply the materials identified are necessarily the best available for the purpose.   Figure 3.