ChenFeng87 / network_inference

2 stars 1 forks source link

RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead #1

Closed gui11aume closed 2 years ago

gui11aume commented 2 years ago

When I call python Edge_removal.py in the MISA directory after following the first steps, I obtain the error below. I am using Python3.8, and numpy version 1.22.3. Are they the right versions?

python Edge_removal.py 

---------- Use this Use this part to infer the structure of GRNs ----------

--   You need to wait about 10 seconds to obtain picture The_role_X1.png

----------   import the DNN model  ----------

----------   import DNN is finish  ----------

----------   get the original sequence  ----------

----------   block the link from X1 to X1  ----------

----------   block the link from X1 to X2  ----------

----------   block the link from X2 to X1  ----------

----------   block the link from X2 to X2  ----------

----------   begin picture ----------
Traceback (most recent call last):
  File "Edge_removal.py", line 167, in <module>
    plt.plot(tt, x_1, label='X1-before', color='#98FB98', linewidth=4.0)  # pale green
  File "/home/gfilion/miniconda3/envs/temp/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2769, in plot
    return gca().plot(
  File "/home/gfilion/miniconda3/envs/temp/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 1632, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/home/gfilion/miniconda3/envs/temp/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 312, in __call__
    yield from self._plot_args(this, kwargs)
  File "/home/gfilion/miniconda3/envs/temp/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 488, in _plot_args
    y = _check_1d(xy[1])
  File "/home/gfilion/miniconda3/envs/temp/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 1306, in _check_1d
    return np.atleast_1d(x)
  File "<__array_function__ internals>", line 180, in atleast_1d
  File "/home/gfilion/.local/lib/python3.8/site-packages/numpy/core/shape_base.py", line 65, in atleast_1d
    ary = asanyarray(ary)
  File "/home/gfilion/miniconda3/envs/temp/lib/python3.8/site-packages/torch/tensor.py", line 486, in __array__
    return self.numpy()
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.
ChenFeng87 commented 2 years ago

We have modified the code so that it works with python 3.8. Thank you very much for your comments.