pyoptmat.temperature: dealing with temperature dependence
The idea of the objects here, derived from TemperatureParameter
is to provide temperature-dependent versions of raw model parameters.
These scaling rules are functions of some “actual” parameters, either PyTorch or Pyro parameters, which are actually optimized. These scaling rules somehow map a collection of these parameters to a temperature dependent property.
On top of this temperature scaling, these classes can also, optionally be used to do numerical scaling of the underlying parameters to achieve better numerical stability. So, in the end, mathematically these classes are functions of the kind
where \(s\) is a scaling function with fixed parameters aimed at helping numerical scaling and \(t\) is the actual temperature scaling function, parameterized with a set of parameters \(p\) which will be varied during optimization.
The simplest example is the pyoptmat.temperature.ConstantParameter
which simple returns the constant (temperature-indpendent)
value of a single underlying parameter p.
The second simplest example is
pyoptmat.temperature.PolynomialScaling which takes a tensor parameter
c describing polynomial coefficients. This scaling function
evaluates the polynomial described by these coefficients at T to
provide the parameter temperature dependence.
The numerical scaling functions \(s\) default to the identity, i.e.
no scaling. The pyoptmat.optimize module provides some
common, useful scaling functions, though often simply scaling by an
appropriate order of magnitude value so that the “actual” parameters
\(p\) are on the order of 1.
All of these temperature scaling rules have to be compatible with
batched temperatures, i.e. they should expect to receive a tensor
of shape (nbatch,), not just a scalar.
- class pyoptmat.temperature.ArrheniusScaling(A, Q, *args, A_scale=<function ArrheniusScaling.<lambda>>, Q_scale=<function ArrheniusScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterSimple Arrhenius scaling of the type
\[A \exp(-Q/T)\]- Parameters:
A (torch.tensor) – Prefactor
Q (torch.tensor) – Activation energy (times R)
- Keyword Args
A_scale (function): numerical scaling for A, defaults to no scaling Q_scale (function): numerical scaling for Q, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.ConstantParameter(pvalue, *args, p_scale=<function ConstantParameter.<lambda>>, **kwargs)
Bases:
TemperatureParameterA parameter that is constant with temperature
- Parameters:
pvalue (torch.tensor) – the constant parameter value
- Keyword Arguments:
p_scale (function) – numerical scaling function, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
The shape of the underlying parameter
- value(T)
Pretty simple, just return the value!
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.InverseArrheniusScaling(A, Q, *args, A_scale=<function InverseArrheniusScaling.<lambda>>, Q_scale=<function InverseArrheniusScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterSimple Arrhenius scaling of the type
\[A (1 - \exp(-Q/T))\]- Parameters:
A (torch.tensor) – Prefactor
Q (torch.tensor) – Activation energy (times R)
- Keyword Args
A_scale (function): numerical scaling for A, defaults to no scaling Q_scale (function): numerical scaling for Q, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.KMRateSensitivityScaling(A, mu, b, k, *args, A_scale=<function KMRateSensitivityScaling.<lambda>>, cutoff=20.0, **kwargs)
Bases:
TemperatureParameterParameter that scales as:
\[\frac{-\mu b^3}{kTA}\]where \(\mu\) further depends on temperature
- Parameters:
A (torch.tensor) – Kocks-Mecking slope parameter, sets shape
mu (
TemperatureParameter) – scalar, temperature-dependent shear modulusb (torch.tensor) – scalar, Burgers vector
k (torch.tensor) – scalar, Boltzmann constant
- Keyword Arguments:
cutoff (float) – don’t let n go higher than this
A_scale (function) – numerical scaling function for A, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.KMViscosityScaling(A, B, mu, eps0, b, k, *args, A_scale=<function KMViscosityScaling.<lambda>>, B_scale=<function KMViscosityScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterParameter that varies as
\[\exp{B} \mu \dot{\varepsilon}_0^{-1/n}\]where \(B\) is the Kocks-Mecking intercept parameter and the rest are defined in the
pyoptmat.temperature.KMRateSensitivityScalingobject.\(n\) is the rate sensitivity, again given by the
pyoptmat.temperature.KMRateSensitivityScalingobject- Parameters:
A (torch.tensor) – Kocks-Mecking slope parameter
B (torch.tensor) – Kocks-Mecking intercept parameter, sets shape, must be same shape as A
mu (
TemperatureParameter) – scalar, temperature-dependent shear moduluseps0 (torch.tensor) – scalar, reference strain rate
b (torch.tensor) – scalar, Burger’s vector
k (torch.tensor) – scalar, Boltzmann constant
- Keyword Arguments:
A_scale (function) – numerical scaling function for A, defaults to no scaling
B_scale (function) – numerical scaling function B, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.MTSScaling(tau0, g0, q, p, k, b, mu, *args, tau0_scale=<function MTSScaling.<lambda>>, g0_scale=<function MTSScaling.<lambda>>, q_scale=<function MTSScaling.<lambda>>, p_scale=<function MTSScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterParameter that scales as:
\[\hat{\tau}\left\{ 1 - \left[ \frac{kT}{\mu b^3 g_0} \right]^{1/q} \right\}^{1/p}\]- Parameters:
tau0 (torch.tensor) – threshold strength
g0 (torch.tensor) – activation energy
q (torch.tensor) – shape parameter
p (torch.tensor) – shape parameter
k (torch.tensor) – Boltzmann constant
b (torch.tensor) – burgers vector
mu (
TemperatureParameter) – shear modulus, temperature-dependent
- Keyword Arguments:
tau0_scale (function) – numerical scaling function for tau0, defaults to no scaling
g0_scale (function) – numerical scaling function for g0, defaults to no scaling
q_scale (function) – numerical scaling function for g0, defaults to no scaling
p_scale (function) – numerical scaling function for p, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.PiecewiseScaling(control, values, *args, values_scale_fn=<function PiecewiseScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterPiecewise linear interpolation, mimics scipy.interp1d with default options
- Parameters:
control (torch.tensor) – temperature control points (npoints)
values (torch.tensor) – values at control points (optional_batch, npoints)
- Keyword Arguments:
values_scale_fn (function) – numerical scaling function for values, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.PolynomialScaling(coefs, *args, coef_scale_fn=<function PolynomialScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterMimics np.polyval using Horner’s method to evaluate a polynomial
- Parameters:
coefs (torch.tensor) – polynomial coefficients in the numpy convention (highest order 1st)
- Keyword Arguments:
coef_scale_fn (function) – numerical scaling function for coefs, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
Shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.ShearModulusScaling(A, mu, *args, A_scale=<function ShearModulusScaling.<lambda>>, **kwargs)
Bases:
TemperatureParameterParameter that scales as:
\[A \mu\]where \(\mu\) further depends on temperature
- Parameters:
A (torch.tensor) – actual parameter
mu (
TemperatureParameter) – scalar, temperature-dependent shear modulus
- Keyword Arguments:
A_scale (function) – numerical scaling function for A, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
The shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.ShearModulusScalingExp(A, mu, *args, A_scale=<function ShearModulusScalingExp.<lambda>>, **kwargs)
Bases:
TemperatureParameterParameter that scales as:
\[\exp(A) \mu\]where \(\mu\) further depends on temperature
- Parameters:
A (torch.tensor) – actual parameter
mu (
TemperatureParameter) – scalar, temperature-dependent shear modulus
- Keyword Arguments:
A_scale (function) – numerical scaling function for A, defaults to no scaling
- property device
Return the device used by the scaling function
- property shape
The shape of the underlying parameter
- value(T)
Return the function value
- Parameters:
T (torch.tensor) – current temperature
- Returns:
value at the given temperatures
- Return type:
torch.tensor
- class pyoptmat.temperature.TemperatureParameter(*args, scaling=<function TemperatureParameter.<lambda>>, **kwargs)
Bases:
ModuleSuperclass of all temperature-dependent parameters
This class takes care of numerical scaling on the end result, if required
- Keyword Arguments:
scaling (function) – numerical scaling function, defaults to no scaling
- forward(T)
Return the actual parameter value
- Parameters:
T (torch.tensor) – current temperature