oberbichler / hyperjet Goto Github PK
View Code? Open in Web Editor NEWAlgorithmic differentiation with hyper-dual numbers in C++ and Python
License: MIT License
Algorithmic differentiation with hyper-dual numbers in C++ and Python
License: MIT License
Hello,
I am trying to follow your quickstart.md
but I find this error. could you please help me?
I have installed with
>> pip install git+https://github.com/oberbichler/HyperJet
then
In [2]: import hyperjet as hj
In [3]: x, y = hj.Jet.variables([3, 6])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-1bbea4a89a88> in <module>
----> 1 x, y = hj.Jet.variables([3, 6])
AttributeError: module 'hyperjet' has no attribute 'Jet'
Thanks
HyperJet/include/hyperjet/Jet.h
Line 297 in 0ab72b6
Have you tried what happens if one takes the square root of 0.0?
>>> import hyperjet as hj
>>> a = hj.Jet(0.0, [1])
>>> np.sqrt(a)
__main__:1: RuntimeWarning: divide by zero encountered in sqrt
Jet<0.000000>
I'm not sure if this Warning is caused by the division by 0.0 inside the Jet implementation or somewhere in numpy.
Armin
Hi,
I'm always looking for alternative backends beside casADi for my constitutive material definition python package (matADi, ideas on alternative backends here) and I really like hyperjet, thanks ๐ ! Given the example below, do you have any other ideas to speed things up? My use case is to evaluate gradients and hessian of a strain energy function for hyperelastic solids within finite element analyses (using FElupe).
import numpy as np
from hyperjet import DDScalar
def det(A):
return (
A[0] * A[1] * A[2] + 2 * A[3] * A[4] * A[5]
- A[1] * A[5] ** 2 - A[0] * A[4] **2 - A[2] * A[3] ** 2
)
def trace(A):
return A[:3].sum()
def neo_hooke(C):
return det(C) ** (-1 / 3) * trace(C) - 3
def tensor(x):
return np.array(DDScalar.variables(x.ravel())).reshape(*x.shape)
# init 100,000 random right Cauchy-Green deformation tensors
rCG = (np.random.rand(100000, 6) - 0.5) / 5
rCG[:, :3] += 1
from joblib import Parallel, delayed
hessian = lambda fun, x: fun(tensor(x)).hm()
A = Parallel(n_jobs=16, verbose=1, batch_size=1000)(
delayed(hessian)(neo_hooke, C) for C in rCG#
)
gives
[Parallel(n_jobs=16)]: Using backend LokyBackend with 16 concurrent workers.
[Parallel(n_jobs=16)]: Done 18032 tasks | elapsed: 0.9s
[Parallel(n_jobs=16)]: Done 97760 tasks | elapsed: 3.0s
[Parallel(n_jobs=16)]: Done 100000 out of 100000 | elapsed: 3.1s finished
which is very ok but I'd like to know if there is room for improvement. Not in using joblib, but some best-practise tips for hyperjet instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.