Comments (8)
Interesting. I've never even considered what happens to units when using differentiate
.
@dallan-keylogic - can you provide a little more context about what you are trying to do? Where are these derivatives getting used?
from pyomo.
@michaelbynum , they're getting used as part of building up an expression for excess molar enthalpy in an activity coefficient model. Initially, I was using AD to build up the entire expression, but it generally builds expressions that are considerably larger than those I can generate by hand. Right now, I'm using it to get derivatives of other user-defined properties to avoid requiring the user to provide the derivative in addition to the property.
v = pyunits.convert(
getattr(b, pname + "_vol_mol_solvent"), pyunits.m**3 / pyunits.mol
)
dv_dT = differentiate(
v,
b.temperature,
mode=Modes.reverse_symbolic
)
eps = getattr(b, pname + "_relative_permittivity_solvent")
d_eps_dT = getattr(b, pname + "_d_relative_permittivity_solvent_dT")
A_DH = getattr(b, pname + "_A_DH")
Ix = getattr(b, pname + "_ionic_strength")
rho = ClosestApproach
# Temperature derivative of Debye Huckel term
dA_dT = -A_DH / 2 * (
1/v * dv_dT + 3 * (1/eps) * d_eps_dT
)
from pyomo.
Could you use numeric differentiation instead of symbolic? Or you need symbolic?
from pyomo.
This is in the context of building up a big Pyomo expression, so it has to be symbolic.
from pyomo.
I think we could add some logic to the differentiate
function that checks if an int
or a float
is being returned and, if so, makes it a Pyomo expression with units that match what is expected. Thoughts, @jsiirola?
from pyomo.
Oh, this is actually because of the way we initialize the derivative map here:
. I think I just need to update that to include units...from pyomo.
No, I think this is probably easier to handle inside of differentiate
.
from pyomo.
Somewhat tangential to this issue, I have another entry in the "zero should be treated as being equivalent with any set of units" file:
pyunits.convert(
N_A * (q_e)**2/(8 * pi * eps_vacuum * eps_solvent)
* (1 + b.temperature / eps_solvent * d_eps_solvent_dT)
* sum(
b.mole_frac_phase_comp_true[pname, s]
* abs(cobj(b, s).config.charge) ** 2
/ cobj(b, s).born_radius
for s in b.params.ion_set
),
to_units=units.ENERGY/units.AMOUNT
)
I have this expression as part of an eNRTL expression, and have just debugged an issue arising when b.params.ion_set
is empty. The summation, instead of picking up units of 1/length, returns the integer zero instead, which leads to dimensional inconsistency when the unit conversion is performed.
There's a straightforward solution in this case, however: return zero with correct units if len(b.params.ion_set) == 0
, otherwise return this expression.
from pyomo.
Related Issues (20)
- Negative number of continuous variables in the results
- Add Configuration Option for NL Writer Presolve Tolerance
- Incompatibility with numpy 2.0 HOT 2
- Baron writer refuses to solve a deactivated block
- Python 3.11.8 on Windows: tuple object does not support item assignment HOT 2
- NEOS/octeract interface is failing tests
- Cannot initialize Suffix component with scalar value
- pyomo.contrib.latex_printer.latex_printer throws KeyError on numpy.int64
- We don't update rule when we change domain on IndexedVar
- Error with cplex persistent : "ValueError: Cannot load a SolverResults object with bad status" HOT 4
- Error running Pyomo with threading HOT 3
- Mismatch: `OptSolver` versus `set_results_format` HOT 1
- Numpy breaking value from pyomo.environ HOT 4
- contrib.alternative_solutions TODO HOT 2
- Scaling transformation does not transform named Expressions HOT 5
- Pyomo.DoE refactor: Development plan for remaining functionality upgrades and future vision
- "np.float" in pyomo HOT 1
- NL file contains np.float64(0.0)
- Deprecate use of positional arguments in CyIpopt callbacks
- Valid solvers for GAMS writer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyomo.