20  An Introduction to Modelling Complex Real-World Systems

20.1 The Challenge Now…

As you begin to model your first real-world systems, you may find yourself uncertain of the best approach to take to a problem, and seeking out the ‘right’ way to do something.

While there are often rules of thumb and efficient or less efficient ways of doing things, there often isn’t a single answer to how you structure a solution.

The chapters that follow in this section will tend to give you an idea of how you might approach a situation, and some general rules of thumb to follow, but you should not be afraid of trying a different approach.

Tip

Part 5 will also be crucial for building your confidence in real-world systems, as it will help you to understand how you can build logging, testing and visualisation into various parts of your model to confirm that it is working in the way it should be.

20.2 What do I do if what I need isn’t covered in the book?

20.2.1 Check the SimPy Documentation

The SimPy documentation is a rich resource for information on how to do things.

https://simpy.readthedocs.io/en/latest/

It covers a range of things that we don’t yet touch on in the book, such as

  • interrupting processes
  • building custom events
  • waiting for any of or all events before triggering a process
  • additional resource types, such as containers and stores

20.2.2 Experiment!

There’s no harm in trying things out!

It may take a while and a few false starts to get things working as expected, but that’s entirely normal - if your code works first time, that would be quite unusual!

Make use of some of the debugging and logging tips to determine whether your approach is leading to events happening in the order expected and at the frequency expected.

If you’re having issues, check your indentation - this is a common thing to get wrong as your model gets more complex.

Make sure you have a clean working copy of your original code saved to go back to (ideally tracked via version control on a platform like GitHub!) and make notes of the different approaches you have tried - it’s very easy to accidentally circle back to a non-working solution.

Finally, don’t be afraid to step away from the code for a bit - you will often find that you will ruminate over the problem without even realising, and inspiration will strike when you least expect it.

20.2.3 Check out StackOverflow

StackOverflow is a long-running site where users post questions about coding problems.

Often, relevant StackOverflow questions will come up near the top of a Google search on coding topics.

You can also ask questions yourself, though try to include a very clear description of your aim, your difficulty, what you have already tried to solve the problem yourself, and a ‘reproducible example’ (reprex) that someone trying to answer your question can run themselves to get them started.

Warning

Take the time to understand any code that is presented on StackOverflow and thoroughly test it to ensure it’s doing what it says it’s doing.

20.2.4 Try Using General AI

Warning

All AI tools should be used with caution. They may give you wrong information, may suggest functions or functionality that doesn’t exist, and more. Take the time to understand any code that is generated by an AI tool and thoroughly test it to ensure it’s doing what it says it’s doing.

Important

Never upload any sensitive data to one of these tools. Data is processed on external servers, potentially in other countries, and you may be in serious breach of the information governance rules of your organisation.

AI chat assistants can be helpful coding buddies.

ChatGPT is often quite good at generating code and ideas, and can be used for free. Claude also gets good feedback for this purpose.

Perplexity is good as it links back to the key sources in its answer, allowing you to interrogate them further.

Tools built in to your coding environment, like Github Copilot and Intellicode in VSCode, can also be of use.

20.2.5 Try Using a Custom AI

For example, NotebookLM allows you to upload a series of custom resources, such as videos, websites and slides. Through this you could create an AI trained specifially on the HSMA lectures, this book, and the SimPy documentation, among other SimPy-specific sources.

Note

Note that if you are adding an ebook like this resource, or the documentation site of a library, you will need to add each page as a source individually, meaning you can quickly exceed the total number of sources allowed.

20.2.6 Check out the SimPy Issues on GitLab

The code for SimPy is hosted on GitLab.

You can take a look at previously raised issues to see if there is a known difficulty with what you are trying to do - it may be that what you are attempting to achieve is an actual limitation of the library.