繁体   English   中英

在 PyDrake 中使用 autodiff 时无法检查不可行的约束

[英]Unable to check infeasible constraints when using autodiff in PyDrake

我正在使用 SNOPT 解决 PyDrake 中的一个问题,我得到了看起来合理的解决方案,但是当我执行result.is_success()时,它会返回False ,所以我希望调查为什么它认为问题没有解决。 我假设我在某处有一个不好的约束,所以我使用以下代码执行此操作:

result = mp.Solve(prog)
if not result.is_success():
    print("INFEASIBLE:")
    infeasible = result.GetInfeasibleConstraints(prog)
    for c in infeasible:
        print(c)

但是,它在调用result.GetInfeasibleConstraints(prog)时退出,并出现以下错误:

Traceback (most recent call last):
  File "test_drake_distribution.py", line 250, in <module>
    infeasible = result.GetInfeasibleConstraints(prog)
  File "/home/adam/.miniconda3/envs/drake/lib/python3.6/site-packages/pydrake/solvers/_mathematicalprogram_extra.py", line 34, in _check_array_type
    f"{var_name} must be of scalar type {expected_name}, but unable "
RuntimeError: PyFunctionConstraint: Output must be of scalar type float, but unable to infer scalar type.

它说的是真的,因为我的约束函数正在利用 Drake 中的 autodiff 功能,所以它们返回 arrays 和dtype=AutoDiffXd 如果是这种情况,这是否意味着我不能使用约束不可行性检查器? 关于在使用 autodiff 时能够检查不可行约束的任何建议?

我想您使用 python function 编写约束。 我建议写这个 python function 来处理浮动和 autodiffxd,所以像这样

def my_evaluator(x: np.ndarray):
    if x.dtype == np.object:
        # This is the autodiff case
    elif x.dtype == np.float:
        # This is the float case 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM