CS 1 (Spring 2025) Project 05: Chemical Reaction Balancer

This project covers using custom types and linear algebra operations in Python.

Goals and Outcomes

Setup

Go to project registration to register for the project. Make sure to sign up for cs1-25sp projects on the left! Once you do, restart vscode and a folder with the starter code should automatically show up in your file browser.

Project Grading

As per the syllabus, to pass the class, you must earn a non-zero score on every project. However, you must also earn a total average of at least 75% cumulatively on the projects and quizzes.

How This Project Works

This project will be structured differently from the previous ones. Think of this as a “choose your own adventure” project, where you can choose which subset of functions you want to write that are outlined below. Each function is assigned a certain number of “stars” corresponding to their difficulty and ultimately their point value.

Your Development Cycle for This Project

Step 1: Choose a function to implement.

Look at the list of function choices and choose one to attempt to implement next.

Step 2: Uncomment that function in config.py.

Each time you write a function, you must uncomment the name of function in the file config.py. Keep all function names that you have not written as commented out!

Debugging tip: Isolate the the function you are working on by commenting out everything else in config.py. Please come to OH if you need more help!

The tests will automatically ONLY use your versions of the functions you have uncommented. It will use our reference solution for any commented/unimplemented functions. This also means that the functions you write can (and often will!) use a helper function that you have not written, and the tests will still work because they will pull those helper functions from our reference solution. This is why all your tests should always pass if the code you wrote is correct!

Step 3: Run score.py.

Before implementing a function. Run score.py by using the play button in the top right to see what your score would be with that function implemented correctly. Note that score.py does not check correctness; it only indicates your final score assuming you have passed all the tests (NOT just the ones for your implemented functions). We expect you to play around with choices until you reach your desired score. Since functions are worth different numbers of points, you should decide what to implement based on what you’re interested in. Additionally, there are “bonus” stars (i.e., points) for every category you’ve implemented at least one function in AND every category you’ve implemented every function in!

Step 4: Write the code!!!

You got this!

The Idea

We’ve seen in previous projects that CS can be useful in many other fields, including subjects in the rest of core!

You might have seen in Ch1a that balancing chemical equations can often be quite tedious. However, we can automate this process using linear algebra (specifically, gaussian elimination methods) to find coefficients of chemical compounds, and can also extend this to find limiting reagents and yields for various chemical equations.

It’s okay if you don’t know what all these words mean! We have provided guidance for each of the functions, and you are always encouraged to go to OH for any questions (short or long!).

What’s New?

To simplify the transition between chemistry and linear algebra, we have created some new useful chemistry and math types that will be used throughout the chemistry components of the project. In the drop-down definitions of each function, you will see the relevant chemistry and math types required, and some documentation to help understand them better. To see how they are implemented, take a look at the file chem_types.py in the support folder.

Just to be clear, while the tool you’re writing can be incredibly helpful in classes like Ch1a and Ma1b, we expect you to follow the Honor Code and use your best judgment if using it in any of these classes!

The Functions

There are no DUES for this project!