#019 - Why Engineers Should Learn Python
This is a call for engineers to learn Python, highlighting its benefits in automation, open-source capabilities, integration with engineering tools, and relevance in AI and future technologies.
The civil and structural engineering industry, a colossal field grounded in millennia of tradition, has its foundations for a reason. While it may not be my place to prescribe changes to such a well-established domain, I'll venture to do so regardless, in the spirit of a true keyboard warrior.
This article is the latest in a series aimed at illustrating why Python is a valuable resource for engineers looking to enhance their skill set and optimize their work.
The sections that follow offer a broad overview, focusing on the most accessible benefits of Python for engineers. While each topic warrants a detailed series of articles in its own right, I need to start somewhere. If you are curious and want to dig deeper into certain aspects, let it be known in the comments.
I know people want to see more examples and specific use cases for Python in engineering; if you dig through my post archive, there are a few. More case studies and examples are coming, but we will stay out of the weeds today.
Excel
I do not want to address Python vs Excel. In the modern age of social polarization, there is some sort of gravitational anomaly that pulls people into these endless mud-slinging debate wormholes. There are Excel power users out there who probably have a hit out on me. A few short notes without losing focus:
Yes, there is overlap.
Yes, Excel now features Python capability.
Yes, you can use Excel for many things. It is fantastic, effective and proven.
There is nothing wrong with Excel; it’s an incredibly powerful tool. I use it regularly.
Excel is not going anywhere. It is the backbone of the modern corporate world.
Many of the people who decide on your salary, bonuses and career love Excel.
The bottom line is that they are different tools. A husky and a chihuahua are both dogs, but you don’t see many chihuahas pulling sleds. Conversely, you don’t often see a husky in a handbag.
Choose the tool that fits your needs.
If you want to increase your technical reach as an engineer, enhance your skill set, broaden your perspective and prepare for a future that is already here, there is no question that you need to learn Python.
Python's Open-Source Advantage:
Python's open-source nature is, without a doubt, my favourite aspect. It offers unparalleled transparency, allowing anyone to see exactly how it functions.
Python is available at no cost and does not require a commercial license for use.
If you're new to the concept, open-source tools are software whose source code is freely available for anyone to view, modify, and distribute. This means you can see how the software works, make changes to it to fit your needs, and share it with others, fostering an environment of collaboration and continuous improvement. Open-source tools are often developed and maintained by a community of contributors, making them highly adaptable and often more secure due to the transparency and collective oversight.
This openness is Python's standout feature, especially in modern engineering, where we rely heavily on expensive, complex finite element modelling tools. Commercial tools are impressively powerful, enabling remarkable feats of analysis and design, yet they are not without flaws. Engineers often find themselves using two separate software packages to cross-check models, doubling costs and complexity. Even then, there's a lack of clarity about what happens behind the scenes, particularly regarding computation and system boundary conditions.
Many engineers have their own tale of a modelling disaster, and my experience is no exception. My team and I have spent days, sometimes weeks, agonizing over the "what ifs" of certain models. This is especially true when dealing with dynamics and nonlinearity. Frequently, technical support staff can't provide the help we need due to various reasons. Often, the provided documentation fails to address our specific scenarios. As most engineers know, every project is unique, with conditions and variables constantly changing and evolving.
This is where the incredible advantage of open-source tools shines. They are inherently transparent — every line of code is visible. If a particular line doesn't sit right with you, you have the power to propose a change through a pull request. This collaborative environment fosters continuous improvement, with the community working together to identify and resolve issues, unlike commercial software, which can't be customized for every unique use case.
Open-source tools evolve dynamically as their user base grows, learns, and adapts, continually enhancing the tools. This evolution is a testament to the power of community-driven development, contrasting sharply with the limitations inherent in commercial software.
An incredible example of this is the growth and evolution of QGIS, a fantastic open-source GIS tool that many readers are probably familiar with. Check out the time-lapse video below that shows the development activity and growth of QGIS over 20 years. More and more users, most of whom are unpaid volunteers solving their own specific problems, contribute to the core features and use cases of QGIS, catapulting its functionality far beyond its original scope.
QGIS is free to download and is used by geospatial professionals around the world. This is what it’s all about.
I want to see this type of community collaboration and crowd-sourced ingenuity for structural and civil engineering tools. That’s part of the Flocode mission. I will talk more about this soon.
Jupyter Notebooks - Collaborative and Interactive:
I'm a big fan of Jupyter Notebooks for their interactive and user-friendly approach to documentation. They're like a living document that combines calculation and analysis tools with a record of sources, references, methodologies, concepts, and ideas—all in one. Their ability to support rich text, images, links, and markdown formatting enhances readability. You can install any Python library or package to meet various scientific objectives, integrating tools like Microsoft Excel, AutoCAD, Revit, SAP2000, ANSYS, CSI Bridge, S-Frame, and GeoStudio, among others.
For a more detailed dive into Jupyter, check out my previous post.
#013 - Python Essentials | 01 - Jupyter Notebooks Part 1/3
What sets Jupyter notebooks apart is the division of content into individual cell blocks, which improves readability and functionality. As you progress through a design or concept, you can modularize your content, making each cell a standalone function or component of your design. Running notebook cells sequentially offers a programmatic method to update all inputs in real-time. Plus, you can interconnect different notebooks, allowing the reuse of functions or classes from other projects. This concept of combining different modules and blocks of code from your expanding code library is such a game-changer.
Collaboration is another key feature. Jupyter notebooks enable team members to share ideas and solutions interactively and dynamically. They offer a multitude of options in a single tool, unmatched by any other format. Google Colab and GitHub Codespaces are great examples.
I have a free Codespace here you can investigate.
Automation with Python:
Automation stands out as a key benefit of Python, yet ironically, it's a feature I use less often, given the diverse nature of my work in hydropower. Still, I leverage it to automate iterative tasks or calculation processes involving multiple steps, such as online actions in a web browser or entering data across various fields and dropdown lists in specific sequences.
Take, for instance, the ASCE 7 seismic hazard tool. I use automation via Selenium to process multiple locations or sites and extract seismic data. This data is fed into functions for calculating base shear or other project requirements. The real power of automation lies in combining tools like Selenium, which accesses the internet, with desktop automation, managing inputs and outputs of the more robust tools and commercially sensitive data sources I use regularly.
For a deeper dive into automation with examples, check out my last article:
#018 - Automation for Civil/Structural Engineers | Selenium
Tasks as simple as renaming files in a folder or as complex as extracting information from a PDF, processing it through Excel, Python, SAP2000, and then back to Python and into a report are all automatable. This saves tremendous effort in redoing complex analyses and paves the way for a parametric design approach. This approach transcends the confines of a single commercial software, bridging multiple software platforms. This integration offers insights and data to other disciplines or team members who would otherwise be engaged in lengthy, cumbersome data processing tasks.
Automation significantly boosts my productivity, but its practical benefits extend beyond that. It enables the swift and reliable transfer of information to other team members and disciplines. In engineering, where goals and parameters frequently shift, automation offers the agility to adjust and provide revised information as needed.
Interestingly, a serendipitous side effect of automation is the unintentional improvement in my thought process. It sharpens my control logic, bringing clarity to various processes. Like mastering any skill, gaining fluency in automation enhances your ability to tackle a wide range of engineering challenges. This mindset of thinking in terms of automation transcends its immediate applications, adding a unique and valuable dimension to my overall engineering perspective.
It’s a strange thing to articulate, but programming has improved my ability to create mental models for how different engineering problems can be solved. As I gain experience, these models become more efficient, flexible and refined.
Python: The Language at the Heart of AI:
Artificial Intelligence has dominated discussions as the standout buzzword in the past year and a half. We are now white-knuckling through the next great epochal shift in the tech sector.
This change is driven by groundbreaking advancements from major players like OpenAI, Meta, and Google. Their tools are incredibly powerful, and I find immense value in them. However, the current hype around AI reminds me of the crypto craze back in 2021 and the NFT frenzy, which both took a significant nosedive. The next Bitcoin halving is coming in April 2024; we might see a big jump! Will you be remortgaging the house like me? Only havin’ a laugh, I can’t afford a house.
Recently, at the World Economic Forum, it was noted that AI will impact 60% of jobs in advanced economies.
"Your job may disappear altogether - not good - or artificial intelligence may enhance your job, so you actually will be more productive and your income level may go up," International Monetary Fund (IMF) Managing Director Kristalina Georgieva.
A profound insight. So, I either lose my job or increase my income.
AI has arrived—it's commercialized, mainstream, and accessible, achieving remarkable feats today. While many AI tools, like large language models and computer vision technologies, have relatively simple, user-friendly interfaces that don't require a programming background, the advantage of having even a basic understanding of Python is immense. Learning Python's basics opens doors to a whole new realm of possibilities.
It's hard to convey the impact of this realization until you experience it. Once you grasp Python's basic syntax and see its broad applicability to virtually any type of computer programming, the epiphany is profound. It's like learning a new language or skill that completely shifts your perspective. Suddenly, you're empowered to create new tools, control hardware, develop new interactive software, manipulate existing tools, and unlock insights from data that were previously inconceivable.
This is just the beginning, even before leveraging AI to scale your impact. As I continue to explore and learn, the use cases for AI in my work keep expanding.
Blending AI into engineering work is no small task and carries tremendous risk in our profession. Those who learn the basics of Python and some of the foundational principles of the architecture of AI platforms will be best positioned to leverage these solutions as more and more tools become available.
"He who controls the spice controls the universe." - Frank Herbert, Dune
This is the long game for Flocode. I am building a global community of engineers that will grow and develop alongside this technology. Change is not coming; it’s already here.
Closing
I touched on the most obvious benefits of Python today, but the real efficiencies are in the broad variety of workflows and the details of technical work. It’s a challenge to create engineering examples that appeal broadly to engineers without alienating most, but I am working on it. As always, your feedback is highly valued and helps drive this project forward.
I have some exciting news coming soon on the Flocode Beta Program. Newsletter subscribers will be notified so hang tight.
If you are interested in learning more about Python for civil and structural engineering, you can check out the growing newsletter post archive or visit flocode.dev.
See you in the next one.
James 🌊