Skip to content

Commit

Permalink
tutorials: beautifuling
Browse files Browse the repository at this point in the history
  • Loading branch information
Peva Blanchard committed Jan 26, 2024
1 parent 6fece28 commit d74dc4e
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 97 deletions.
29 changes: 29 additions & 0 deletions tutorials/02-language-features/05-datasources/00-datasources.lca
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
A datasource is assumed to provide a sequence of records.
For now, only the local CSV file source is supported.
*/

datasource inventory {
/*
The location is relative to the path chosen when invoking the cli.
*/
location = "data/inventory.csv"

/*
The schema is defined using default values. Note that the unit of
the default value will be the one chosen for the entire column.
*/
schema {
quantity = 1 p
ram_size = 16 GB
storage_size = 1 TB
amortization_period = 5 year
power = 400 W
ram_allocation = 75 percent
storage_allocation = 25 percent

// embodied impact
GWP = 0 kg_CO2_Eq
WU = 0 m3
}
}
42 changes: 42 additions & 0 deletions tutorials/02-language-features/05-datasources/01-lookup.lca
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Lookup primitive
*/

process my_lookup {
products {
1 p material
}
variables {
/*
The lookup primitive fetches exactly one record matching
the given condition. Here, the chosen row is the one whose
value in the column 'id' equals the value "small".

If no record or more than one record is found, an error
is thrown.
*/
row = lookup inventory match id = "small"

/*
Individual entries of the record are accessed using
the dot syntax. Their dimensions is specified by
the data source schema.
*/

quantity = row.quantity
GWP = row.GWP
}

impacts {
quantity * GWP GWP
}
}

test my_lookup {
given {
1 p material from my_lookup
}
assert {
GWP between 38 p * 2800 kg_CO2_Eq and 38 p * 2900 kg_CO2_Eq
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*
A datasource is assumed to provide a sequence of records.
For now, only the local CSV file source is supported.
*/
datasource inventory {
location = "inventory.csv"

/*
The schema is defined using default values. Note that the unit of
the default value will be the one chosen for the entire column.
*/
schema {
quantity = 1 p
ram_size = 16 GB
storage_size = 1 TB
amortization_period = 5 year
power = 400 W
ram_allocation = 75 percent
storage_allocation = 25 percent

// embodied impact
GWP = 0 kg_CO2_Eq
WU = 0 m3
}
}

/*
Block 'for_each'
*/
Expand Down Expand Up @@ -78,7 +52,7 @@ process pool_server {
inputs {
for_each row from inventory {
// record variable can be fed to the process invoked.
row .quantity server from server(row = row)
row.quantity server from server(row = row)
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions tutorials/03-advanced/01-relational-modeling/01-main.lca
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
process datacenter {
params {
id = "dc-zone-01"
}
variables {
dc = lookup datacenters match id = id
total = dc.reserved_power * dc.amortization_period
}
products {
total energy
}
inputs {
// include electricity from the relevant geographic zone
total electricity from electricity_mix(geo = dc.geo)

// include all components belonging to the given datacenter
for_each row from datacenter_components match datacenter_id = dc .id {

// pass the component parameters
1 p component from datacenter_component(dc_component = row)
}
}
}

process datacenter_component {
params {
dc_component from datacenter_components
}
products {
1 p component
}
impacts {
dc_component.GWP GWP
}
}

process electricity_mix {
params {
geo = "GLO"
}
variables {
mix = lookup electricity_mixes match geo = geo
}
products {
1 kWh electricity
}
impacts {
mix.GWP GWP
}
}

test datacenter {
given {
1 kWh energy from datacenter(id = "dc-zone-01")
}
assert {
GWP between 70 g_CO2_Eq and 75 g_CO2_Eq
}
}
59 changes: 0 additions & 59 deletions tutorials/03-advanced/01-relational-modeling/main.lca

This file was deleted.

5 changes: 5 additions & 0 deletions tutorials/03-advanced/01-relational-modeling/units.lca
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unit g_CO2_Eq {
symbol = "g_CO2_Eq"
alias_for = 1e-3 kg_CO2_Eq
}

unit ton_CO2_Eq {
symbol = "ton_CO2_Eq"
alias_for = 1000 kg_CO2_Eq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ process cff {
}
}

test cff {
given {
1 kg material from cff
}
assert {
GWP between 1.38 kg_CO2_Eq and 1.4 kg_CO2_Eq
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ process end_of_life {
variables {
mat_params = lookup material_params match id = id

ErecyclingEol_id = mat_params .ErecyclingEol_id
EstarV_id = mat_params .EstarV_id
Eer_id = mat_params .Eer_id
Ed_id = mat_params .Ed_id
ErecyclingEol_id = mat_params.ErecyclingEol_id
EstarV_id = mat_params.EstarV_id
Eer_id = mat_params.Eer_id
Ed_id = mat_params.Ed_id

A = mat_params.A
B = mat_params.B
Q_out = mat_params.Q_out

R2_data = lookup R2_data match ( geo = geo, id = id )
R2 = R2_data .R2
R2 = R2_data.R2

R3 = mat_params .R3
R3 = mat_params.R3

LHV = mat_params .LHV
Xer_heat = mat_params .Xer_heat
Xer_elec = mat_params .Xer_elec
LHV = mat_params.LHV
Xer_heat = mat_params.Xer_heat
Xer_elec = mat_params.Xer_elec
}

inputs {
Expand Down
7 changes: 5 additions & 2 deletions tutorials/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ fi
lcaac test -p $TUTORIALS_PATH/01-basics/01-getting-started
lcaac test -p $TUTORIALS_PATH/01-basics/02-biosphere
lcaac test -p $TUTORIALS_PATH/01-basics/03-impacts

lcaac test -p $TUTORIALS_PATH/02-language-features/01-parametrized-process
lcaac test -p $TUTORIALS_PATH/02-language-features/02-variables
lcaac test -p $TUTORIALS_PATH/02-language-features/03-units
lcaac test -p $TUTORIALS_PATH/02-language-features/04-labels
lcaac test -p $TUTORIALS_PATH/02-language-features/05-datasources

lcaac test -p $TUTORIALS_PATH/03-advanced/01-relational-modeling
lcaac test -p $TUTORIALS_PATH/03-advanced/02-circular-footprint-formula

# Check custom dimensions tutorial
set -euo

# The following assessment is expected to fail.
if lcaac assess -p $TUTORIALS_PATH/02-language-features/03-units customer; then
exit 0
fi
fi 2> /dev/null

0 comments on commit d74dc4e

Please sign in to comment.