Skip to content

Commit 23e37d9

Browse files
committed
Fix #8
1 parent 5499ab9 commit 23e37d9

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ You don't need to use library for substitution, that already works natively in B
5959

6060
There is currently no built-in functionality to determine if an edge is functional based on its attributes - instead we rely on the label `functional` being manually specified. You can write a function to iterate over datasets and label the functional edges in whatever fashion you choose.
6161

62+
### Specifying `code` values for allocated products
63+
64+
When writing a multifunctional process, we need to create artificial edges to allocated processes which don't exist yet. You can't therefore specify the `code` of such an edge - but you can tell the system what code the allocated process *should have* upon allocation using the `desired_code` edge attribute. See `dev/basic_example.ipynb` for a simple example.
65+
6266
### Built-in allocation functions
6367

6468
`multifunctional` includes the following built-in property-based allocation functions:

multifunctional/allocation.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def generic_allocation(
5858
del exc["code"]
5959

6060
try:
61-
process_code = exc["mf_allocated_process_code"]
61+
if "desired_code" in exc:
62+
process_code = exc["desired_code"]
63+
else:
64+
process_code = exc["mf_allocated_process_code"]
6265
except KeyError:
6366
process_code = exc["mf_allocated_process_code"] = uuid4().hex
6467
change = True

tests/fixtures/basic.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{
1616
"functional": True,
1717
"type": "production",
18+
"desired_code": "my favorite code",
1819
"name": "first product - 1",
1920
"unit": "kg",
2021
"amount": 4,

tests/test_allocation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def check_basic_allocation_results(factor_1, factor_2, database):
3838
assert nodes[2][key] == value
3939

4040
expected = {
41-
"input": nodes[2].key,
42-
"output": nodes[2].key,
41+
"input": ("basic", "my favorite code"),
42+
"output": ("basic", "my favorite code"),
4343
"amount": 4,
4444
"type": "production",
4545
"functional": True,
@@ -51,7 +51,7 @@ def check_basic_allocation_results(factor_1, factor_2, database):
5151

5252
expected = {
5353
"input": nodes[0].key,
54-
"output": nodes[2].key,
54+
"output": ("basic", "my favorite code"),
5555
"amount": factor_1,
5656
"type": "biosphere",
5757
}

0 commit comments

Comments
 (0)