Skip to content

Commit 6a01ad4

Browse files
authored
Type annotation and validation of exact in simulation.py
- Add type annotation for `exact`. - Add input validation for `exact`. - Add short explanation in docstring.
1 parent cd544c8 commit 6a01ad4

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

ciw/simulation.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Simulation(object):
2121
def __init__(
2222
self,
2323
network,
24-
exact=False,
24+
exact: int = 0,
2525
name="Simulation",
2626
tracker=None,
2727
deadlock_detector=None,
@@ -32,8 +32,20 @@ def __init__(
3232
server_class=None,
3333
):
3434
"""
35-
Initialise an instance of the simualation.
35+
Initialise an instance of the simulation.
36+
37+
This class supports exact arithmetic when `exact` is given a positive integer
38+
representing the desired numerical precision. A precision of `0` is interpreted
39+
to mean using ordinary float precision.
3640
"""
41+
42+
# Input validation
43+
if not isinstance(exact, int):
44+
raise TypeError(f"{exact=} must be an integer.")
45+
if exact < 0:
46+
raise TypeError(f"{exact=} must be non-negative.")
47+
48+
# Assignments
3749
self.current_time = 0.0
3850
self.network = network
3951
self.set_classes(node_class, arrival_node_class, exit_node_class, individual_class, server_class)

0 commit comments

Comments
 (0)