YaChienChang / Neural-Lyapunov-Control

Learning Lyapunov functions and control policies of nonlinear dynamical systems
117 stars 31 forks source link

RuntimeError: expected scalar type Float but found Double #4

Closed ssantus closed 3 years ago

ssantus commented 3 years ago

Hi, I am trying to run your repository but I get the following error: "RuntimeError: expected scalar type Float but found Double" when trying to run the block of Learning and Falsification on both the inverted pendulum and the path following notebooks. I am not sure how to proceed and I was wondering if you have faced this before. More details about the error:

0 Lyapunov Risk= 73.07649993896484 ===========Verifying========== Not a Lyapunov function. Found counterexample: x1 : [-5.607981400644867165, -5.607370072610038392] x2 : [0.9742785792574937265, 0.974595727232512421]


RuntimeError Traceback (most recent call last)

in 13 14 while i < max_iters and not valid: ---> 15 V_candidate, u = model(x) 16 X0,u0 = model(x_0) 17 f = f_value(x,u) ~/anaconda3/envs/nnlyap/lib/python3.6/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 887 result = self._slow_forward(*input, **kwargs) 888 else: --> 889 result = self.forward(*input, **kwargs) 890 for hook in itertools.chain( 891 _global_forward_hooks.values(), in forward(self, x) 11 def forward(self,x): 12 sigmoid = torch.nn.Tanh() ---> 13 h_1 = sigmoid(self.layer1(x)) 14 out = sigmoid(self.layer2(h_1)) 15 u = self.control(x) ~/anaconda3/envs/nnlyap/lib/python3.6/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 887 result = self._slow_forward(*input, **kwargs) 888 else: --> 889 result = self.forward(*input, **kwargs) 890 for hook in itertools.chain( 891 _global_forward_hooks.values(), ~/anaconda3/envs/nnlyap/lib/python3.6/site-packages/torch/nn/modules/linear.py in forward(self, input) 92 93 def forward(self, input: Tensor) -> Tensor: ---> 94 return F.linear(input, self.weight, self.bias) 95 96 def extra_repr(self) -> str: ~/anaconda3/envs/nnlyap/lib/python3.6/site-packages/torch/nn/functional.py in linear(input, weight, bias) 1751 if has_torch_function_variadic(input, weight): 1752 return handle_torch_function(linear, (input, weight), input, weight, bias=bias) -> 1753 return torch._C._nn.linear(input, weight, bias) 1754 1755 RuntimeError: expected scalar type Float but found Double
YaChienChang commented 3 years ago

Hi, Did you modify any files in the repo? I downloaded again the repo and ran all Jupyter notebook files without any error. Could you check whether something is different between the code in the repo and yours? Thank you

ssantus commented 3 years ago

@YaChienChang No, I didn't change anything. I think the problem can be in the version of the modules. Could you please tell me which version of the required modules are you running in your environment? Thanks in advance!

YaChienChang commented 3 years ago

Hi, The version of the modules I am using :

dReal: v4.19.02.1
PyTorch: 1.2.0 
ssantus commented 3 years ago

@YaChienChang , downgrading my version of PyTorch to 1.2.0, as you indicated, solved my issue. Thanks!