ENGG1811 Assignment 2: Simulation and Design of Biofuel Production
ENGG1811 Assignment 2: Simulation and Design of Biofuel Production (draft)
Due date: 11pm, Friday Sunday of Week-10 .
Late Penalty: Late submissions will be penalised at the rate of 10% per day (including weekends). The penalty applies to the maximum available mark. For example, if you submit 2 days late, maximum available marks is 80% of the assignment marks. Submissions will not be accepted after 11pm Tuesday of Week-11.
Change log :
Submission system is now available. To Submit this assignment, go to the Submission page and click the tab named "Make Submission".
09pm Thursday 11 April: Deadline is now extended to 11pm Sunday (ealier it was Friday) of Week-10
09pm Thursday 11 April: There was typo in the file "test_3.py" at line 82,
replace ", best_alpha_b: " by ", best_alpha_p: ". The values printed were correct, just the message had typo!
You can download the revised test_3.py (click right mouse and select "save as" or similar)
Introduction
We often think bacteria are bad. The truth is that there are many different types of bacteria in this world. Some bacteria are harmful to humans but some bacteria in our bodies help us to live. Have you ever considered the possibility that bacteria can also be "factory workers"? Engineers and scientists are working on using bacteria to produce certain chemicals and materials. An example is to use bacteria to produce fuel for us. In engineering, we often want to optimise the process, so we may want to make the bacteria to produce as much fuel as possible in a given time. However, there are often constraints in nature. The truth is that fuel is toxic to bacteria, so we need to find a way for the bacteria to make a lot of fuel but at the same time keep them alive! This biofuel production process is the theme of this assignment.
The aim of this assignment is to give you an opportunity to work on a small-scale engineering design problem in python. The engineering system that you will be working on is biofuel production. Your goal is to determine the design parameters so that the bacteria can produce as much fuel as possible while respecting a couple of constraints. You will use simulation as part of the design process.
For this assignment, you need to work in a group of two with the restriction that your group partner must come from the same lab class (i.e. same lab time slot and lab room). If you want to work on your own, please check with your tutor.
Learning objectives
This assignment is designed to give you practice in
Applying programming to solve a simple engineering design problem
Writing a python program to simulate an engineering system
Applying a number of python features, which include array, vectorisation, built-in functions and others
Applying good software engineering practices, which includes proper documentation, program style
Assignment overview
This assignment is design to imitate engineering design. You will see the following elements:
(Simulation) Simulation of a biofuel production system with different design parameters.
(Design) Evaluate the performance of the systems that you have simulated.
Download files: There are a number of python files that you need to do this assignment. These files are in assign2.zip. We will first talk about the tasks involved, and later introduce these supplied files, see Supplied Files for more.
We will first give an introduction to biofuel production. This introduction is meant to give you some intuition on the design problem. After that we will tell you what you need to do for the assignment.
Biofuel production process
We will give you a basic mental picture that you can use to visualise biofuel production. A pictorial representation of a bacterium is in Figure 1. A bacterium is a single-cell organism. It has a cell membrane, which you can think about as the "skin" of a bacterium. By using bioengineering, we can get the bacteria to produce fuel for us. This production will take place within the bacteria, i.e. inside the cell membrane of the bacteria.
Figure 1. A pictorial depiction of the main elements of a bacterium for biofuel production.
Now that you know that fuel is produced inside the membrane of bacteria, the next thing you need to know is that having the fuel staying inside the bacteria is neither good for us nor the bacteria. It is not good for us because we cannot collect the fuel. It is not good for the bacteria because it is toxic to them. This means we need a way to get the fuel from the inside of the membrane to the outside. A good news is that bacteria can make efflux pumps on the membrane to push the fuel from the inside of the membrane to the outside.
With these efflux pumps, we can reduce the amount of fuel in the bacteria (i.e. toxicity level) and collect the fuel, solving the problem that we talked about in the last paragraph, but there is one catch. Efflux pumps, though useful, can be a burden to the bacteria. This means that a bacterium should not have too many efflux pumps. A clever way is to get the bacteria to make efflux pumps on demand. If a bacterium senses that there is a lot of fuel inside its membrane, it should make more efflux pumps to expel the fuel; and vice versa. With the help of bioengineering, it is possible to have biosensors in bacteria to sense the amount of fuel in the bacteria.
The above mental picture should give you the intuition you need for the biofuel production process. In order to do engineering design, we need a mathematical model which we will discuss next.
A mathematical model for the biofuel production process
From the biofuel production description that we have discussed above, you know that we are interested in a few quantities: the amount of biofuel inside the bacteria because this is related to the toxicity level; and, the amount of biofuel outside the bacteria because this is the amount that we can collect. We would like to have a mathematical model which tells us how these two quantities vary over time. The mathematical model can tell us how the following five quantities vary over time:
The amount of bacteria in the colony denoted by the mathematical symbol n. Note that we scale the amount by the maximum possible of bacteria so n is a number in the interval [0,1].
The biosensor output denoted by R which is a non-negative real number.
The amount of efflux pumps, denoted by p, which is a non-negative real number.
The amount of biofuel in the interior of the bacteria, denoted by bi, which is a non-negative real number. We also call this internal biofuel.
The amount of biofuel in the exterior of the bacteria, denoted by be, which is a non-negative real number. We also call this external biofuel.
You will use simulation to determine these five quantities.
There are two design parameters which we will vary, they are:
The biofuel production rate αb. (python variable name alpha_b)
The efflux pump production rate αp. (python variable name alpha_p)
We have placed the mathematical model for the biofuel on a separate page. We believe it is best for you to understand what you need to do for this assignment first before dwelling into the mathematical model. You should be able to understand what you need to do for the assignment without going into the mathematical model at this stage. (The model is here and you can read it later.) The mathematical model for biofuel production is based on Reference [1].
Overview of tasks
We have divided the work into a number of tasks.
Task 1 and Task 2: are on simulation
Task 3: is on engineering design
Task 1: A python function to simulate the biofuel production system
The aim of this task is to write a python function sim_biofuel (which should be in a file with name sim_biofuel.py) to simulate the biofuel production process. You can find a template for this function in sim_biofuel_template.py (in assign2.zip). You should rename it as sim_biofuel.py before you start. The declaration of the function sim_biofuel is:
def sim_biofuel(data_set_to_use, time_array, init_bacteria_amount, alpha_b, alpha_p) :
The above function returns five arrays. All these five arrays should have the same length as the input array arrayTime. These five arrays contain the following simulation outputs:
bacteria_amount_array for the amount of bacteria n
sensor_array for the biosensor output denoted by R
pump_array for the amount of efflux pumps p
biofuel_int_array for the amount of biofuel in the interior of the bacteria bi,
biofuel_ext_array for the amount of biofuel in the exterior of the bacteria be,
The inputs are:
data_set_to_use is an integer indicating data set to use containing constants you need for simulation.
time_array is a array of time instances that you need for simulation.
init_bacteria_amount is a scalar for the initial amount of bacteria in the colony.
alpha_b is a scalar for the design parameter for biofuel production rate αb
alpha_p is a scalar for the design parameter efflux pump production rate αp
The implementation of sim_biofuel requires the mathematical model for the biofuel production process. (The model is here and the suggestion is that you read the model later.)
Hint: You can use the python simulation program para_ODE_ext_lib.py and para_speed_height_by_ODE.py (code from Week 7's lecture) or the material from "Lab 08: Simulation and its applications" as a starting point to develop the function sim_biofuel.
The only non-zero initial condition is the amount of bacteria. This is defined by the constant INITIAL_BACTERIA_AMOUNT, which is specified in the simulation data set. The python files provided for testing load this constant in for you, so you can assume this constant is available and use it. You can assume the initial conditions for R, p, bi and be are zero.
The array time_array is a uniformly spaced array of time instances. The start and end times, as well as time increments, are specified in the simulation data set. The python files provided for testing your function load these constants in for you, as well as define the array time_array. So, you can assume the time array is available and use it.
When you call the function sim_biofuel, the only inputs that you need to adjust are the values of alpha_b and alpha_p. For example, if you want to do simulation with αb = 0.1 and αp = 0.6, you should use:
def sim_biofuel(data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, 0.1, 0.6) :
Note that you can leave the first three inputs (shown in red) as they are shown in the above line. You may want to read through the file test_1.py to give you an example on how to call the function.
You can use the python program test_1.py (in assign2.zip) to test your sim_biofuel. The program test_1.py first reads in the constants and parameters for the selected data set. It then creates an equally spaced array time_array. The program then calls the function sim_biofuel to compute the five outputs of the simulation, and compares them to the reference values. If you see the error is small, i.e. less than 10-6, then your sim_biofuel should be working correctly.
Note that we have provided two different sets of system and simulation parameters. You can choose between them by assigning the variable data_set_to_use to either 1 or 2. You can find this variable near the beginning of the file. For each system parameter set, you can use three different pairs of design parameters in test_1 to test your data_set_to_use. The selection is done by setting the variable test_index to 1, 2 or 3.
You can test this function by using the script test_1. The lines for testing this function is commented out initially. You need to remove the # sign in order to get the testing going. If you adjust the value of the variable test_index, you can choose between 3 different set of design parameters.
Task 2: Calculating the design objective and constraints for many pairs of (alpha_b, alpha_p)
We have mentioned earlier that biofuel is toxic to the bacteria. It would be desirable if we can choose our design parameters αb and αp to limit the maximum amount of biofuel inside the bacteria. This is one design constraint that we want to impose. For our design, we would like to find design parameters which limit the maximum amount of internal biofuel. We want to do this quantitatively. Let us assume that you have done the simulation and have the amount of internal fuel stored in the array biofuel_int_array. The maximum amount of internal biofuel is then the maximum value in the array for biofuel_int_array.
You have seen that different values of αb and αp can lead to different behaviour of internal biofuel level. In the same way, different values αb and αp can lead to different amount of fuel that we can collect. Our design objective is to collect as much fuel as possible at the end of the production process. We can measure this design objective quantitatively by using the value of the last element of the array biofuel_ext_array, which represents the amount of external biofuel at the end time of the simulation.
In this task, you will use many different pairs of (alpha_b, alpha_p) for simulation. For each pair of (alpha_b, alpha_p), you will simulate the biofuel production and use the output of the simulation to determine: (1) The amount of biofuel you can collect and (2) The maximum amount of internal biofuel.
The steps for this task are:
Create an array of alpha_p_array of equally spaced αp values. The first value is ALPHA_P_LOWER and the last value is ALPHA_P_UPPER with an increment of ALPHA_P_STEP. These three constants are specified in a parameter set that the program test_2.py reads in. You can use them directly.
Hint: Note that the program test_2.py has a line which creates an equally spaced array time_array. You can similarly create an array equally spaced alpha_p_array using the above three values (lower, upper and step values).
Create two zero arrays whose number of rows is the number of elements in alpha_b_array and the number of columns is the number of elements in alpha_p_array. You should call these two arrays max_internal_biofuel and final_external_biofuel.
Perform simulations for all possible pairs of (alpha_b, alpha_p) where alpha_b comes from the elements in alpha_b_array and alpha_p comes from the elements of alpha_p_array. For each pair of (alpha_b, alpha_p), we need to do the following:
The (i,j) element of the array max_internal_biofuel, i.e. max_internal_biofuel(i,j), should be assigned the maximum amount of internal biofuel when alpha_b_array(i) and alpha_p_array(j) are used.
For example,
The (i,j) element of the array final_external_biofuel, i.e. final_external_biofuel(i,j), should be assigned the amount of biofuel that can be collected when alpha_b_array(i) and alpha_p_array(j) are used. This array final_external_biofuel will be similar to the above example for max_internal_biofuel.
Hint: please read the examples in the file numpy_2d_examples.py
In this part you need to implement the following function:
def generate(data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, alpha_b_array, ALPHA_P_LOWER, ALPHA_P_UPPER, ALPHA_P_STEP) :
Input (7 values):
data_set_to_use, time_array,
INITIAL_BACTERIA_AMOUNT, alpha_b_array,
ALPHA_P_LOWER, ALPHA_P_UPPER, ALPHA_P_STEP
Output (4 values):
alpha_b_array, alpha_p_array,
max_internal_biofuel, final_external_biofuel
You can use the file test_2.py to check whether you have calculated the two arrays max_internal_biofuel and final_external_biofuel correctly.
Task 3: Engineering design
The engineering design problem is to choose good design parameters to meet our design requirements. In our case, a design has two design parameters alpha_b and alpha_p. In Task 2, you have associated each design, or each pair of (alpha_b, alpha_p), with two quantitative measures:
Amount of biofuel that can be collected
Maximum amount of internal biofuel
We want to choose the best pair of (alpha_b, alpha_p) based on these two quantitative measures. We know that large amount of internal biofuel is undesirable. What we want to do is to impose an upper limit on maximum amount of internal biofuel. We introduce the following threshold:
THRESHOLD_MAX_INTERNAL_FUEL is a threshold on the maximum amount of internal biofuel
The above constant is specified in a parameter set that the program test_3.py reads in. We say that a design is acceptable if
Maximum amount of internal biofuel is less than or equal to THRESHOLD_MAX_INTERNAL_FUEL,
Out of all the designs that are acceptable, we will choose the design that allows us to collect the largest amount of biofuel. We will call this design the best design.
For comparison purpose, we will also determine a poor design which we define as the design that maximises the amount of biofuel that can be collected, without considering the above constraint.
Once you have obtained the best design and the poor design, you need to return these four values from the following function you need to implement for his part.
A requirement for Task 3 is that you should complete this task without using any loops. You can only get full marks if your solution does not use loops. If your solution requires loops, then you can only get a reduced mark.
Hint: You can easily implement this function WITHOUT using a loop structure. Please read (or re-read!) lecture notes and labs on numpy, and also the related code examples. In particular, look for numpy functions that may help you to solve problems related to Task-3.
In this part, you need to implement the following function:
def design( THRESHOLD_MAX_INTERNAL_FUEL,
alpha_b_array, alpha_p_array,
max_internal_biofuel, final_external_biofuel) :
Output (return values):
best_alpha_b, best_alpha_p, poor_alpha_b, poor_alpha_p
You should be able to determine whether your answers are correct by manually checking on the elements of the arrays. You can do that. The arrays are big so you may want to come out with some smaller arrays yourselves to test your work. We strongly encourage you to do that because it is always good to try to check your own work. When you go out to work, you will need to check your own work. We have also placed the answers here but we encourage you to check your own work before looking at them.
Remark: We have used exhaustive search here to determine the design parameters. This is certainly not the most efficient algorithm but you will learn better optimization methods in later years.
Style
You should make sure that all your files are properly documented with appropriate comments. Variables that you use should have well chosen names and their meaning explained. Appropriate style should be used.
Supplied Files
The supplied files are (in assign2.zip):
The file sim_biofuel_template.py is for Task 1. You should rename it as sim_biofuel.py
The file generate_template.py is for Task 2. You should rename it as generate.py
The file design_template.py is for Task 3. You should rename it as design.py
We have two sets of parameters. You can choose between the two sets of parameters by using the variables data_set_to_use. Each set of parameters is made up of constants in two files:
System parameters which are the constants you need for the mathematical model in biofuel_system_parameter_sets.py.
Simulation and design parameters in biofuel_simulation_design_parameter_sets.py.
Files for testing
test_1 for testing Tasks 1.
test_2 for testing Tasks 2.
test_3 for testing Tasks 3.
These files require support files, which are set1_check.pickle and set2_check.pickle files.
Assessment
The following table shows the maximum possible marks for the tasks. Note that, for Task 3, you can only get full marks if your solution does not use any loops; otherwise, a reduced mark will apply.
Marks Feature/Assessable Item
6 Task 1 (Function sim_biofuel)
6 Task 2 (Correct max_internal_biofuel and final_external_biofuel)
6 Task 3 (Correct values of alpha_b and alpha_p for the two designs). Reduced maximum: 1.5
2 Style, complexity, etc. (Comments; Variable definitions; Style; Complexity)
20 Total mark (rescaled to 10% of overall assessment)
Submission
A complete submission should contain the following three files (as described above):
sim_biofuel.py
generate.py
design.py
The submission system will accept the above three filenames. You must not submit any other files.
Submission system is now available. To Submit this assignment, go to the Submission page and click the tab named "Make Submission".
Originality of Assignments
As with all material submitted for assessment, this must be substantially your own registered group's work. It's OK to discuss approaches to solutions with other students, and to get help from tutors and consultants, but you must write the Basic code yourself. Sophisticated software is used to identify submissions that are unreasonably similar, and marks will be reduced or removed in such cases.
Further Information
Use the forum to ask general questions about the assignment, and keep an eye on it for updates and responses.
Reference
[1] M.E. Harrison and M.J. Dunlop. Synthetic feedback loop model for increasing microbial biofuel production using a biosensor. Frontiers in Microbiology, Oct 2012.