ENGG1811–Assignment 2: Biofuel Production – Simulation and Design

0 Comments

ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
Learning Objectives:
1. Applying programming to solve a simple engineering design problem
2. Writing a python program to simulate an engineering system
3. Applying a number of python features, which include array, vectorisation, built-in

functions and others
4. Applying good software engineering practices, which includes proper documentation,
program style.
Aaron Quigley, October, 2020
Deliverables: Submit by 17:00 on Friday 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 9am Wednesday of Week-11.
To Submit this assignment, go to the Submission page and click the link named
“Make Submission”.
GENERAL RULES
1. This assignment is weighted at 20%
2. You are reminded that work submitted for assessment must be your own. It’s OK
to discuss approaches to solutions with other students, and to get general help
from tutors or others, but you must write the python code yourself. Increasingly
sophisticated software is used to identify submissions that are unreasonably
similar, and marks will be reduced or removed in such cases.
3. The Student Code of Conduct sets out what the University expects from students
as members of the UNSW community. As well as the learning, teaching and
research environment, the University aims to provide an environment that enables
students to achieve their full potential and to provide an experience consistent
with the University’s values and guiding principles. A condition of enrolment is that
students inform themselves of the University’s rules and policies affecting them, &
conduct themselves accordingly. (see the course outline page with links).
4. You should also read the following page which describes your rights and
responsibilities in the CSE context: Essential Advice for CSE Students
Essential
The University views plagiarism very seriously. UNSW and CSE treat plagiarism as
academic misconduct, which means that it carries penalties as severe as being
excluded from further study at UNSW. [see: UNSW Plagiarism Procedure]
Resources Provided to you
There are a number of python files that you need to do this assignment. These files are
in assign2.zip. We introduce these supplied files, see the section on Supplied Files.
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
Introduction
In these days, with the worlds attention turned to viruses, infection and disease
transmission some people think that bacteria are harmful. In reality there are many
different types of bacteria in this world. Some bacteria are harmful to humans but some
bacteria help us (e.g. curdling milk) or in our bodies (e.g. our digestion) 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, given the marks allocated, you need to work alone.
Assignment overview
This assignment is design to imitate engineering design. You will see the following
elements:
1. (Simulation) Simulation of a biofuel production system with different design
parameters.
2. (Design) Evaluate the performance of the systems that you have simulated.
As noted on page 1, there are a number of files provided to get you started please see the
section on Supplied Files below for more details.
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.
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
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
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.
“One mechanism for dealing with toxicity is to export the fuel molecules using efflux
pumps. These pumps are protein complexes in the cell membrane that recognize toxic
substrates and expel them. Once a toxin is sensed, a channel in the membrane opens in
an iris-like fashion and the toxin is pushed out using the electrochemical gradient across
the cell membrane.” From, Dunlop, Mary J., Jay D. Keasling, and Aindrila Mukhopadhyay.
“A model for improving microbial biofuel production using a synthetic feedback loop.”
Systems and synthetic biology 4.2 (2010): 95-104.
Aaron Quigley, October, 2020
Figure 1: (a) Biofuel production using microbes (e.g. bacteria) to convert sugar into fuel.
(b) Efflux pumps can be used to export biofuel out of the cell (adapted from Dunlop 2010)
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
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 nonnegative
real number. We also call this internal biofuel.
• The amount of biofuel in the exterior of the bacteria, denoted by be, which is a nonnegative
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 in the appendix 1. We believe it is
best for you to understand what you need to do for this assignment first before exploring
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 mathematical model (in Appendix 1) 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: Simulate the biofuel production system with a python function
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
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
in this order of expected function output:
• 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 in Appendix 1 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
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
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. If you adjust the value of the
variable test_index, you can choose between 3 different set of design parameters.
Task 2: Generate 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:
1. 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).
2. 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.
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
3. 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.
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
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
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
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:
1. System parameters which are the constants you need for the mathematical
model in biofuel_system_parameter_sets.py.
2. Simulation and design parameters in
biofuel_simulation_design_parameter_sets.py.
• Files for testing
1. test_1 for testing Tasks 1.
2. test_2 for testing Tasks 2.
3. test_3 for testing Tasks 3.
4. These files require support files, which are set1_check.pickle and
set2_check.pickle files.
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
Getting Started
1. Download the zip file assign2.zip, and unzip it
2. Rename/move the directory (folder) you just created named ‘assign2’ to ‘ass2’. The
name is different to avoid possibly overwriting your work if you were to download
the ‘assign2.zip’ file again later.
3. First browse through all the files provided, and importantly read comments in the
files.
4. Do not try to implement too much at once, just one function at a time and test that it
is working before moving on.
5. Start implementing the first function, properly test it using the given testing file, and
once you are happy, move on to the the second function, and so on.
6. Please do not use ‘print’ or ‘input’ statements. We won’t be able to assess your
program properly if you do. Remember, all the required values are part of the
parameters, and your function needs to return the required answer. Do not ‘print’
your answers.
Testing
Test your functions thoroughly before submission. You can use the provided python
programs to test your functions.
Please note that the tests provided in these files cover only basic scenarios (cases), you
need to think about other possible cases, modify the files accordingly and test your
functions.
Submission
A complete submission should contain the following three files (as described above):
1. sim_biofuel.py
2. generate.py
3. design.py
The submission system will accept the above three filenames. You must not submit any
other files.
To Submit this assignment, go to the Submission page and click the tab named “Make
Submission”.
Assessment Criteria
We will test your program thoroughly and objectively. This assignment will be marked out
of 20 where 18 marks are for correctness and 2 marks are for style.
Correctness
The 18 marks for correctness are awarded according to these criteria.
Criteria Nominal marks
Task 1 (Function sim_biofuel) 6
Task 2 (Correct max_internal_biofuel and
final_external_biofuel) 6
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
Style
Two (2) marks are awarded by your tutor for style and complexity of your solution. The
style assessment includes the following, in no particular order:
• Use of meaningful variable names where applicable
• Use of sensible comments to explain what you’re doing
• Use of docstring for documentation to identify purpose, author, date, data dictionary,
parameters, return value(s) and program description at the top of the file
Assignment Originality
You are reminded that work submitted for assessment must be your own. It’s OK to
discuss approaches to solutions with other students, and to get help from tutors and
consultants, but you must write the python 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, but take specific
ones to Help Sessions.
• You can ask your tutor during your lab time any queries you may have regarding
this assignment.
• Keep an eye on the class webpage notice board for updates and responses.
Task 3 (Correct values of alpha_b and
alpha_p for the two designs). Reduced
maximum: 1.5
6
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
Appendix 1
Mathematical model for biofuel
The model consists of five ordinary differential equations:
Some helpful intuition for some of these equations at the end of the
appendix.
Note that for the purpose of simulation, there are three groups of
quantities:
1. Time dependent variables: n(t), p(t), R(t), bi(t) and be(t). These are
quantities that you want to use simulation to obtain.
2. Two design parameters: αb (python variable: alphaB) and αp
(python variable: alphaP). You will use different values of these two
parameters in simulation to see how they change the amount of fuel
produced internally and externally. Note that alphaB and alphaP
are two inputs to the simulation function that you need to write.
3. The rest of the parameters (αn, δn etc.) are constants. A mapping
between the mathematical symbols and their python constant names
is below. You will need to make use of these constants in your python
simulation code. Essentially, you replace the mathematical symbol
by its corresponding python name in your simulation code.
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
The next step is to apply Euler’s forward method to the ordinary
differential equations, which result in the following equations you need for
simulation.
Mapping between symbol names and python constant
names
The python constant names are in upper case. For most symbols, the first
part is the name of the Greek alphabet, followed by an underscore and then
the subscript. The values of these constants are defined in files with the
name that contains the words “biofuelSystemParameterSet”.
Aaron Quigley, October, 2020
ENGG1811 20T3 Assignment 2: Biofuel Production – Simulation and Design
Meaning behind the equations
Right-hand side (RHS) of (1) describes the rate of change in the amount of
bacteria. The first term is the logistic growth function taking into account
the limitation of resources. You can learn more on logistic growth from
this Wikipedia page (https://en.wikipedia.org/wiki/Logistic_function ). The
second term is the death rate of bacteria due to biofuel. The third term is
the death rate due to efflux pumps.
RHS of (3) is the rate of change in the number of efflux pumps. The first
term is a base production rate. The second term describes how biofuel in
the bacteria affects the production rate. Essentially, the more the biofuel
inside the bacteria, the higher the production rate. The last term is the
pump degradation rate.
RHS of (4) is the rate of production of biofuel in the interior of bacteria.
The first term says the production rate is proportional to the amount of
bacteria. The second term is the rate at which biofuel is pumped out of the
bacteria by efflux pumps.
RHS of (5) is the rate at which biofuel is pumped into the exterior.
Aaron Quigley, October, 2020

Leave a Reply

Your email address will not be published.