Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't save transition system #21

Open
kjleahy opened this issue Aug 13, 2020 · 4 comments
Open

Can't save transition system #21

kjleahy opened this issue Aug 13, 2020 · 4 comments
Assignees

Comments

@kjleahy
Copy link
Collaborator

kjleahy commented Aug 13, 2020

I have a script to generate a transition system. Cristi has access to it in another repo. But dumper has issues saving the TS. I assume there is an issue with the formatting in the graph somehow.

import lomap as lm
from RandomizedCaTLExperiments import generateRandomGridTS_seed

b = generateRandomGridTS_seed('test_ts',[5,5],0.1,['A','B','C'],[0.1,0.2,0.7],[1,2],seed=1)
b.save('test_b.yaml')

If I change model.py to include this definition

    def save(self, filename):
        '''Save the model to file in YAML format.'''
        Dumper.ignore_aliases = lambda *args : True
        with open(filename, 'w') as fout:
            dump(self, fout, Dumper=Dumper)

then I can use save without any issues.

Hrere is the long error message I obtain:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kevin/iitchs/catl_planning/RandomizedCaTLExperiments.py", line 116, in generateRandomGridTS_seed
    tsModel.save(tsname)
  File "/home/kevin/iitchs/catl_planning/lomap/lomap/classes/model.py", line 114, in save
    dump(self, fout, Dumper=Dumper)
  File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 202, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 190, in dump_all
    dumper.represent(data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 28, in represent
    node = self.represent_data(data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/home/kevin/iitchs/catl_planning/lomap/lomap/classes/__init__.py", line 39, in model_representer
    'edges' : map(list, model.g.edges(data=True))
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 123, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 223, in represent_dict
    return self.represent_mapping(u'tag:yaml.org,2002:map', data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 123, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 215, in represent_list
    return self.represent_sequence(u'tag:yaml.org,2002:seq', data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 101, in represent_sequence
    node_item = self.represent_data(item)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 215, in represent_list
    return self.represent_sequence(u'tag:yaml.org,2002:seq', data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 101, in represent_sequence
    node_item = self.represent_data(item)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 223, in represent_dict
    return self.represent_mapping(u'tag:yaml.org,2002:map', data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 123, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 61, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 437, in represent_object
    return self.represent_sequence(tag+function_name, args)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 101, in represent_sequence
    node_item = self.represent_data(item)
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 41, in represent_data
    if self.ignore_aliases(data):
  File "/usr/lib/python2.7/dist-packages/yaml/representer.py", line 142, in ignore_aliases
    if data in [None, ()]:
TypeError: data type not understood
@wasserfeder wasserfeder self-assigned this Aug 16, 2020
@wasserfeder
Copy link
Owner

I was not able to reproduce the error. What version of pyyaml, numpy, and networkx are you using. The issue might be because of numpy arrays, in your case the edge weights (which are scalar numpy arrays).

@kjleahy
Copy link
Collaborator Author

kjleahy commented Aug 17, 2020

I've got pyyaml 3.11, numpy 1.11.0, and networkx 1.11.

@wasserfeder
Copy link
Owner

Is this still an issue?

@kjleahy
Copy link
Collaborator Author

kjleahy commented Sep 10, 2020

It is still an issue. The input arguments to generateRandomGridTS have changed, so you can call it as b = generateRandomGridTS_seed('test_ts',[5,5],['A','B','C'],[1,2],1,seed=1).

But I can modify my copy of lomap to make it work if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants