From f92f8c5f14c8d96f3db01611e12e5dbad5978028 Mon Sep 17 00:00:00 2001 From: Craig Hamel <31457225+cmhamel@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:43:25 -0500 Subject: [PATCH 1/8] Update setup.py Add a scipy version restriction after encountering terrible errors in a plato build. The culprit was a method call somewhere in ```Objective.py``` with an error similar to ```terminate called after throwing an instance of 'pybind11::error_already_set' what(): TypeError: primal and tangent arguments to jax.jvp do not match; dtypes must be equal, or in case of int/bool primal dtype the tangent dtype must be float0.Got primal dtype float64 and so expected tangent dtype float64, but got tangent dtype int8 instead. __notes__ (len=1):``` --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c4edecda..24f10cce 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ 'matplotlib', # this is not strictly necessary 'metis', 'netcdf4', - 'scipy',], + 'scipy==1.14.1',], #tests_require=[], # could put chex and pytest here extras_require={'sparse': ['scikit-sparse'], 'test': ['pytest', 'pytest-cov', 'pytest-xdist'], From ed7c413649b6c401c839a02d2aa770c5178c9fe9 Mon Sep 17 00:00:00 2001 From: Craig Hamel <31457225+cmhamel@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:48:17 -0500 Subject: [PATCH 2/8] Update setup.py fixing to an upper bound since 1.14.1 doesn't exist for python 3.9 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 24f10cce..8972933b 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ 'matplotlib', # this is not strictly necessary 'metis', 'netcdf4', - 'scipy==1.14.1',], + 'scipy<1.15.0',], #tests_require=[], # could put chex and pytest here extras_require={'sparse': ['scikit-sparse'], 'test': ['pytest', 'pytest-cov', 'pytest-xdist'], From 31cfadb4015c76f5f7e631900ced5cf9ff03c35e Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Wed, 8 Jan 2025 09:57:04 -0700 Subject: [PATCH 3/8] adding Mike's fix --- optimism/WarmStart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimism/WarmStart.py b/optimism/WarmStart.py index 47642bf1..ba2aa69c 100644 --- a/optimism/WarmStart.py +++ b/optimism/WarmStart.py @@ -14,7 +14,7 @@ def warm_start_increment(objective, x, pNew, index=0): raise('invalid warm start parameter gradient direction') sz = b.size - op = lambda v: objective.hessian_vec(x, v) + op = lambda v: objective.hessian_vec(x, np.array(v, dtype=np.float64)) Lop = LinearOperator((sz,sz), matvec = op) From a457f1432f9b5f96266794299a79d3fd8e8151cf Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Wed, 8 Jan 2025 09:57:27 -0700 Subject: [PATCH 4/8] removing dead import. --- optimism/WarmStart.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/optimism/WarmStart.py b/optimism/WarmStart.py index ba2aa69c..9c675f97 100644 --- a/optimism/WarmStart.py +++ b/optimism/WarmStart.py @@ -1,8 +1,7 @@ -from scipy.sparse.linalg import cg, LinearOperator - from optimism.JaxConfig import * -import optimism.Objective as Objective +from scipy.sparse.linalg import cg, LinearOperator + def warm_start_increment(objective, x, pNew, index=0): dp = objective.p[index] - pNew[index] From 920030f9cf8bbbf95c244f0a95c039f4e0749e20 Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Wed, 8 Jan 2025 09:57:43 -0700 Subject: [PATCH 5/8] removing scipy upperbound. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8972933b..c4edecda 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ 'matplotlib', # this is not strictly necessary 'metis', 'netcdf4', - 'scipy<1.15.0',], + 'scipy',], #tests_require=[], # could put chex and pytest here extras_require={'sparse': ['scikit-sparse'], 'test': ['pytest', 'pytest-cov', 'pytest-xdist'], From 8ff76d827bc1965f2954fbd28a341aa3332fb443 Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Wed, 8 Jan 2025 10:23:44 -0700 Subject: [PATCH 6/8] patching up some tests. --- optimism/contact/test/test_NewtonGlobalization.py | 2 +- optimism/inverse/test/test_Hyperelastic_gradient_checks.py | 2 +- optimism/inverse/test/test_J2Plastic_gradient_checks.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/optimism/contact/test/test_NewtonGlobalization.py b/optimism/contact/test/test_NewtonGlobalization.py index b8512988..65efc5d3 100644 --- a/optimism/contact/test/test_NewtonGlobalization.py +++ b/optimism/contact/test/test_NewtonGlobalization.py @@ -171,7 +171,7 @@ def test_al_solver(self): randRhs = np.array(rand(self.x.size)) randRhs *= 0.25 / np.linalg.norm(randRhs) - penalty0 = unconstrainedObjective.hessian_vec(self.x, randRhs) @ randRhs + penalty0 = unconstrainedObjective.hessian_vec(self.x, np.array(randRhs, dtype=np.float64)) @ randRhs alObjective = ConstrainedObjective(lambda x,p: objective(x), lambda x,p: constraint(x), diff --git a/optimism/inverse/test/test_Hyperelastic_gradient_checks.py b/optimism/inverse/test/test_Hyperelastic_gradient_checks.py index 83b52cd6..96a1e0d5 100644 --- a/optimism/inverse/test/test_Hyperelastic_gradient_checks.py +++ b/optimism/inverse/test/test_Hyperelastic_gradient_checks.py @@ -164,7 +164,7 @@ def total_work_gradient_with_adjoint(self, storedState, parameters): n = self.dofManager.get_unknown_size() self.objective.p = p # have to update parameters to get precond to work self.objective.update_precond(Uu) # update preconditioner for use in cg (will converge in 1 iteration as long as the preconditioner is not approximate) - dRdu = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.hessian_vec(Uu, V))) + dRdu = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.hessian_vec(Uu, np.array(V, dtype=np.float64)))) dRdu_decomp = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.apply_precond(V))) adjointVector = linalg.cg(dRdu, onp.array(adjointLoad, copy=False), rtol=1e-10, atol=0.0, M=dRdu_decomp)[0] diff --git a/optimism/inverse/test/test_J2Plastic_gradient_checks.py b/optimism/inverse/test/test_J2Plastic_gradient_checks.py index 53c3eea2..32b1112f 100644 --- a/optimism/inverse/test/test_J2Plastic_gradient_checks.py +++ b/optimism/inverse/test/test_J2Plastic_gradient_checks.py @@ -171,7 +171,7 @@ def total_work_gradient(self, storedState, parameters): p_objective = Objective.Params(bc_data=p.bc_data, state_data=p_prev.state_data) # remember R is a function of ivs_prev self.objective.p = p_objective self.objective.update_precond(Uu) # update preconditioner for use in cg (will converge in 1 iteration as long as the preconditioner is not approximate) - dRdu = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.hessian_vec(Uu, V))) + dRdu = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.hessian_vec(Uu, np.array(V, dtype=np.float64)))) dRdu_decomp = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.apply_precond(V))) adjointVector = linalg.cg(dRdu, onp.array(adjointLoad, copy=False), rtol=1e-10, atol=0.0, M=dRdu_decomp)[0] @@ -253,7 +253,7 @@ def target_curve_gradient(self, storedState, parameters): p_objective = Objective.Params(bc_data=p.bc_data, state_data=p_prev.state_data) # remember R is a function of ivs_prev self.objective.p = p_objective self.objective.update_precond(Uu) # update preconditioner for use in cg (will converge in 1 iteration as long as the preconditioner is not approximate) - dRdu = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.hessian_vec(Uu, V))) + dRdu = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.hessian_vec(Uu, np.array(V, np.float64)))) dRdu_decomp = linalg.LinearOperator((n, n), lambda V: onp.asarray(self.objective.apply_precond(V))) adjointVector = linalg.cg(dRdu, onp.array(adjointLoad, copy=False), rtol=1e-10, atol=0.0, M=dRdu_decomp)[0] From ddbc3cbc5cd205aa7d973c232c78891708f4f480 Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Wed, 8 Jan 2025 11:13:09 -0700 Subject: [PATCH 7/8] a few more fixes to tests. Hopefully that's it. --- optimism/contact/test/test_NewtonGlobalization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/optimism/contact/test/test_NewtonGlobalization.py b/optimism/contact/test/test_NewtonGlobalization.py index 65efc5d3..f60e3101 100644 --- a/optimism/contact/test/test_NewtonGlobalization.py +++ b/optimism/contact/test/test_NewtonGlobalization.py @@ -133,7 +133,7 @@ def test_newton_step(self): xl = np.hstack( (self.x, self.lam) ) r0 = np.linalg.norm( residual(xl) ) - xl += newton_step(residual, lambda v: linear_op(xl,v), xl)[0] + xl += newton_step(residual, lambda v: linear_op(xl, np.array(v, dtype=np.float64)), xl)[0] r1 = np.linalg.norm( residual(xl) ) self.assertTrue( r1 < 10*r0 ) @@ -144,7 +144,7 @@ def test_globalized_newton_step_with_cubic(self): linear_op = create_linear_op(residual) x = np.array([0.1]) r0 = np.linalg.norm( residual(x) ) - x += globalized_newton_step(residual, lambda v: linear_op(x,v), x, self.etak, self.t) + x += globalized_newton_step(residual, lambda v: linear_op(x, np.array(v, dtype=np.float64)), x, self.etak, self.t) r1 = np.linalg.norm( residual(x) ) self.assertTrue( r1 < r0 ) @@ -154,7 +154,7 @@ def test_globalized_newton_step_nonconvex(self): xl = np.hstack( (self.x, self.lam) ) r0 = np.linalg.norm( residual(xl) ) - xl += globalized_newton_step(residual, lambda v: linear_op(xl,v), xl, self.etak, self.t) + xl += globalized_newton_step(residual, lambda v: linear_op(xl, np.array(v, dtype=np.float64)), xl, self.etak, self.t) r1 = np.linalg.norm( residual(xl) ) self.assertTrue( r1 < r0 ) From 47db509051c57ecf4007779ea9fb6c874fb30907 Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Wed, 8 Jan 2025 12:22:35 -0700 Subject: [PATCH 8/8] trying with scipy upper bound since metis is causing issues now. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c4edecda..8972933b 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ 'matplotlib', # this is not strictly necessary 'metis', 'netcdf4', - 'scipy',], + 'scipy<1.15.0',], #tests_require=[], # could put chex and pytest here extras_require={'sparse': ['scikit-sparse'], 'test': ['pytest', 'pytest-cov', 'pytest-xdist'],