Repository: dmlc/dgl

Issue:
【DGLError】dgl._ffi.base.DGLError:Check failed: fs: Filename is invalid
## dgl._ffi.base.DGLError:Check failed: fs: Filename is invalid
Run link prediction example fails.

When i test my code

There are some troubles with it.

I don`t have any idea with what happens. Could you help me? thanks a lot.

paper`s name:GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
paper:https://arxiv.org/abs/2006.09963
code:https://github.com/THUDM/GCC

##Error
```
(GCC01) chloe@chloe-MS-7A74:~/Documents/00 Work/02 Xovee/01 Code/GCC$ bash scripts/pretrain.sh 0 --batch-size 256
Using backend: pytorch
Namespace(alpha=0.999, aug='1st', batch_size=256, beta1=0.9, beta2=0.999, clip_norm=1.0, cv=False, dataset='dgl', degree_embedding_size=16, epochs=100, exp='Pretrain', finetune=False, fold_idx=0, freq_embedding_size=16, gpu=0, hidden_size=64, learning_rate=0.005, load_path=None, lr_decay_epochs=[120, 160, 200], lr_decay_rate=0.0, max_degree=512, max_edge_freq=16, max_node_freq=16, moco=False, model='gin', model_folder='saved/Pretrain_moco_False_dgl_gin_layer_5_lr_0.005_decay_1e-05_bsz_256_hid_64_samples_2000_nce_t_0.07_nce_k_32_rw_hops_256_restart_prob_0.8_aug_1st_ft_False_deg_16_pos_32_momentum_0.999', model_name='Pretrain_moco_False_dgl_gin_layer_5_lr_0.005_decay_1e-05_bsz_256_hid_64_samples_2000_nce_t_0.07_nce_k_32_rw_hops_256_restart_prob_0.8_aug_1st_ft_False_deg_16_pos_32_momentum_0.999', model_path='saved', momentum=0.9, nce_k=32, nce_t=0.07, norm=True, num_copies=6, num_layer=5, num_samples=2000, num_workers=12, optimizer='adam', positional_embedding_size=32, print_freq=10, readout='avg', restart_prob=0.8, resume='', rw_hops=256, save_freq=1, seed=0, set2set_iter=6, set2set_lstm_layer=3, subgraph_size=128, tb_folder='tensorboard/Pretrain_moco_False_dgl_gin_layer_5_lr_0.005_decay_1e-05_bsz_256_hid_64_samples_2000_nce_t_0.07_nce_k_32_rw_hops_256_restart_prob_0.8_aug_1st_ft_False_deg_16_pos_32_momentum_0.999', tb_freq=250, tb_path='tensorboard', weight_decay=1e-05)
Use GPU: 0 for training
setting random seeds
before construct dataset 6.249996185302734
Traceback (most recent call last):
  File "train.py", line 818, in <module>
    main(args)
  File "train.py", line 555, in main
    num_copies=args.num_copies
  File "/home/chloe/Documents/00 Work/02 Xovee/01 Code/GCC/gcc/datasets/graph_dataset.py", line 58, in __init__
    graph_sizes = dgl.data.utils.load_labels(dgl_graphs_file)[
  File "/home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/data/graph_serialize.py", line 172, in load_labels
    metadata = _CAPI_DGLLoadGraphs(filename, [], True)
  File "dgl/_ffi/_cython/./function.pxi", line 287, in dgl._ffi._cy3.core.FunctionBase.__call__
  File "dgl/_ffi/_cython/./function.pxi", line 222, in dgl._ffi._cy3.core.FuncCall
  File "dgl/_ffi/_cython/./function.pxi", line 211, in dgl._ffi._cy3.core.FuncCall3
  File "dgl/_ffi/_cython/./base.pxi", line 155, in dgl._ffi._cy3.core.CALL
dgl._ffi.base.DGLError: [21:41:01] /opt/dgl/src/graph/graph_serialize.cc:193: Check failed: fs: Filename is invalid
Stack trace:
  [bt] (0) /home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/libdgl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x22) [0x7fbe9e1ec782]
  [bt] (1) /home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/libdgl.so(dgl::serialize::LoadDGLGraphs(std::string const&, std::vector<unsigned long, std::allocator<unsigned long> >, bool)+0xe7c) [0x7fbe9e859a5c]
  [bt] (2) /home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/libdgl.so(+0xd1f0eb) [0x7fbe9e85a0eb]
  [bt] (3) /home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/libdgl.so(DGLFuncCall+0x52) [0x7fbe9e7f46e2]
  [bt] (4) /home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/_ffi/_cy3/core.cpython-37m-x86_64-linux-gnu.so(+0x19cdb) [0x7fbef63a5cdb]
  [bt] (5) /home/chloe/anaconda3/envs/GCC01/lib/python3.7/site-packages/dgl/_ffi/_cy3/core.cpython-37m-x86_64-linux-gnu.so(+0x1a25b) [0x7fbef63a625b]
  [bt] (6) python(_PyObject_FastCallKeywords+0x48b) [0x55db603c900b]
  [bt] (7) python(_PyEval_EvalFrameDefault+0x49b6) [0x55db6042d186]
  [bt] (8) python(_PyFunction_FastCallKeywords+0xfb) [0x55db603c120b]
```
##Environment

scikit-learn==0.20.3
scipy==1.4.1
coverage==4.5.4
coveralls==1.9.2
black==19.3b0
pytest==5.3.2
networkx==2.3
numpy==1.18.2
matplotlib==3.1.0
seaborn==0.9.0
tqdm==4.43.0
tensorboard_logger==0.1.0

torch~=1.5.1
dgl~=0.4.3.post2
pandas~=1.0.5
requests~=2.24.0
psutil~=5.7.2
joblib~=0.16.0

Python:3.7
PyTorch 1.5.1
DGL 0.4.1
rdkit=2019.09.2.




Discussion:
Hi, could you please try latest version of DGL (0.4.3), which updates the graph serialization module.
Hi,

May I know which code are you running?
> Hi, could you please try latest version of DGL (0.4.3), which updates the graph serialization module.

Thanks for your answer. But it still doesn`t work when I update to the lastest version of DGL(0.4.3). The DGL`s version of my environment is 0.4.3.post2
> > Hi, could you please try latest version of DGL (0.4.3), which updates the graph serialization module.
> 
> Thanks for your answer. But it still doesn`t work when I update to the lastest version of DGL(0.4.3). The DGL`s version of my environment is 0.4.3.post2

the code`link is https://github.com/THUDM/GCC
Did you properly download the pre-training dataset at https://github.com/THUDM/GCC/blob/master/GETTING_STARTED.md? This error seems the filename is not found.

Resolving patch:
diff --git a/python/dgl/data/graph_serialize.py b/python/dgl/data/graph_serialize.py
--- a/python/dgl/data/graph_serialize.py
+++ b/python/dgl/data/graph_serialize.py
@@ -1,5 +1,6 @@
 """For Graph Serialization"""
 from __future__ import absolute_import
+import os
 from ..graph import DGLGraph
 from ..heterograph import DGLHeteroGraph
 from .._ffi.object import ObjectBase, register_object
@@ -70,7 +71,7 @@ def save_graphs(filename, g_list, labels=None):
     Parameters
     ----------
     filename : str
-        File name to store graphs. 
+        File name to store graphs.
     g_list: list
         DGLGraph or list of DGLGraph/DGLHeteroGraph
     labels: dict[str, tensor]
@@ -81,7 +82,7 @@ def save_graphs(filename, g_list, labels=None):
     >>> import dgl
     >>> import torch as th
 
-    Create :code:`DGLGraph`/:code:`DGLHeteroGraph` objects and initialize node 
+    Create :code:`DGLGraph`/:code:`DGLHeteroGraph` objects and initialize node
     and edge features.
 
     >>> g1 = dgl.graph(([0, 1, 2], [1, 2, 3])
@@ -95,6 +96,13 @@ def save_graphs(filename, g_list, labels=None):
     >>> save_graphs("./data.bin", [g1, g2], graph_labels)
 
     """
+    # if it is local file, do some sanity check
+    if filename.startswith('s3://') is False:
+        assert not os.path.isdir(filename), "filename {} is an existing directory.".format(filename)
+        f_path, _ = os.path.split(filename)
+        if not os.path.exists(f_path):
+            os.makedirs(f_path)
+
     g_sample = g_list[0] if isinstance(g_list, list) else g_list
     if isinstance(g_sample, DGLGraph):
         save_dglgraphs(filename, g_list, labels)
@@ -149,6 +157,9 @@ def load_graphs(filename, idx_list=None):
     >>> glist, label_dict = load_graphs("./data.bin", [0]) # glist will be [g1]
 
     """
+    # if it is local file, do some sanity check
+    assert filename.startswith('s3://') or os.path.exists(filename), "file {} does not exist.".format(filename)
+
     version = _CAPI_GetFileVersion(filename)
     if version == 1:
         return load_graph_v1(filename, idx_list)
@@ -204,6 +215,9 @@ def load_labels(filename):
     >>> label_dict = load_graphs("./data.bin")
 
     """
+    # if it is local file, do some sanity check
+    assert filename.startswith('s3://') or os.path.exists(filename), "file {} does not exist.".format(filename)
+
     version = _CAPI_GetFileVersion(filename)
     if version == 1:
         return load_labels_v1(filename)


Test patch: