Kratos: Errors Load function for StreamSerializer object

Created on 28 Nov 2018  路  7Comments  路  Source: KratosMultiphysics/Kratos

Hi to everyone,

If in https://github.com/KratosMultiphysics/Kratos/blob/master/kratos/tests/test_model.py in the function "test_file_serialization" I modify/add the lines

    # ######## here we pickle the serializer
    # try:
    #     import cpickle as pickle  # Use cPickle on Python 2.7
    # except ImportError:
    #     import pickle

    # #pickle dataserialized_data
    # pickled_data = pickle.dumps(serializer, 2) #second argument is the protocol and is NECESSARY (according to pybind11 docs)

    # #overwrite the old serializer with the unpickled one
    # serializer = pickle.loads(pickled_data)

    loaded_model = KratosMultiphysics.Model()
    serializer.Load("ModelSerialization",loaded_model)
    self.assertTrue(loaded_model["Main"].HasNodalSolutionStepVariable(KratosMultiphysics.TEMPERATURE))
    self.assertTrue(loaded_model["Other"].HasNodalSolutionStepVariable(KratosMultiphysics.PRESSURE))

    self.assertTrue(loaded_model.HasModelPart("Main.Inlets"))
    self.assertTrue(loaded_model.HasModelPart("Main.Temp"))
    self.assertTrue(1 in loaded_model["Main"].Nodes)
    self.assertTrue(1 in loaded_model["Other"].Nodes)

    del(loaded_model)

    loaded_model_again = KratosMultiphysics.Model()
    serializer.Load("ModelSerialization",loaded_model_again)

I am not able to deserialize a second time the StreaSerializer object. I get the following error:
serializer.Load("ModelSerialization",loaded_model_again)
MemoryError: std::bad_alloc

For the parameters I get a similar problem when I deserealize a second time. In https://github.com/KratosMultiphysics/Kratos/blob/master/kratos/tests/test_kratos_parameters.py in the function "test_stream_serialization" I modify/add the following lines

    # ######## here we pickle the serializer
    # try:
    #     import cickle as pickle  # Use cPickle on Python 2.7
    # except ImportError:
    #     import pickle

    # #pickle dataserialized_data
    # pickled_data = pickle.dumps(serializer, 2) #second argument is the protocol and is NECESSARY (according to pybind11 docs)
    # del(serializer)

    #unpickle data - note that here i override "serialized_data"
    # serializer = pickle.loads(pickled_data)

    loaded_parameters = Parameters()
    serializer.Load("ParametersSerialization",loaded_parameters)

    loaded_parameters_again = Parameters()
    serializer.Load("ParametersSerialization",loaded_parameters_again)

to deserialize a second time the StreamSerializer Kratos object, and I get the following error:
The document is empty. offset of the error from the beginning of the string = 0

I attach the two files I modifed.

Serializer_errors.zip

Bug Help Wanted Testing

All 7 comments

Seems to be a not symmetric load and save. Can you try to construct the serializer with debug flag and see what it is saying?

What do you mean with debug flag?

Look for the call of FileSerializer(Filename) and add trace flag: SERIALIZER_TRACE_ALL in the constructor

Ex:

serializer = Kratos.FileSerializer("serialized_model.txt", Kratos.SERIALIZER_TRACE_ALL)

We did something similar 2 weeks ago when we were debugging the problem with the parameters.

is this still active?

Yep, still working on this

Btw this will be fixed when we #5071

@riccardotosi independently of tbis been solved i would avoid using neighbours in your algorithm. we ll discuss thjs in person

Was this page helpful?
0 / 5 - 0 ratings

Related issues

najianaslreza picture najianaslreza  路  7Comments

roigcarlo picture roigcarlo  路  7Comments

armingeiser picture armingeiser  路  6Comments

ipouplana picture ipouplana  路  6Comments

e-dub picture e-dub  路  3Comments