The text of a manual · part 10 of 14
Feasibility of formal model checking in the Vitatron environment: Chapter 5Formal modeling of pacemakerfirmware, pages 55 to 60
Pages 55 to 60 of 91, from Feasibility of formal model checking in the Vitatron environment
The original document is the PDF (6.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the Vitatron EE244
Page 55
Because synchronizations can not be parameterized in Uppaal1 , data flows can not be modeled as this is done in mCRL2. Instead we use global variables for modeling data flows. The source of the data flow sends its output to a global variable which can be read by any receiving process. This is dangerous because the global variable can potentially be written by any process, but simplicity is the reason why this modeling has been chosen. Furthermore, to avoid unwanted writing to global variables, naming conventions are used in the Uppaal models. We encountered a type problem when modeling the hardware module PG in Uppaal. On an atrial or ventricular event, the current values of the atrial timer and the ventricular timer must be stored in global variables (representing the data flows aa int, av int, va int and vv int, see chapter 4). The atrial timer and the ventricular timer are represented by two clock variables which are reset on each atrial or on each ventricular event, respectively. But storing of the current clock value in a global integer variable is not just a matter of assigning the clock value to the global variable, because this results in a typing error. Clock variables are real typed and Uppaal does not provide a type casting function. To store the value of the clock variable in an integer variable anyhow, we created a committed state with looping transitions which increase the global variable as long as it is smaller than the clock value. Of course this has unfavorable effects on the model state space, because the system runs through a rather lot of intermediate states while performing these looping transitions. The effects on the state space are reduced by creating three kinds of these looping transitions which increase the variable with 1, 10, or 100 (each time only the maximal possibility is enabled).
5.4
Formal model of heart behavior and PG
As an environment in which the formal pacemaker model can be verified, a formal model is developed that simulates the heart behavior. This model is constructed such that it can show various rhythms, PVCs, retrograde conduction and crosstalk (refer to section 3.4 for these terms). Interaction between the pacemaker model and the heart model happens by sense and pace events between these models. The formal heart model has been developed through consultation with Vitatron. This section briefly describes the heart model to indicate against which behavior the pacemaker model has been verified. Creating this awareness is important, because any heart model always is an abstraction of the reality. If the pacemaker model is found to be correct based on verification against this heart model, it can always be the case that flaws occur for heart behavior that is outside the scope of this heart model. The formal heart model consists of two processes that simulate the behavior of the atrium and the ventricle and 5 processes that together simulate the behavior of the AV node. In figure 5.2 an overview of the heart model is given. The left hand side of this figure shows the architecture of the heart processes where the possible events between the processes are represented by dashed lines. The right hand side shows the behavior of one single AV node process in a kind of state transition diagram that partially depends on time (its meaning is described further on). 1 Parameterization of synchronizations can be simulated by introducing arrays of synchronization channels, but this is rather awkward.
54
Page 56
Figure 5.2: Formal heart model overview The atrium can contract upon receipt of an atrial pace from the PG, upon receipt of a stimulus from the AV node (simulating retrograde conduction) and it can generate a spontaneous contraction to simulate the function of the sinus node. After each contraction, the atrium process determines when its next spontaneous contraction will take place by making a non-deterministic choice from a number of rates; this spontaneous contraction will of course only take place if no stimulus from the PG or the AV node arrives before the determined moment in time. Upon each contraction an event is sent to the AV node processes to start the conduction to the ventricle and the atrial refractory period is enabled in which all external stimuli to the atrium are ignored. If the contraction was not caused by an atrial pace, an atrial sense event is sent to the PG. Atrioventricular crosstalk is modeled by allowing the atrium process to possibly send a ventricular sense event to the PG shortly after an atrial pace is received (a ventricular sense is classified as crosstalk ventricular sense if the PG receives it within 90 ms after the atrial pace has been delivered). The ventricle process behaves analogously, except that crosstalk does not have to be addressed in this process and that it only has two choices for its spontaneous contraction rate. One choice is a very low rate, which corresponds to the normal heart behavior in which the ventricle does not show spontaneous contractions. The second choice is a relatively high rate to enable the ventricle process to show PVCs. Next we address the processes that simulate the behavior of the AV node (refer to section 3.2.2 for a purpose description of the AV node). Each process represents a slice of the AV node and is responsible for delaying all conduction signals that travel through the AV node. The total delay that a conduction signal encounters in anterograde direction (100 ms) is smaller than the delay in retrograde direction (450 ms) which is according to the natural behavior of the AV node (although these values can vary in the heart’s natural behavior, we have modeled
55
Page 57
them as constants to limit the state space size). During delaying a signal and a period here after each slice is refractory meaning that any incoming signal is not handled. This behavior is illustrated in the right hand side of figure 5.2: the slice is non-refractory until any external stimulation arrives (either from another slice, the atrium or the ventricle). Upon receipt of an external stimulation, the slice starts its anterograde delay; after this delay the stimulus is ‘conducted’ to the slice below (or the ventricle in case of the lower slice). Then the retrograde delay starts after which the stimulus is send to the slice above (or the atrium in case of the upper slice). Finally the slice remains refractory for a while after which it returns to its non-refractory state. The AV node is modeled in several slices to take the behavior of the natural AV node in the following situation into account: The atrium contracts and triggers the AV node (at the upper side) and before the signal is conducted to the ventricle, the ventricle also contracts and triggers the AV node (at the lower side). In this situation two conduction signals approach each other in the AV node. On the moment that the two signals meet each other in a cell somewhere halfway the AV node, they will extinguish. This happens because the first signal that arrives at this cell makes this cell refractory which causes that the secondly arriving signal will not be conducted anymore. In reality the AV node contains too many cells to model them all as a separate process. Therefore it is chosen to model 5 slices which all represent one fifth of the AV node cells. As described in chapter 4, the PG is the interface between the pacemaker leads and the firmware. Therefore the PG is also formalized in the models that contain the heart model. The atrial and ventricular timer are modeled as two parameters in the PG (by clock variables in Uppaal and by naturals that are increased on every tick-action in mCRL2).
Here some text is removed for confidentiality reasons. This text describes how some PG details are formally modeled.
5.5
State space reducing modeling techniques
During the actual model checking several adaptations were made to the models in order to limit the state space. These state space reductions emerged from a kind of iterative procedure; each time the model state space size appeared to be too large we tried to invent a reduction that would be helpful in the specific model. The adaptations vary from just changing some constants to adding transitions and to making the ordering of events more strictly. This section clarifies these reductions and explains why they are justified, i.e. why the behavior of the model still conforms to the behavior of the modeled system. The H&P model of the pacemaker firmware specifies that a command for an atrial pace is given on the detection of a PVC (in case of a sequence of PVCs this is only done for the 56
Page 58
first PVC in the sequence). As described in section 3.4 this PVC-A stim is given to prevent that the ventricular contraction will be retrogradely conducted to the atrium. This is formally modeled by allowing the process PVC Astim Generator to send a message to the PG that upon receipt of this message will directly deliver an atrial pace. Furthermore the accompanying document of the H&P model specifies the following: “The time between the PVC and PVC-A stim has to be less than 40 ms. Note: The specified value of 40 (ms) is a maximum. The implementation should strive for an as short as possible delay in order to optimize the effectiveness of this feature.” Initially this was modeled by allowing an arbitrary time passage (but less than 40 ms) after the process PVC Astim Generator has decided that a PVC-A stim must be given. This resulted in an enormous state space explosion, because each possible time passage between the PVC and the PVC-A stim caused a different value to be stored by the PG in va int and aa int. Although the precise moment in time on which the PVC-A stim is given does not have great influence on the behavior of the system, the many different values of va int and aa int that are stored in the model state result in an explosion of states. Therefore we skipped the implementation of the 40 ms delay between the PVC and the PVC-A stim and just give the command for the PVC-A stim directly after detecting the PVC. Because the firmware implementation should strive for an as short as possible delay, the formal model does not deviate from the specified system too much in this way. But it is important to realize that this is a real simplification of the formal model which potentially can hide certain flaws in the firmware design that are caused by the time interval between a PVC and the PVC-A stim. Recall from section 4.1 that in a process activation table (PAT) in an H&P model the order of triggering PSPECs and child DFDs and sending output events (PAT-consequences in the sequel) can be specified. Figure 4.4 shows that this order is specified by numbering the PATconsequences. But often a PAT does not specify the exact order of the PAT-consequences by numbering them all with the same number. This is usually done because the order does not matter for the behavior of the system. Then the choice for a specific order is just left open for the ones that implement the system. Again in a try to deviate as less as possible from the specified system, we modeled such ‘unordered’ PAT-consequences by triggering (sending the event or executing the PSPEC’s pseudo-code) these processes all consecutively, followed by waiting on an acknowledgment message from all these processes. But as you can imagine, the fact that a number of processes can be processing an event simultaneously, results in many possible interleavings in the model state space and hence in an explosion of the state space. To reduce the state space we decided to fix the ordering of the PAT-consequences according to the choices that are made in the implementation code of the firmware system (the implementation of the firmware system must choose a specific ordering because the system has no parallel threads). Because the model checking purpose is verification of the system specification and not of the system implementation, this is not preferred. It could be the case that the choices that are made in the translation of the system specification to its implementation accidentally have made the system behavior satisfying its requirements, while other choices would have resulted in incorrect system behavior. But keeping this in mind, we have made this decision to be at least able to verify a model that corresponds to the system implementation. 57
Page 59
Next, we applied some state space reductions in the processes that are responsible for detection and handling of retrograde conduction. The DFD VP AS Pattern maintains two counter variables; Total PRAS cntr that counts the number of possibly retrogradely conducted atrial senses and Successive VP cntr that counts the number of successive ventricular paces. Based on the values of these counter variables this process might decide that retrograde conduction is probably present and can start the RC Test therapy in order to verify this and to handle appropriately. Basically said, this decision is made if Total PRAS cntr crosses a certain threshold value while Successive VP cntr is yet under another threshold value. The factory settings of these two mentioned threshold values are 26 and 32, respectively. Therefore it takes a rather large sequence of atrial senses and ventricular paces before the RC Test is started, which results in many intermediate states in the state space. By decreasing the threshold values, the amount of intermediate states can be reduced which also reduces the state space significantly. In the occurrence of a certain event sequence2 the counter variable Successive VP cntr keeps being increased without ever checking whether it already crossed the threshold value. If this event sequence holds on infinitely Successive VP cntr is also being increased infinitely, resulting in a infinite state space. This is highly undesirable, so we have added an upper bound in the specification of VP AS Pattern which avoids that Successive VP cntr becomes much greater than the threshold value.
Figure 5.3: STD structure of Multiple Successive VS and NOA Detection 2
A sequence of alternating ventricular paces and PFASs is present. PFAS stands for Potential Farfield Atrial Sense, which means that the time interval between this atrial sense and the preceding ventricular event is too short to be conducted retrogradely.
58
Page 60
The DFDs Multiple Successive VS and NOA Detection both maintain a counter variable and are driven by a state transition diagram which is similar for both processes. The structure of these state transition diagrams is shown in figure 5.3. Note that the labels on a transition in the state transition diagram define the received action above the bar and the triggered PSPEC below the bar. The word ‘cntr’ between two horizontal lines represents a data store, containing a counter variable. The counter variable is only used when the STD is in the state ‘counting active’; in this state the number of received ‘Event B’ events is counted and on the third ‘Event B’ the STD moves to state ‘counting inactive’. Although the counter variable is not used in state ‘counting inactive’, it is not reset upon the transition to this state. Hence the last used value of the counter variable stays in the variable, which has negative consequences on the state space. Potentially the size of the state space is multiplied by 4 for all 4 values that the counter can have; because there are 2 such processes, this factor can even become 16. Therefore we added a reset of the counter variable to the transitions to state ‘counting inactive’. So both on receipt of ‘Event C’ as on receipt of the third ‘Event B’ in state ‘counting active’ the counter is reset. Because the nature of Multiple Successive VS and NOA Detection implies that they are only counting in a limited part of the state space, the values of their counter variables only differ from 0 in this part of the state space. Experimentally it has been encountered that this adaptation reduces the size of the state space significantly, while the behavior of the model clearly is left unchanged. As described in section 4.2, the Atrial Monitor updates a physiological band on every incoming atrial event and the Ventricular Monitor updates a moving average of the ventricular rate on every incoming ventricular event. This causes that a lot of information about the rate history is stored in the state space which has dramatic results on the size of the state space. To limit these results the following changes have been made: Normally the physiological band is increased or decreased in steps of 2 if the current atrial rate is higher or lower, respectively than the current physiological band. This step size is now increased to 20 so that the number of possible band values decreases. In this way the band still follows the current atrial rate; although this happens a lot coarser now, incoming atrial events can still be classified based on the physiological band. The value of the ventricular rate average has been fixed, which is of course the best reduction that can be applied on a varying parameter. The only decision that is based on the average ventricular rate is whether an incoming atrial sense should be tracked or not; by fixing the average ventricular rate this tracking decision is made less history dependent, but because the tracking decision is also based on the physiological band the behavior will not be radically changed. The value to which the average ventricular rate has been fixed is 110, which is chosen to enable the occurring of repeatedly retrograde conduction; if the value would be lower, any retrogradely conducted atrial sense would not be tracked by ventricular paces which would stop the retrograde conduction sequence.
59