Labels

This section introduces the process labeling feature. But let's start with a short example to motivate its purpose.

Motivating example

Imagine that you want to model the electricity mix for two different countries: say, Switzerland and France.

With what you have learned so far, you could right

process electricity_production_switzerland {
    products {
        1 kWh electricity
    }
    // ... the Swiss model here
}

process electricity_production_france {
    products {
        1 kWh electricity
    }
    // ... the French model here
}

Now, imagine that you want to model a electric vehicle (EV). The actual EV is the same all countries in Europe, and the only difference lies in the electricity mix used by the EV. How would you write that?

process electric_vehicle_switzerland {
    products {
       1 person * km transport
    }
    // ... some formula here
    inputs {
       q_elec electricity from electricity_production_switzerland
    }
}

process electric_vehicle_france {
    products {
       1 person * km transport
    }
    // ... the exact same formula
    inputs {
       q_elec electricity from electricity_production_france
    }
}

This is clear instance of code duplication! With this approach, one would need to copy-paste essentially the same process for every country in Europe.

We would like to parametrize the country.

process electric_vehicle {
   params {
      country = "switzerland" // or "france"
   }
   products {
       1 person * km transport
   }
   // ... some formula here
   inputs {
      q_elec electricity from // ??? 
   }
}

Now how can we express the fact that the electricity should be that of Switzerland when country matches switzerland, and that of France when it matches france?

Labels

Labels are introduced exactly for this situation. The idea is to write two models for electricity, with the same name, but labelled differently.

process electricity_production {
    labels {
       geo = "switzerland"
    }
    products {
        1 kWh electricity
    }
    // ... the Swiss model here
}

process electricity_production {
    labels {
       geo = "france"
    }
    products {
        1 kWh electricity
    }
    // ... the French model here
}

Now one can connect to the appropriate process by matching the parameter with the label.

process electric_vehicle {
   params {
      country = "switzerland" // or "france"
   }
   products {
       1 person * km transport
   }
   // ... some formula here
   inputs {
      q_elec electricity from electricity_production match (geo = country)
   }
}

When assessing the process electric_vehicle, the appropriate electricity production process will be selected based on the value on the value of the parameter country.