DimensionalityError when trying to use solution array as initial guess for SP solve
See original GitHub issueLess of an issue, and more of a question on the new corrected syntax. 2 different causes of DimensionalityError:
---------------------------------------------------------------------------
DimensionalityError Traceback (most recent call last)
/Users/philippekirschen/Documents/MIT/Research/GPjet/gpjet/vtail/vtail.py in <module>()
175
176 if __name__ == "__main__":
--> 177 VerticalTail().test()
/Users/philippekirschen/Documents/MIT/Research/GPjet/gpjet/vtail/vtail.py in test(self)
151
152 npt.assert_almost_equal(sol('\\Delta x_{trail}'), sol('c_{root}')
--> 153 + sol('\\Delta x_{lead}'), decimal=4)
154 npt.assert_almost_equal(sol('\\Delta x_{lead}') + sol('z_{\\bar{c}}')
155 *sol('\\tan(\\Lambda_{LE})')
/Users/philippekirschen/anaconda/lib/python2.7/site-packages/numpy/testing/utils.pyc in assert_almost_equal(actual, desired, decimal, err_msg, verbose)
487 except (NotImplementedError, TypeError):
488 pass
--> 489 if round(abs(desired - actual), decimal) != 0 :
490 raise AssertionError(_build_err_msg())
491
/Users/philippekirschen/anaconda/lib/python2.7/site-packages/pint/quantity.pyc in __float__(self)
280 if self.dimensionless:
281 return float(self._convert_magnitude_not_inplace(UnitsContainer()))
--> 282 raise DimensionalityError(self.units, 'dimensionless')
283
284 def __complex__(self):
DimensionalityError: Cannot convert from 'meter' to 'dimensionless'
[philippekirschen@dhcp-18-189-101-248 aircraft]$ ipython aircraft.py
Beginning signomial solve.
The 'setup' method of this model had an error.
---------------------------------------------------------------------------
DimensionalityError Traceback (most recent call last)
/Users/philippekirschen/Documents/MIT/Research/GPjet/gpjet/aircraft/aircraft.py in <module>()
86
87 if __name__ == "__main__":
---> 88 Aircraft()#.test()
89
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/model.pyc in __init__(self, cost, constraints, substitutions, *args, **kwargs)
84 extended_args.extend(args)
85 name = kwargs.pop("name", self.__class__.__name__)
---> 86 setup = self.setup(*extended_args, **kwargs)
87 except:
88 print("The 'setup' method of this model had an error.")
/Users/philippekirschen/Documents/MIT/Research/GPjet/gpjet/aircraft/aircraft.py in setup(self)
78 init2[newkey] = value
79
---> 80 aircraft.localsolve(x0=init2)
81
82 return aircraft
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/model.pyc in localsolve(self, solver, verbosity, skipsweepfailures, *args, **kwargs)
383 with SignomialsEnabled():
384 return self._solve("sp", solver, verbosity, skipsweepfailures,
--> 385 *args, **kwargs)
386 except ValueError as err:
387 if err.message == ("SignomialPrograms must contain at least one"
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/model.pyc in _solve(self, programType, solver, verbosity, skipsweepfailures, *args, **kwargs)
500 self.program, solvefn = form_program(programType, signomials,
501 verbosity=verbosity)
--> 502 result = solvefn(*args, **kwargs)
503 solution.append(parse_result(result, constants, beforesubs))
504 solution.program = self.program
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/signomial_program.py in localsolve(self, solver, verbosity, x0, rel_tol, iteration_limit, *args, **kwargs)
115 appear to be converging, you may wish to increase the iteration limit by
116 calling .localsolve(..., iteration_limit=NEWLIMIT).""" % len(self.gps))
--> 117 gp = self.step(x0, verbosity=verbosity-1)
118 self.gps.append(gp) # NOTE: SIDE EFFECTS
119 try:
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/signomial_program.py in step(self, x0, verbosity)
169 posy_approx = p
170 else:
--> 171 posy_approx = p/n.mono_lower_bound(x0)
172 # posy_approxs.append(posy_approx)
173 # posy_approx = 1/posy_approx
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/nomials.pyc in mono_lower_bound(self, x_0)
484 Monomial
485 """
--> 486 return self.mono_approximation(x_0)
487
488
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/nomials.pyc in mono_approximation(self, x_0)
172 x_0 = get_constants(self, x_0)
173 exp = HashVector()
--> 174 psub = self.sub(x_0)
175 if psub.varlocs:
176 raise ValueError("Variables %s remained after substituting x_0=%s"
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/nomials.pyc in sub(self, substitutions, val, require_positive)
206 Returns substituted nomial.
207 """
--> 208 _, exps, cs, _ = substitution(self, substitutions, val)
209 return Signomial(exps, cs, require_positive=require_positive)
210
/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/substitution.pyc in substitution(nomial, substitutions, val)
158 if isinstance(sub, Numbers):
159 if sub != 0:
--> 160 cs_[i] *= sub**x
161 else: # frickin' pints bug. let's reimplement pow()
162 if x > 0:
/Users/philippekirschen/anaconda/lib/python2.7/site-packages/pint/quantity.pyc in __setitem__(self, key, value)
1030 extra_msg='. Assign a quantity with the same dimensionality or '
1031 'access the magnitude directly as '
-> 1032 '`obj.magnitude[%s] = %s`' % (key, value))
1033 self._magnitude[key] = factor.magnitude
1034 else:
DimensionalityError: Cannot convert from '15253.5801059 newton ** 2' to 'newton'. Assign a quantity with the same dimensionality or access the magnitude directly as `obj.magnitude[2] = 15253.5801059 newton ** 2`
Issue Analytics
- State:
- Created 8 years ago
- Comments:21 (19 by maintainers)
Top Results From Across the Web
Solve symbolic equations numerically - MATLAB vpasolve
S = vpasolve( eqn , var , init_param ) numerically solves the equation eqn for the variable var using the initial guess or...
Read more >Solvers - SymPy 1.11 documentation
Instructs solve to try to find a particular solution to a linear system with as many zeros as possible; this is very expensive....
Read more >solving a sparse non linear system of equations using ...
In any event, this function uses root to solve the system of equations. ... Initial guess on x. alpha0 - nx1 numpy array....
Read more >scipy.sparse.linalg.lsqr — SciPy v1.9.3 Manual
Find the least-squares solution to a large, sparse, linear system of equations. ... barray_like, shape (m,) ... Initial guess of x, if None...
Read more >Python nonlinear systems of equations using fsolve - YouTube
Python, solving systems of nonlinear equations using fsolve. The corresponding notes are here: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I actually haven’t tested it with the second case, but when I do and if it works I will close.
it works 😃