in each iteration you're modifying the sql database with your inventory when you do heat_exchange.save()
. This is going to be mega slow. It is much better to use an interface with bw_processing. You can create one that in each iteration returns a value from your function and modify the precise value of your A matrix that you want to change.
An example here or here. You can combine that with the uncertainty coming from your background (ecoinvent) if you want.