Abstract
Modern computational models tend to become more and more complex, especially in fields like computational biology, physical modeling, social simulation, and others. With the increasing complexity of simulations, modern computational architectures demand efficient parallel execution strategies. This paper proposes a novel approach leveraging the reactive stream paradigm as a general-purpose synchronization protocol for parallel simulation. We introduce a method to construct simulation graphs from predefined transition functions, ensuring modularity and reusability. Additionally, we outline strategies for graph optimization and interactive simulation through push and pull patterns. The resulting computational graph, implemented using reactive streams, offers a scalable framework for parallel computation. Through theoretical analysis and practical implementation, we demonstrate the feasibility of this approach, highlighting its advantages over traditional parallel simulation methods. Finally, we discuss future challenges, including automatic graph construction, fault tolerance, and optimization strategies, as key areas for further research.
1. Introduction
As simulations become increasingly complex, more and more computational resources are required to execute them. Computing power continues to grow per Moore’s law, but this growth shifts to the horizontal plane, i.e., it happens due to an increase in the number of parallel processors and their cores. Thus, there is a need to develop parallel simulation algorithms capable of utilizing the computing resources of multiple CPUs.
Today, several approaches exist for parallelizing simulations. In particular, we can consider the Time Warp algorithm [1] described in detail in [2]. This algorithm has been studied for many years and has several implementations in the code [3,4,5]. However, Time Warp uses its own synchronization protocol, which is complex and low level [6]. The RxHLA software framework (based on the reactive adaptation of IEEE 1516 standard) [7] is similar to Time Warp in terms of complexity and low levelness. Another approach, based on the CQRS + ES architecture, is described in [8]. However, the authors of that work concentrate more on the practical aspects of implementation without providing much theoretical background. The HPC simulation platform [9] is also a more practical implementation of parallel simulation; it is based on actors and the AKKA library and constitutes a more conservative approach than reactive streams.
The key concept of this paper is to use a general-purpose synchronization protocol to parallelize simulations, namely, the reactive-streams protocol [10,11,12], particularly the version implemented in the AKKA library [13,14,15,16]. Thus, on the one hand, we have a classical mathematical model. On the other hand, we have a general-purpose synchronization protocol. The goal of this work is to unite them.
The rest of this manuscript is organized as follows:
- Section 2 explains the basic modeling concepts and entities that we will use in this paper.
- Section 3 extends basic modeling to be represented in the form of a transition graph and shows how a simulation can be performed on this graph.
- Section 4 shows how the transition graph can be implemented with reactive streams and how simulations can be executed.
2. Substates
Before we start developing a parallel simulation algorithm with reactive streams, we define substate concepts and some objects for later use in this paper. Before reading this section, we suggest you check Supplementary S1, which describes the notation, and Supplementary S2, which gives a common basic definition used in this article. Also, in Section 5 and Supplementary S6, you can find real word examples that illustrate the described approach.
2.1. Substates as a Decomposition of the State
Each state can be represented as a set of substates, each of which contains only a part of the values of . There must be a way to determine which of the substates belongs to a certain . One option to achieve this is to use a unique key to mark all substates belonging to a certain .
Definition 1.
Let us define a substate , where is part or all of the set of values, , is some key unique to the state ;, and is the index of the substate with the same key, .
One or more values can be used as key . In this case, it makes no sense to include them in any of the substates since they will be presented in the key.
For some state , we have the set of substates with the same key . We will denote this set by a bold . With such representation of the state , it is necessary to ensure that all marked by the same are not contradictory. The pair of with the same key can be contradictory if one or more values differ under the same index.
Definition 2.
Let us define the set of substates
where for all the consistency criterion
is true.
In this paper, we will talk about arbitrary sets of substates , whose only requirement is to meet the consistency criterion.
Definition 3.
Let us define an arbitrary set of substates
as the union of the sets with different .
Notice that these definitions do not require the presence in the set (and consequently, in ) of a sufficient number of substates to cover all values .
Let us also note that, by definition, the set can contain more than one substate with the same key . However, on an arbitrary set that contains duplicate keys , we can construct a set that does not contain them. For this, we need to combine all substates with the same key into one substate:
where is a set with duplicate keys and is a set with unique . Thus, we can say that an arbitrary set of substates can be considered as a key–value structure or as the surjective function
As follows from the definition, the set can only be constructed from a set of states in which a unique key can be associated with each state . Otherwise, this will lead to the appearance of substates in conflict.
The inverse transformation, i.e., the construction of from an arbitrary
is possible only if contains enough substates to construct each state completely.
The set of substates can be equivalent to the state space if this state-space contains enough substates to construct each state . We will denote such a set by .
2.2. Representation of the Dependence of Y on X as a Set of Substates:
The dependence of the variables upon can be represented as a set of states . This representation is an alternative to a set of functions . In this case, it is convenient to choose the values as the key and the subset of the values as the values of (including ).
Definition 4.
Let us define the substate , where the key is ,, the value,, and the index is such that
also, and
Since the values of the parameters are constant for any possible values of and , they are also constant for any possible substates composed of the values of and . Thus, the definition of does not include values . Being joined into a set, the substates will have the same parameters , but may have different values of the key .
Definition 5.
Let us define the dependence
which represents the dependence of the variables upon for given parameters that are the same for all substates included in the set . At the same time, substates should not be contradictory:
The set with all substates having the same key will be denoted .
Let us note that we do not impose a completeness restriction upon the set —i.e., may not contain all of the keys or may even be empty: . may also not contain all and/or it may not contain enough to build one or more complete .
The representation is equivalent to the representation if and only if, for each at a given , the representations are equal:
For each key , there exists a set of substates that cover all possible values . We will denote this set by . This set may not satisfy the consistency criterion (Formula (1)) and will have cardinality
If we join the sets for all possible keys , we obtain the set of all possible substates. We will denote it by
The cardinality of this set when will be
Moreover, since, from the set only, one set of values is used (note, the cardinalities will be equal in case ).
In practice, we will more often see sparse , where it is impossible to completely construct for every . The use of sparse will reduce the modeling accuracy. In general, this is not a problem from an engineering standpoint since increasing or decreasing the cardinality allows us to choose an acceptable accuracy level for solving a specific simulation problem.
2.3. Reflection as a Record of Changes in the Values of Variables
We can reflect the behavior of a modeled object by measuring its properties and recording the corresponding values of the variables , and . By abstracting from a specific implementation, we will call such a record a reflection of the modeled object.
Definition 6.
Let us define the reflection as an arbitrary representation of the dependence of the dependent variables upon the independent variables and the values of the parameters . Moreover, this dependence is constructed by studying and measuring the modeled object’s properties.
We can graphically represent the building of the reflection by adding the points
into the state space at the coordinates , where , , and . The added points will form a geometric figure that reflects the behavior of the modeled object.
A reflection can be represented as a set of functions
or as a set of states
In the first case, a set of functions can be constructed by recording the obtained or measured values of the variables , and [17]. In the second case, from the values of obtained or measured with respect to and , the substate can be directly built and added to the set of substates .
In this case, writing down the values of the stopwatch (which reflects the variable ) and the level gauge (which reflects ), we obtain the function , which reflects the dependence of on . In practice, this function will be defined only on a certain interval or several intervals of the time , during which the measurement was performed.
2.4. Model as an Imitation of Changes in the Variables V
In one of several ways, we can define the dependencies of the variables on and without directly measuring the properties of the modeled object [18,19,20]. We will call the dependence defined in this way the model of the modeled object.
Definition 7.
The model of the modeled object is an arbitrary representation or implementation of the dependence of the dependent variables upon the independent variables and the values of the parameters . Moreover, this dependence is constructed without the direct participation of the modeled object.
We can graphically represent the model as a geometrical figure in the state space consisting of the points
that define the relationship between the variables and and the parameters , where , and .
The model can be implemented as a set of possibly partial functions
or as a set of states
In the first case, the set of functions can be determined analytically or in another way. In the second case, many substates must be pre-built in one way or another.
We can define the model such that it completely coincides with certain reflection ; however, it is much more reasonable and useful to construct to predict changes in the modeled object.
From a practical point of view, we are interested in how accurately the constructed model corresponds to the modeled object. One way to determine compliance is to compare the model and reflection (i.e., to calculate the magnitude of their inconsistency in one way or another). Let us denote the inconsistency value by .
For example, for the case in which all variables have domain , we can define as the integral sum of the difference of the values and for each :
where .
2.5. Simulation of the Model as a Calculation of a Subset of from the Subset and the Parameters
The simulation task can be reduced to obtaining or calculating the subset of the unknown values of the dependent variables from the subset of the known values of the independent variables and the values of the parameters using a certain model .
Definition 8.
Let us define the simulation as the operator
where is a possibly ordered set of unique known values of independent variables, is the desired set of possibly not unique values of the dependent variables, and is a certain model used to obtain the desired for a given .
For the case where the model is implemented as a set of functions (Formula (3)), the simulation
is simply a calculation of the result for each argument :
where
which is the operation for calculating for a given . For a model implemented as a set of substates (Formula (4)), the simulation is a matter of finding all substates for each key and then building the values of from the found substates
where
is the operation for selecting a subset of substates with the same key .
A simulation can be interactive, i.e., it can react with external events and produce the results to the outside right during the calculation. In the simplest case, an interactive simulation can be represented as a series of simulations
of the set of models
for the corresponding sets of subsets of values of independent variables sequentially received during the interaction and the sets of dependent sequentially returned as simulation results.
3. Graph Modeling
We show how the model can be represented as a transition graph and how a simulation can be performed for this representation. We define and prove the rules for constructing a consistent transition graph. Before reading this section, we recommend to check Supplementary S3, which describes transition function concepts. In Section 5 and Supplementary S7, we present a simple example of the construction and simulation of a transition graph.
3.1. The Transition Graph and the Simulation Graph
We can join the function and a set of functions represented as graphs by combining the result nodes
and the argument nodes
with intermediate-variable nodes
(see Figure 1).
Figure 1.
Joining of function
We continue in the same way to sequentially join the functions included in the same set (possibly using the same function more than once); we obtain some DAG (see Figure 2). We call such DAG a transition graph. Also, as an option, we can combine two or more root variables that do not have incoming edges, thereby reducing the total number of nodes.
Figure 2.
Example of the transition DAG built from functions
Definition 9.
We define the transition graph as a DAG constructed on the set of transition functions by sequentially joining arbitrary subsets of functions
and by combining the result node
and the argument nodes
such that
into intermediate variable nodes
Additionally, the root nodes
and their domains
may also be combined.
We note that this definition imposes no restrictions on the graph structure except for its acyclicity (the result of the next joined cannot be connected with the argument of any already joined ) and continuity (all nodes of the graph are connected by at least one edge).
When we join the transition functions , we also join the transitions from the equivalent set , forming a set of more complex DAGs with the same structure as the graph , but which consist of the substates and transitions (see Figure 3). We call such DAGs simulation graphs.
Figure 3.
Example of the simulation graph that can be obtained from the transition graph in Figure 2.
Definition 10.
A simulation graph is defined as the DAG obtained by constructing a transition graph ; it has the same structure as . The graph consists of constructions of the form
which results from joining the transitions
and
belonging to the set of joined functions
such that
We note that all will have a structure exactly matching . According to the definition of , during the construction of , incomplete graphs of with structures not coinciding with that of will be discarded. Thus, the substates included in the discarded graphs will also be removed from the domains of the variables included in the constructed .
Let us denote some arbitrary set of graphs by . According to the definitions of the graphs and , each of the substates from the domains of the variable nodes will belong to one of the simulation graphs . All terms that do not belong to any will be discarded during the construction of , along with the incomplete .
Thus, we can represent the graph as an equivalent set of graphs . We will denote such a set as ; this set will include all from all domains :
where is the set of domains of the variable nodes from the graph and is the set of all belonging to , which is consistent:
Moreover, all simulation graphs will share the same set of parameters split into parts .
Let us index each node from the set with the depth index
where , is the set of all possible paths from any root node (i.e., the node that has no incoming edges) to the indexed node and is the length of the path (the number of edges in the path). Let us also index all transition functions with the same index same as the index of the result node
Thus, each root node of will have and each leaf node (i.e., such that it has no outgoing edges) will have , where is the minimum number of edges to the nearest root node .
3.2. Construction of a Consistent Transition Graph
From a practical viewpoint, we want to be able to construct transitions from a set of predefined transition functions —in other words, to build models from a set of ready-made functional blocks, similar to the Simulink software (Version R2024b). It is necessary to guarantee the consistency of at the local level, i.e., at the level of individual functions , to implement this approach successfully.
We can represent some simulation graph as the set of directional paths (dipaths) covering all substates and transitions .
Definition 11.
Let us define a dipath
in the simulation graph , where , , is the index of the node, which is in the dipath, such that corresponds to some root node , and corresponds to some leaf node in the graph , , , , with .
We denote some arbitrary set of paths by , which is not necessarily related to the same graph .
The set of paths can be equivalent to the graph if the paths in this set contain all substates and transitions :
In order to guarantee the consistency condition
for the graph (i.e., to guarantee that each of the simulation graphs described by will not contain any inconsistent substates), the graph must meet the following two restrictions:
- For each graph , each substate (i.e., located on one of all possible paths ) must have a unique key regarding the .
- For each graph , the values of some variable should only belong to the set of substates such that there exists in at least one path , including all of these substates.
At the local level (i.e., without studying the entire graph ), the above restrictions can be met by applying the following construction principles (Supplementary S4):
- I.
- The set of keys must be linearly ordered.
- II.
- Each transition function(where ) for each transition(where ) in some graph must generate the resulting substate such that its key will always satisfy the conditionsorwhere
- III.
- For each variable , its values must belong to no more than one root node :where(i.e., the set of all values in all substates form the domain of the variable ).
- IV.
- If, for some node and some variable the condition is true, then either the node must be a root, or there must be a transition functionwith one or more arguments for which the condition is true and in the graph there exists a chainthat includes all . Moreover, for the last argument in the chain, there should not be another functionfor which the condition is true.
In practice, principle (I) can be easily implemented since linearly ordered sets are common. For example, time, speed, etc., can be represented using variables with ℝ. Next, if the domains of all independent variables are in linear order, then the set of keys will also be in linear order.
Principle (II) says that the key–value constantly increases or decreases as the simulation graph is calculated. This approach can be applied, for example, to physical models, where independent variables are usually rational numbers that increase or decrease over the simulation.
Principle (III) holds if the graph has a single root node such that in each graph there will be only one substate thereby excluding the possibility that the values of the same variable are in different substates .
Another approach to implementing (III) is for each root node to include values only from its own unique set of variables , such that
This approach, for example, is convenient in the graphs used for interactive simulation, where each next node reflects the next input of data from outside the simulation.
In practice, a simple way to implement principle (IV) is to check whether adding the next function to form does not include variables that are already in the results of the functions that have joint arguments with . For example, if there are nodes and for which and , where
and these nodes are the arguments of some function
for which the result is , then we can add only a function
for which and either or , but not .
3.3. Computability of the Simulation Graph and the Initial Set of Substates
In practice, we will need to find some specific simulation graph from some known set of consistent substates associated with the nodes of the graph . We will call the initial set of substates.
Definition 12.
Let us define the initial set of substates
associated with the specific nodes of the graph such that
where , , .
The search for a specific graph with some set can be imperatively represented as a calculation of all functions using as the initial arguments for these functions.
Note that the definition requires that be a subset of the one and only one set . However, in the general case, some can be a subset of more than one . In this case, in the imperative representation of the search, a single graph cannot be calculated from such since for some or all functions , not all arguments can be defined.
By representing the search for a specific in the form of a calculation of the functions , we notice that all will be calculated only if the values of all root nodes are known or can be obtained in some way. Thus, is a subset of the unique set (Formula (8)) if and only if, for each initial node , there exists a path
where is a node whose value is defined in , and all functions are this reversible (Supplementary S5).
Another important property of this approach is the glitching freedom described in [21,22]. Since only one graph is to be found, there never exist inconsistent substates .
3.4. Representation of the Dependence of Y on X in the Form of a Simulation Graph and a Graph Model
The dependence of the dependent variables upon the independent variables can be represented as a tuple of the transition graph , and the set of initial substates with given values of the parameters .
Definition 13.
Let us define a pair
representing the dependence of the variables on the variables , as parametrized by the values of , where
is a simulation graph found for a given , and , and
is the merging operation of the substates with the same key into the set of values .
The representation can be used to implement the model ; we call this implementation a graph model and denote it as
This implementation is similar to a representation in the form of a set of substates (Formula (4)), except that the set must first be found as
3.5. Simulation of the Graph Model as a Calculation of a Subset of the Values on the Subset and the Parameters G
For the graph model , we can define the simulation as the operator
where is the subset of known values of the set of independent variables and is the subset of unknown values of dependent variables .
The simulation can be implemented as a search for the simulation graph for a given initial set and a set . Then, from the set is constructed for each as follows:
In the simulation problem, we can significantly optimize the search for the graph . Since the set is usually much smaller than , we can search or calculate only a part of the substates from , which contain all the required keys :
We can also optimize by including substates that are as close as possible (from the point of view of the distance in the graph ) to substates from the desired or even equivalent to these substates. This will reduce the number of calculations not related to the search for (see Figure 4).
Figure 4.
Reduction in the number of calculations by including substates that are as close as possible to those from the desired
For the graphical model , an interactive simulation can also be performed. In the simplest case, this requires many models ; however, a more interesting and optimal approach is to undertake interactive manipulation of the values of the nodes when imperative representations (sequential calculation of the functions ) of the operation are used. This approach was explored briefly in [23].
Two patterns are possible here:
- Push pattern:This pattern can help synchronize the simulation with some external processes (for example, to synchronize with real-time). The essence of the pattern is that some function cannot be calculated until all its arguments are defined; thus, we can locally pause the simulation, leaving some of the root nodes uninitialized. We can then continue it by defining these nodes.
- Pool pattern:This pattern can be used to implement an asynchronous simulation reaction to some external events—for example, to respond to user input. As in the previous case, some remain uninitialized. However, the simulation does not stop there. Their values are constructed as needed to calculate the next . Using this approach, it is figuratively possible to imagine that undefined is computed by some set of unknown transition functions, possibly also combined into a transition graph. In other words, there is some “shadow” or “unknown” part of the graph and, as a result of its calculation, the is initialized (see Figure 5).
Figure 5. Representing the input/output as a set of unknown transition functions.
4. Logical Processors
We show how the graph model can be implemented using the reactive-stream paradigm in the form of a computational graph. We also show how the simulation can be evaluated on this graph and offer ways to optimize it. Additionally, in Supplementary S8, we implement a simple computational graph and perform a simulation with it.
4.1. Reactive Streams and Graph Model
The concept of reactive streams was formulated in 2014 in manifest [10,11,12] and extended by AKKA library developers with tools for composing reactive streams into computational graphs [13,24], which are already widely used in practice [9,25,26,27]. The graph nodes are logical processors, and the edges are the channels representing the stream of messages that transmit data; each of the processors transforms the messages in some way. Generally, reactive streams are an implementation of the well-known dataflow-programming paradigm [25].
This chapter will follow the approach described in (i.e., we will compose a computational system from small blocks that process data streams) [22,28,29]. However, we will use reactive streams to do all the hard work for us to distribute computation and load balancing.
We will denote messages (values) by , logical processors (reactors) by , channels connecting the processors by , and the numeral graph by .
We can transform an arbitrary graphical model (Formula (9)) into a computational graph :
- To represent each substate with the message .
- To replace all for which with equivalent processors :and all (for which ) with processors equivalent to the inverse functions :
- To successively replace all functions and all arguments that are already replaced by the channels , which are equivalent to :
- And to successively replace all , with the result having already been replaced by channel , by , which is equivalent to the inverse functions , consider the following:
As a result, we obtain a graph containing the equivalent for each but possibly differing structures compared to , since its construction was carried out starting from rather than from the root nodes (see Figure 6).
Figure 6.
Example of constructing the computational graph from the model .
Next, each root channel must be connected to a logical processor , whose task is to send the corresponding (where , which starts the computational process (see Figure 7).
Figure 7.
Addition of and into the computational graph
Moreover, all or part of the channels must be connected with one or more , which will collect part or all of the calculated substates belonging to the graph given by the set of initial states (see Figure 7).
4.2. Graph Optimization
Simply replacing functions with processors yields an extremely suboptimal and potentially infinite processing graph , which is not good from the viewpoint of minimizing computing resources. To solve this problem, we can optimize graph . For example, consider two optimization methods:
- Folding of cyclic sequences in the graph :Consider a chain with an arbitrary length of the same functions , as in Figure 8a. This can be transformed into a chain of logical processors of equal length, as in Figure 8b. We can fold this chain into a single by adding a message-return loop as in Figure 8c. Thus, more than one message will go through one , so that if has more than one argument, it can lead to collisions. To resolve collisions and also to implement breakage of the loop, we need to determine the loop-iteration number of messages . The simple way to do this is to add an iteration counter for each loop in . Another approach is to use history-sensitive values [21]. As a more complex example, we consider the graph in Figure 9a, which can be converted and collapsed into a compact graph as in Figure 9b.
Figure 8. Example of the folding of the simple computational graph . (a) a chain with an arbitrary length of the same functions . (b) a chain of logical processors of equal length. (c) folded chain of a single with a message-return loop.
Figure 9. Example of the folding of a more complex computational graph . (a) a more complex example of the graph . (b) graph built from . (c) folded graph into a single . - Folding of graph :
In general, the optimization problem for graph is rather complex and goes beyond the scope of this article.
4.3. Simulation of the Graph Model Using the Computational Graph
In the simplest case, we can simulate the model (Formula (10)) using the graph constructed on it in two stages:
- Calculate the set of substatesFor this, we initialize the calculation by sending messages using the processors . Using the processors , we collect all the calculated messages, .
- Find all substates for each key , and then collect the values from the found substates (Formula (6)).
In most cases, this approach will be computationally expensive since, in practice, usually occurs.
Generally, simulation optimization is the minimization of the number of calculated substates such that . Several approaches are possible here—for example, constructing a minimalistic with a certain well-known collection . Alternatively, lazy algorithms that cut off the calculations , whose result is not required to cover , could be used. However, this topic is beyond the scope of the present article.
5. Practice
In this chapter, we show our approach in practice. First, we describe a modeled object, then define its mathematical model and the analytical solution. In the next step, we explain the procedure of the construction of the graph and parallelization scheme and present the results. This chapter contains a shortened description; please check Supplementary S6–S8 for the full one.
5.1. Description of the Modeled Object and the Construction of Model
As an example, consider the classic model of saline mixing. Here, the simulated object is a system of two connected tanks of volumes and . Over time , a saline solution circulates from the first tank to the second with a speed and in the opposite direction with a speed of . In addition, the saline solution is poured into the first tank at a speed of and drains from the second tank at the same speed , i.e., the volume of the saline solution in the tanks does not change. Initially, the first and second tanks are entirely filled with solutions with initial salt concentrations of and , respectively. A saline solution with a concentration of is supplied to the first tank constantly. Thus, the set of variables reflecting the properties of interest will look like the following:
The modeling task is to predict the change in the salt concentrations and over time .
As part of the modeling problem to be solved, we represent the simulated object in the form of the model (Formula (3)), breaking the variables as
and specifying their dependence as a set of functions:
which are obtained by solving the Cauchy problem
We can also represent the simulated object in the form of model (Formula (4)). In this case, the values of the variable will be used as keys, and those of the variables and can be separated by different substates in such a way that we obtain two types of substates and . In the code, we can represent the values , and the substate as OOP classes (source code B.1.L27).
One simple, but impractical, way to construct a set of substates is to generate using a set of functions (Formula (12)) with some step of key (source code B.2.L60).
Using the model we can perform the simulation (Formula (5)) for some segment and obtain the corresponding set of values (source code B.1.L71 is an implementation of , and source code B.2.L70 is an implementation of ). Looking at the output plots, we can see that they are similar (see Figure 10).
Figure 10.
Results of a simulation of the (first plot) and (second plot) models, where the X axis is time and the Y axis is salt concentration, the green line is the salt concentration in tank 1, and the red line is the salt concentration in tank 2.
We can compare the results of executing the models and just by accumulating different overall output values:
Evaluating this algorithm (source B.3.L24), we obtain .
5.2. Building and Simulating a Graphical Model
The graph for this example will represent an infinite chain of pairs of nodes connected by edges . For convenience, in addition to the index of depth , we index the nodes with indices of width so that the nodes with the same index will have different values of . Moreover, we set , where is the index of the argument (edges) and q is the index of the substate assigned to . Each pair and corresponds to a certain moment of discrete time . For simplicity, we will use a fixed time step , where is the depth index, and is the time-step coefficient. Also, we restrict model time to a small interval . In this case, the graph will contain
pairs of nodes .
The simplest way to implement the transition functions and is to use the functions and from the set (Formula (12)). In this case,
A slightly more complicated implementation is to rewrite the system of differential equations (Formula (13)) to be solved by the Euler method
as iterated by :
In this case,
We implement the nodes and the sets of edges as OOP classes (source code C.1.L89). nodes are essentially variables that are not initially defined. The transition graph and the simulation graph can be represented as classes containing collections of nodes of sets of edges (source code C.1.L149). Moreover, the graph is the same as graph , but with all variables defined.
Due to the simplicity of the transition graph , we can implement the function build_Γ(, ), which automatically constructs based on the given number of steps and the time step (source code C.1.L190).
The search for the simulation graph is a calculation of the values of all nodes from the initial set of substates
We implement the search as method .γ(), using the indices and as the key in the set (source code C.1.L156). The method first initializes the nodes and with the initial substates and and then calculates the values of the rest nodes by calling each method .eval() until all are defined. The method .eval() checks whether the arguments
are defined and, if so, evaluates the result
The set of substates can be obtained from the simulation graph by simply extracting the values from the nodes and combining them into the set . We implement this in the form of the method .() (source code C.1.L179); next, can be used to obtain the values of from the values of .
5.3. Constructing and Calculating Graph Using the Graphical Model
As an example, we construct graph using the model for mixing salt solutions. To implement it, we use the AKKA Streams library. There was a similar approach for implementing the SwiftVis tool.
We can build an unoptimized version of graph by simply replacing the functions and with logical processors and and adding , , and .
We represent the substates in the form of the messages produced by the corresponding , where . In particular, the substates from the set can be represented as and .
This will work as follows (see source code D.1): the initial messages and are sent by logical processors and to the processors , . Then, the messages will distribute throughout the graph, where a copy of each substate is fed into the processor , which builds the resulting set of substates .
Since the standard blocks Zip, Flow.map, Broadcast, and Merge from the AKKA Streams library were used to construct graph , the implementation of each will be a nested graph.
Since the obtained graph consists of recurring pairs and , it can be optimized by implementing two cycles using two logical processors, and .
Since it is necessary in this case to determine which incoming messages refer to particular iterations of the cycle, we add the iteration (depth) counter to them, , and modify the grouping function Zip so that it selects pairs of incoming with the same value (source code D.2). When we execute this code, we obtain the simulation result (see Figure 11), which was the same as our findings from the implementation of the model (see Figure 10).
Figure 11.
Simulation of the model using graph , where the X axis is time and the Y axis is salt concentration, the green line is salt concentration in tank 1, the red line is salt concentration in tank 2, and the gray line is saline solution concentration supplied to tank 1 constantly.
6. Discussion
One of the primary contributions of this research is the synthesis of classical mathematical modeling techniques with the practical, high-performance synchronization mechanisms provided by reactive streams. Similar to earlier approaches, such as the Time Warp algorithm [1,2] and actor-based frameworks used in HPC simulation platforms [9], our method decomposes the complete object state into substates with unique keys. This modular representation not only supports reuse and flexibility but also enables the direct mapping of transition functions to logical processors. The resulting computational graph is reminiscent of systems such as RxHLA [7] and CQRS + ES architectures [8], which emphasize decoupling and distributed processing.
Representing the model as a transition graph and initial set of sates offers several benefits:
- Modularity and Reusability: By encapsulating transition rules as independent functional blocks, the approach supports reuse and flexibility. This modular structure is similar in spirit to block-diagram environments like Simulink [30,31,32] and has parallels in dataflow programming models discussed by Kuraj and Solar-Lezama [21].
- Scalability: Our implementation leverages the inherent parallelism of modern multi-core and distributed architectures. This approach aligns with the findings of actor-based models [9,25,26] and contemporary research on reactive programming in distributed systems [10,24].
- Interactive Simulation: The push and pool patterns introduced in our model are analogous to techniques used in recent studies on interactive and fault-tolerant reactive systems [23,33]. This design allows the simulation to respond in real time to external events or user inputs.
In summary, the proposed method of using reactive streams as a synchronization protocol for parallel simulation provides a compelling framework that unites rigorous mathematical modeling with practical, scalable implementation techniques. While challenges remain—particularly in optimization, continuous simulation, and fault tolerance, the initial results and conceptual clarity offer a solid foundation for further research and development. The integration of our approach with similar studies in the field [1,2,3,4,5,6,7,8,9,10,13,21,22,23,24,25,26,27,28,33,34] highlights its potential and provides clear directions for future work.
7. Future Work
Many unanswered questions remain, some of which we present for future research:
- Effective optimization of computational graph and simulation on it:Section 4.2 and Section 4.3 dealt with this topic. However, due to its complexity and vastness, it did not fit into this article. In general, this is a very important issue from a practical point of view. Solving it will significantly reduce the number of resources required to perform simulations. Another interesting question is the automation of the optimization of graph . Say that, initially, we have non-optimal , for example, obtained by the method described in Section 4.1. We want to automatically make C compact and computationally easy without loss of accuracy and consistency.The ML technique can be used to resolve the optimization task. For example, reinforcement rearming agents can be trained to explore various graph configurations (i.e., different ways to fold or collapse the computational graph) and learn which configurations yield the best performance in terms of latency, throughput, or resource consumption [35,36,37,38,39]. Also, techniques like neural architecture search (NAS) can be adapted to optimize the layout and parameters of the computational graph. This includes automatically deciding how to fold cyclic sequences, balancing load among logical processors, and minimizing redundant computations [38,39,40].
- Accurate simulation of continuous-valued models:Many properties of modeled objects can be represented in continuous quantities, for example, values from the set ℝ. However, the simulation (the calculation of which is based on message forwarding) is inherently discrete. An open question remains as to how accurately continuous quantities can be calculated. The question is how to increase the accuracy of calculating such quantities without increasing the requirements for computer resources.
- Fault-tolerance of reactive streams:We did not touch on fault tolerance of simulation in this work, but in most real/practical applications, fault tolerance is very important. This question was partially explored in [23], but we also suggest this for future work.
- Manual and automatic graph construction :From a practical viewpoint, it is interesting to be able to use some IDE to manually construct a computational graph and to do this in such a way that the corresponding graph will be consistent and optimal. For example, this might be performed similarly to the Simulink package [30,41], SwiftVis tool [25,42], or XFRP language (Version 2.9.644) [24,43]. It is also interesting to find ways to automate the construction of . For example, the model can initially be defined as a certain set of rules by which graph can be automatically and even dynamically constructed. Specialized programming languages are also an interesting area to explore. For example, the EdgeC [33] language can be considered a tool to describe computational graphs.Also, the ML technique can be applied wildly here. For example, graph learning techniques from graph neural networks (GNNs) can be applied to learn the structure of the optimal computational graph from historical data. The learned model can then suggest or automatically construct a more efficient graph based on current simulation requirements. Adaptive scheduling ML algorithms can dynamically adjust the scheduling of tasks across logical processors, optimizing the execution order and balancing the load [44,45]. This is particularly useful in interactive or real-time simulations where conditions may change frequently.
- Testing with complex models and comparing with other parallelizing approaches:This work provides a small, simple example of parallel simulation to show how the described approach can be implemented in practice. However, the questions of checking this approach with large and complex models and comparing its effectiveness with other parallelizing approaches remain open.
8. Conclusions
The proposed method effectively integrates the reactive stream paradigm with classical mathematical modeling techniques to create a scalable framework for parallel simulation. By using a graph-based representation of object states and transition functions, this approach enhances modularity and reusability while supporting efficient computation through logical processors. The implementation using AKKA reactive streams demonstrates its scalability and practical feasibility for distributed systems. Despite its promise, the work highlights challenges such as graph optimization, continuous model simulation, fault tolerance, and automation of graph construction, which offer significant areas for future research and development. The study lays a strong foundation for advancing parallel simulation techniques, emphasizing both theoretical robustness and practical scalability.
Supplementary Materials
The following supporting information can be downloaded at https://www.mdpi.com/article/10.3390/computation13050103/s1, Supplementary S1: Notation; Supplementary S2: Basic definitions [46,47,48,49,50,51,52,53,54,55,56,57,58,59]; Supplementary S3: Transition functions [60,61,62]; Supplementary S4: Building of a consistent graph theorem ; Supplementary S5: Completeness of the set of initial substates theorem; Supplementary S6: Example: Description of the modeled object and the construction of model ; Supplementary S7: Example: Building and simulating a graphical model ; Supplementary S8: Example: Constructing and calculating graph using the graphical model .
Author Contributions
O.S.: Conceptualization, methodology, formal analysis, writing, visualization, software. A.P.: Conceptualization, methodology, formal analysis, writing—original draft preparation, and visualization. I.P.: Methodology, software, formal analysis, data curation, and writing—original draft preparation. M.Y.: Investigation, resources and editing, and visualization. H.K.: Supervision, data curation, and writing—review and editing. V.A.: Supervision, data curation, visualization, and writing—review and editing. All authors have read and agreed to the published version of the manuscript.
Funding
This research received no external funding.
Data Availability Statement
The raw data supporting the conclusions of this article will be made available by the authors upon request.
Acknowledgments
This work represents a harmonious blend of independent research pursuits and a series of scientifically rigorous endeavors underpinned by various grants. The authors would like to extend their heartfelt gratitude to all the institutions and organizations, reviewers, and our editor, who have contributed to the successful completion of this study. The research was conducted as part of the projects ‘Development of methods and means of increasing the efficiency and resilience of local decentralized electric power systems in Ukraine’ and ‘Development of Distributed Energy in the Context of the Ukrainian Electricity Market Using Digitalization Technologies and Systems,’ implemented under the state budget program ‘Support for Priority Scientific Research and Scientific-Technical (Experimental) Developments of National Importance’ (CPCEL 6541230) at the National Academy of Sciences of Ukraine.
Conflicts of Interest
The authors declare no conflicts of interest.
References
- Jeerson, D.R.; Sowizral, H.A. Fast Concurrent Simulation Using the Time Warp Mechanism; Part I: Local Control; Rand Corp: Santa Monica, CA, USA, 1982. [Google Scholar]
- Richard, R.; Fujimoto, M. Parallel and Distributed Simulation Systems; Wiley: New York, NY, USA, 2000. [Google Scholar]
- Radhakrishnan, R.; Martin, D.E.; Chetlur, M.; Rao, D.M.; Wilsey, P.A. An Object-Oriented, Time Warp Simulation Kernel. In Proceeding of the International Symposium on Computing in Object-Oriented Parallel Environments (ISCOPE’98), Santa Fe, NM, USA, 8–11 December 1998; Caromel, D., Oldehoeft, R.R., Tholburn, M., Eds.; Springer: Berlin/Heidelberg, Germany, 1998; Volume 1505, pp. 13–23. [Google Scholar]
- Jefferson, D.; Beckman, B.; Wieland, F.; Blume, L.; Diloreto, M. Time warp operating system. In Proceedings of the eleventh ACM Symposium on Operating systems principles, Austin, TX, USA, 8–11 November 1987; Volume 21, pp. 77–93. [Google Scholar]
- Aach, J.; Church, G.M. Aligning gene expression time series with time warping algorithms. Bioinformatics 2001, 17, 495–508. [Google Scholar] [CrossRef] [PubMed]
- Nicol, D.M.; Fujimoto, R.M. Parallel simulation today. Ann. Oper. Res. 1994, 53, 249. [Google Scholar] [CrossRef]
- Falcone, A.; Garro, A. Reactive HLA-based distributed simulation systems with rxhla. In Proceedings of the 2018 IEEE/ACM 22nd International Symposium on Distributed Simulation and Real Time Applications (DS-RT), Madrid, Spain, 15–17 October 2018; pp. 1–8. [Google Scholar]
- Debski, A.; Szczepanik, B.; Malawski, M.; Spahr, S. In Search for a scalable & reactive architecture of a cloud application: CQRS and event sourcing case study. IEEE Software 2016, 99. [Google Scholar] [CrossRef]
- Bujas, J.; Dworak, D.; Turek, W.; Byrski, A. High-performance computing framework with desynchronized information propagation for large-scale simulations. J. Comp. Sci. 2019, 32, 70–86. [Google Scholar] [CrossRef]
- Reactive Stream Initiative. Available online: https://www.reactive-streams.org (accessed on 15 April 2025).
- Davis, A.L. Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams; Apress: New York, NY, USA, 2018. [Google Scholar]
- Curasma, H.P.; Estrella, J.C. Reactive Software Architectures in IoT: A Literature Review. In Proceedings of the 2023 International Conference on Research in Adaptive and Convergent Systems (RACS ‘23), Association for Computing Machinery, New York, NY, USA, 6–10 August 2023; Article 25. pp. 1–8. [Google Scholar] [CrossRef]
- The Implementation of Reactive Streams in AKKA. Available online: https://doc.akka.io/docs/akka/current/stream/stream-introduction.html (accessed on 15 April 2025).
- Oeyen, B.; De Koster, J.; De Meuter, W. A Graph-Based Formal Semantics of Reactive Programming from First Principles. In Proceedings of the 24th ACM International Workshop on Formal Techniques for Java-like Programs (FTfJP ‘22), Association for Computing Machinery, New York, NY, USA, 7 June 2022; pp. 18–25. [Google Scholar] [CrossRef]
- Posa, R. Scala Reactive Programming: Build Scalable, Functional Reactive Microservices with Akka, Play, and Lagom; Packt Publishing: Birmingham, UK, 2018. [Google Scholar]
- Baxter, C. Mastering Akka; Packt Publishing: Birmingham, UK, 2016. [Google Scholar]
- Nolte, D.D. The tangled tale of phase space. Phys. Today 2010, 63, 33–38. [Google Scholar] [CrossRef]
- Myshkis, A.D. Classification of applied mathematical models-the main analytical methods of their investigation. Elem. Theory Math. Models 2007, 9, 9. [Google Scholar]
- Briand, L.C.; Wust, J. Modeling development effort in object-oriented systems using design properties. IEEE Trans. Softw. Eng. 2001, 27, 963–986. [Google Scholar] [CrossRef]
- Briand, L.C.; Daly, J.W.; Wust, J.K. A unified framework for coupling measurement in object-oriented systems. IEEE Trans. Softw. Eng. 1999, 25, 91–121. [Google Scholar] [CrossRef]
- Shibanai, K.; Watanabe, T. Distributed functional reactive programming on actor-based runtime. In Proceedings of the 8th ACM SIGPLAN International Workshop on Programming Based on Actors, Agents, and Decentralized Control, Boston, MA, USA, 5 November 2018; pp. 13–22. [Google Scholar]
- Lohstroh, M.; Romeo, I.I.; Goens, A.; Derler, P.; Castrillon, J.; Lee, E.A.; Sangiovanni-Vincentelli, A. Reactors: A deterministic model for composable reactive systems. In Cyber Physical Systems. Model-Based Design; Springer: Cham, Switzerland, 2019; pp. 59–85. [Google Scholar]
- Mogk, R.; Baumgärtner, L.; Salvaneschi, G.; Freisleben, B.; Mezini, M. Fault-tolerant distributed reactive programming. In Proceedings of the 32nd European Conference on Object-Oriented Programming (ECOOP 2018), Amsterdam, The Netherlands, 19–21 July 2018. [Google Scholar]
- About the Graphs in AKKA Streams. Available online: https://doc.akka.io/docs/akka/2.5/stream/stream-graphs.html (accessed on 15 April 2025).
- Kurima-Blough, Z.; Lewis, M.C.; Lacher, L. Modern parallelization for a dataflow programming environment. In Proceedings of the International Conference on Parallel and Distributed Processing Techniques and Applications (PDPTA), The Steering Committee of the World Congress in Computer Science, Computer Engineering and Applied Computing (WorldComp), Las Vegas, NV, USA, 17–20 July 2017; pp. 101–107. [Google Scholar]
- Kirushanth, S.; Kabaso, B. Designing a cloud-native weigh-in-motion. In Proceedings of the 2019 Open Innovations (OI), Cape Town, South Africa, 2–4 October 2019. [Google Scholar]
- Prymushko, A.; Puchko, I.; Yaroshynskyi, M.; Sinko, D.; Kravtsov, H.; Artemchuk, V. Efficient State Synchronization in Distributed Electrical Grid Systems Using Conflict-Free Replicated Data Types. IoT 2025, 6, 6. [Google Scholar] [CrossRef]
- Oeyen, B.; De Koster, J.; De Meuter, W. Reactive Programming without Functions. arXiv 2024, arXiv:2403.02296. [Google Scholar] [CrossRef]
- Babaei, M.; Bagherzadeh, M.; Dingel, J. Efficient reordering and replay of execution traces of distributed reactive systems in the context of model-driven development. In Proceedings of the 23rd ACM/IEEE International Conference on Model Driven Engineering Languages and Systems, Virtual Event, 16–23 October 2020. [Google Scholar]
- Simulink. Available online: https://www.mathworks.com/help/simulink/index.html?s_tid=CRUX_lftnav (accessed on 15 April 2025).
- Karris, S.T. Introduction to Simulink with Engineering Applications; Orchard Publications: London, UK, 2006. [Google Scholar]
- Dessaint, L.-A.; Al-Haddad, K.; Le-Huy, H.; Sybille, G.; Brunelle, P. A power system simulation tool based on Simulink. IEEE Trans. Ind. Electron. 1999, 46, 1252–1254. [Google Scholar] [CrossRef]
- Kuraj, I.; Solar-Lezama, A. Aspect-oriented language for reactive distributed applications at the edge. In Proceedings of the Third ACM International Workshop on Edge Systems, Analytics and Networking 2020, (EdgeSys ‘20), Association for Computing Machinery, New York, NY, USA, 27 April 2020; pp. 67–72. [Google Scholar] [CrossRef]
- Babbie, E.R. The Practice of Social Research; Wadsworth Publishing: Belmont, CA, USA, 2009; ISBN 0-495-59841-0. [Google Scholar]
- Zoph, B.; Le, Q.V. Neural Architecture Search with Reinforcement Learning. arXiv 2016, arXiv:1611.01578. [Google Scholar]
- Nakata, T.; Chen, S.; Saiki, S.; Nakamura, M. Enhancing Personalized Service Development with Virtual Agents and Upcycling Techniques. Int. J. Netw. Distrib. Comput. 2025, 13, 5. [Google Scholar] [CrossRef]
- Liu, M.; Zhang, L.; Chen, J.; Chen, W.-A.; Yang, Z.; Lo, L.J.; Wen, J.; O’Neil, Z. Large language models for building energy applications: Opportunities and challenges. Build. Simul. 2025, 18, 225–234. [Google Scholar] [CrossRef]
- Kipf, T.N.; Welling, M. Semi-Supervised Classification with Graph Convolutional Networks. International Conference on Learning Representations (ICLR). arXiv 2017, arXiv:1609.02907. [Google Scholar]
- Nie, M.; Chen, D.; Chen, H.; Wang, D. AutoMTNAS: Automated meta-reinforcement learning on graph tokenization for graph neural architecture search. Knowl.-Based Syst. 2025, 310, 113023. [Google Scholar] [CrossRef]
- Kuş, Z.; Aydin, M.; Kiraz, B.; Kiraz, A. Neural Architecture Search for biomedical image classification: A comparative study across data modalities. Artif. Intell. Med. 2025, 160, 103064. [Google Scholar] [CrossRef]
- Chaturvedi, D.K. Modeling and Simulation of Systems Using MATLAB and Simulink; CRC Press: Boca Raton, FL, USA, 2017. [Google Scholar]
- Lewis, M.C.; Lacher, L.L. Swiftvis2: Plotting with spark using scala. In Proceedings of the International Conference on Data Science (ICDATA’18), Las Vegas, NV, USA, 30 July–2 August 2018; Volume 1. [Google Scholar]
- Yoshitaka, S.; Watanabe, T. Towards a statically scheduled parallel execution of an FRP language for embedded systems. In Proceedings of the 6th ACM SIGPLAN International Workshop on Reactive and Event-Based Languages and Systems, Athens, Greece, 21 October 2019; pp. 11–20. [Google Scholar] [CrossRef]
- Bassen, J.; Balaji, B.; Schaarschmidt, M.; Thille, C.; Painter, J.; Zimmaro, D.; Games, A.; Fast, E.; Mitchell, J.C. Reinforcement learning for the adaptive scheduling of educational activities. In Proceedings of the 2020 CHI Conference on Human Factors in Computing Systems, CHI ‘20, Honolulu, HI, USA, 25–30 April 2020; pp. 1–12. [Google Scholar] [CrossRef]
- Long, L.N.B.; You, S.-S.; Cuong, T.N.; Kim, H.-S. Optimizing quay crane scheduling using deep reinforcement learning with hybrid metaheuristic algorithm. Eng. Appl. Artif. Intell. 2025, 143, 110021. [Google Scholar] [CrossRef]
- Pietarinen, A.; Senden, Y.; Sharpless, S.; Shepperson, A.; Vehkavaara, T. The Commens Dictionary of Piece’s Terms, “Object,” 2009-03-19. Available online: https://web.archive.org/web/20090214004523/http:/www.helsinki.fi/science/commens/terms/object.html (accessed on 15 April 2025).
- Sismondo, S. Models, Simulations, and Their Objects. Sci. Context 1999, 12, 247–260. [Google Scholar] [CrossRef]
- Achinstein, P. Theoretical models. Br. J. Philos. Sci. 1965, 16, 102–120. [Google Scholar] [CrossRef]
- Banks, J.; Carson, J.; Nelson, B.; Nicol, D. Discrete-Event System Simulation; Prentice Hall: Hoboken, NJ, USA, 2001; ISBN 0-13-088702-1. [Google Scholar]
- Brézillon, P.; Gonzalez, A.J. (Eds.) Context in Computing: A Cross-Disciplinary Approach for Modeling the Real World; Springer: New York, NY, USA, 2014. [Google Scholar]
- Varga, A. Discrete event simulation system. In Proceedings of the European Simulation Multiconference (ESM2001), Prague, Czech Republic, 6–9 June 2001; Volume 17. [Google Scholar]
- Choi, B.K.; Kang, D. Modeling and Simulation of Discrete Event Systems; John Wiley & Sons: Hoboken, NJ, USA, 2013. [Google Scholar]
- Goldsman, D.; Goldsman, P. Discrete-event simulation. In Modeling and Simulation in the Systems Engineering Life Cycle: Core Concepts and Accompanying Lectures; Springer London: London, UK, 2015; pp. 103–109. [Google Scholar]
- Robinson, S. Conceptual modeling for simulation. In Winter Simulations Conference (WSC); IEEE: Piscataway, NJ, USA, 2013. [Google Scholar]
- Robinson, S. A tutorial on conceptual modeling for simulation. In Winter Simulation Conference (WSC); IEEE: Piscataway, NJ, USA, 2015. [Google Scholar]
- Abdelmegid, M.A.; Gonzales, V.A.; Naraghi, A.M.; O’Sullivan, M.; Walker, C.G.; Poshdar, M. Towards a conceptual modeling framework for construction simulation. In Winter Simulation Conference (WSC); IEEE: Piscataway, NJ, USA, 2017. [Google Scholar]
- Curtright, T.L.; Zachos, C.K.; Fairlie, D.B. Quantum mechanics in phase space. Asia Pac. Phys. Newsl. 2012, 1, 37–46. [Google Scholar] [CrossRef]
- Wu, B.; He, X.; Liu, J. Nonadiabatic field on quantum phase space: A century after Ehrenfest. J. Phys. Chem. Lett. 2024, 15, 644–658. [Google Scholar] [CrossRef] [PubMed]
- Hastings, N.B. Workshop Calculus: Guided Exploration with Review; Springer Science & Business Media: Berlin, Germany, 1998. [Google Scholar]
- Keller, R.M. Formal verification of parallel programs. Commun. ACM 1976, 19, 371–384. [Google Scholar] [CrossRef]
- Erwig, M.; Kollmansberge, S. Functional pearls: Probabilistic functional programming in Haskell. J. Funct. Program. 2006, 16, 21–34. [Google Scholar] [CrossRef]
- Saini, A.; Thiry, L. Functional programming for business process modeling. IFAC-PapersOnLine 2017, 50, 10526–10531. [Google Scholar] [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).