-
Notifications
You must be signed in to change notification settings - Fork 0
Simple Optimization Example
This example assumes that you have Cyclus
and Cycamore installed locally. You will
also need to install the pswarmdriver
command from the cloudlus
repository. The installation instructions for on the cloudlus repository
readme should install it (in addition
to the other cloudlus tools).
There are 2 files needed in order to perform a Cyclus deployment optimization:
-
templated Cyclus input file: This file is a mostly normal Cyclus input
file containing all the details of the facilities, etc. that you want in the
fuel cycle scenario. A sample templated input file can be found
here.
The only required difference from a normal input file is that, instead of
listing deployment for facilities, you will have a special placeholder with
a
:cycamore:DeployInst
that looks roughly like this:
...
<prototype>
<name>optim_deployer</name>
<config>
<DeployInst>
<prototypes>{{range .Builds}}
<val>{{.Proto}}</val>{{end}}
</prototypes>
<build_times>{{range .Builds}}
<val>{{.Time}}</val>{{end}}
</build_times>
<n_build>{{range .Builds}}
<val>{{.N}}</val>{{end}}
</n_build>
<lifetimes>{{range .Builds}}
<val>{{.Lifetime}}</val>{{end}}
</lifetimes>
</DeployInst>
</config>
</prototype>
...
- scenario configuration file: This is a JSON formatted file that defines prototypes available for construction (i.e. optimizer variables), constraints such as availability dates for prototypes, initial facility conditions, etc. A sample scenario configuration file can be found here.
Details about these files can be found on the ScenarioSpecification page. The scenario configuration file has a lot of parameters that control both simulation details and control over the optimization. Some of the parameters must be set consistent with the templated input file. These include:
-
SimDur
: The simulation duration. -
CyclusTmpl
: The name of the templated Cyclus input file. -
Facs
: A list of facility types (i.e. prototypes) - any Life/Cap parameters must must match corresponding prototype lifetimes and capacities in the Cyclus input file.
The BuildPeriod
sets how often new facility deployments can be made (e.g.
every 24 months) allowing control of the optimization granularity and number
of (input) variables. StartBuilds
allows the specification of static
facility builds (i.e. not part of the optimization variables). And finally
MinPower
and MaxPower
define a capacity curve in terms of the Facs
Cap
values that the constrain deployment schedules the optimizer is
allowed to choose. This allows users to define upper and lower bounds for any
arbitrary capacity curve over time. Each entry in each of the two series'
represents the min or max capacity that must be deployed/active at each
deployment period. A 1200 month simulation with a 24 month build period must
have 50 entries in each of these series'.
Assuming you have downloaded the sample Cyclus input file and scenario configuration file (or created/modified your own) do the following inside the same directory as the just mentioned files:
$ pswarmdriver -scen scenario.json -npar 60 > optim.log
This will start an optimization run on your local machine with 60 particles (i.e. 60 simulations per iteration), running hundreds of Cyclus simulations in several optimizer iterations. The particular objective function selected in our scenario configuration file rewards fast reactor energy and penalizes light water reactor energy effectively driving toward a fast transition to fast reactors. If you run out of patience, you can kill the optimization any time.
Details of all data/artifacts produced by the optimization run are explained
on the AnalyzingResults page. We redirected the pswarmdriver
command's output into the optim.log
file. This file contains the best
solutions found by each optimizer iteration - the input variable values that
describe the deployment schedule along with each corresponding objective
value. We can plot the best discovered objective value as a function of
optimizer iteration using this data by doing something like this on the
command line:
$ grep 'Iter' optim.log | sed 's/Iter \([0-9]\+\).* = \(.*\)/\1 \2/' | gnuplot -p -e 'plot "-" u 1:2 w lp'
(assuming gnuplot, sed, and grep are on your system of course). It might look something like this:
And then you might want to see what the best deployment schedule actually is.
To do that, you can use the cycobj
tool that should have been installed
when you installed the other cloudlus tools. We need to convert the best
discovered variable values (i.e. the last ones given in optim.log
) into
the actual deployment schedule using the scenario details:
$ grep ' = ' optim.log | tail -n1 | sed 's/.*\[\(.*\)\].*/\1/' | xargs cycobj -scen scenario.json -transform
Prototype BuildTime Lifetime Number
slow_reactor 1 192 1
slow_reactor 1 204 1
slow_reactor 1 216 1
slow_reactor 1 228 1
slow_reactor 1 240 1
slow_reactor 1 252 1
slow_reactor 1 264 1
slow_reactor 1 276 1
slow_reactor 1 288 1
slow_reactor 1 300 1
slow_reactor 1 552 1
slow_reactor 1 564 1
slow_reactor 1 576 1
slow_reactor 1 588 1
slow_reactor 1 600 1
slow_reactor 1 612 1
slow_reactor 1 624 1
slow_reactor 1 636 1
slow_reactor 1 648 1
slow_reactor 1 660 1
slow_reactor 1 720 3
slow_reactor 49 720 1
fast_reactor 121 720 3
fast_reactor 145 720 1
fast_reactor 169 720 1
fast_reactor 193 720 2
fast_reactor 217 720 8
fast_reactor 241 720 4
...
Note that these deployments include the static ones specified in the scenario configuration file too. If you want to run the simulation scenario using those deployments, you can use the cycobj command again:
$ grep ' = ' optim.log | tail -n1 | sed 's/.*\[\(.*\)\].*/\1/' | xargs cycobj -scen scenario.json
:
.CL:CC CC _Q _Q _Q_Q _Q _Q _Q
CC;CCCCCCCC:C; /_\) /_\)/_/\\) /_\) /_\) /_\)
CCCCCCCCCCCCCl __O|/O___O|/O_OO|/O__O|/O__O|/O____________O|/O__
CCCCCCf iCCCLCC /////////////////////////////////////////////////
iCCCt ;;;;;. CCCC
CCCC ;;;;;;;;;. CClL. c
CCCC ,;; ;;: CCCC ; : CCCCi
CCC ;; ;; CC ;;: CCC` `C;
lCCC ;; CCCC ;;;: :CC .;;. C; ; : ; :;;
CCCC ;. CCCC ;;;, CC ; ; Ci ; : ; : ;
iCC :; CC ;;;, ;C ; CC ; : ; .
CCCi ;; CCC ;;;. .C ; tf ; : ; ;.
CCC ;; CCC ;;;;;;; fC : lC ; : ; ;:
iCf ;; CC :;;: tC ; CC ; : ; ;
fCCC :; LCCf ;;;: LC :. ,: C ; ; ; ; ;
CCCC ;; CCCC ;;;: CCi `;;` CC. ;;;; :;.;. ; ,;
...
...
...
Status: Cyclus run successful!
Output location: ffa4316f-eb1b-4dd0-8b6e-f055c67df14d.sqlite
Simulation ID: 51e7c73c-2d8b-47ee-92f2-4b3b054e02b6
0.254375708458661
It will run the simulation with the (best) deployments creating a normal
Cyclus database that can be queried and analyzed in all the normal ways (named
ffa4316f-eb1b-4dd0-8b6e-f055c67df14d.sqlite
here). It also prints out the
objective value associated with that simulation and deployment schedule
(0.254...
here).