From 6a01ad4a591dba9ae4b346d1f153a5ee52ef1fe1 Mon Sep 17 00:00:00 2001 From: Galen Seilis Date: Mon, 30 Jun 2025 06:59:57 -0700 Subject: [PATCH] Type annotation and validation of exact in simulation.py - Add type annotation for `exact`. - Add input validation for `exact`. - Add short explanation in docstring. --- ciw/simulation.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ciw/simulation.py b/ciw/simulation.py index 858bd4e..04decc9 100644 --- a/ciw/simulation.py +++ b/ciw/simulation.py @@ -21,7 +21,7 @@ class Simulation(object): def __init__( self, network, - exact=False, + exact: int = 0, name="Simulation", tracker=None, deadlock_detector=None, @@ -32,8 +32,20 @@ def __init__( server_class=None, ): """ - Initialise an instance of the simualation. + Initialise an instance of the simulation. + + This class supports exact arithmetic when `exact` is given a positive integer + representing the desired numerical precision. A precision of `0` is interpreted + to mean using ordinary float precision. """ + + # Input validation + if not isinstance(exact, int): + raise TypeError(f"{exact=} must be an integer.") + if exact < 0: + raise TypeError(f"{exact=} must be non-negative.") + + # Assignments self.current_time = 0.0 self.network = network self.set_classes(node_class, arrival_node_class, exit_node_class, individual_class, server_class)