Rust DES

RustDiscrete Event SimulationAlgorithms & Data Structures

Rust DES represents my venture into applying the Rust programming language to the field of clinical trials, specifically focusing on patient demand forecasting through Discrete Event Simulation (DES). With a background primarily in higher-level languages and a theoritical understanding of low-level languages, I embarked on this project to explore Rust's unique approach to memory management, particularly its memory ownership and borrowing model.

My previous experience with DES provided a solid foundation for this project, allowing me to extract a simple yet realistic problem to experiment with and effectively apply my knowledge to a new and challenging context.

Understanding Discrete Event Simulation (DES)

What is DES?

Discrete Event Simulation (DES) is a powerful modeling technique used to simulate the behavior and performance of a real-life system. The core concept of DES lies in its ability to represent the operation of a system as a chronological sequence of events. Each event occurs at a particular instant in time and marks a change of state in the system. Each event is also associated with a set of actions that are executed when the event occurs. The execution of these actions may result in the generation of new events, which are then scheduled for execution at a later time.

The Value of DES in Complex Systems

DES is particularly valuable in analyzing complex and highly stochastic systems. It excels in environments where the behavior of the system is dictated by discrete events and where the interplay of these events can lead to varied outcomes.

Application in Patient Demand Forecasting

In the context of clinical trials, DES provides a robust framework for forecasting and managing patient demand. Clinical trials are inherently complex, with numerous variables and stochastic elements such as patient recruitment rates, treatment durations and evolutions. DES allows for the detailed simulation of these trials, capturing the randomness and variability inherent in such processes.

The Rust Implementation

Discrete Event Simulation (DES) presents itself as an ideal sandbox problem for exploring the capabilities of Rust. The requirements of DES demand a programming language that excels in efficient memory management, parallel processing, and handling of complex data structures. Rust, with its unique features, offers a perfect testing ground to push the boundaries of these aspects.

The following key features of Rust utilized in the DES implementation highlight how the language and its ecosystem meets these demands:

  • Priority Queue for Event Management: To efficiently process events in chronological order.

  • Efficient Memory Usage in Data Collections: Optimized handling of realization collections, such as monthly kit demands, minimizing memory footprint while focusing on specific computations like quantiles.

  • Parallel Processing Capabilities: Leveraging Rust's concurrency and safe shared data handling for simultaneous, interdependent processes in the simulation.

  • Custom Probabilistic Automaton: Utilizing Rust's advanced data structures, including hash structures with composite keys, to model complex probabilistic events, essential for realistic simulations of the patient's treatment and evolution.

Each element showcases Rust's strengths in efficiently managing the intricate requirements of a DES system, making it an excellent choice for this type of application. This implementation of a few hundred LOC demonstrates remarkable efficiency, capable of running thousands of simulations for a complex oncological trial involving 1000 patients, randomization, and weight evolution, in under a minute while maintaining an exceptionally low memory footprint of less than 20MB.