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

model serialisation #23

Open
NaweedAghmad opened this issue Apr 12, 2022 · 4 comments
Open

model serialisation #23

NaweedAghmad opened this issue Apr 12, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@NaweedAghmad
Copy link
Collaborator

Serialize all model rules and facts reflective of model.print

@NaweedAghmad NaweedAghmad added enhancement New feature or request good first issue Good for newcomers labels Apr 12, 2022
@mikulatomas
Copy link
Contributor

mikulatomas commented Apr 13, 2022

Do we want human-readable serialization like json or byte-like one? (EDIT: or which one is preferred as first one)

@NaweedAghmad
Copy link
Collaborator Author

We can start with byte-code, having the ability to dump and load a model is more important than having the dump human-readable right now.

@mikulatomas
Copy link
Contributor

mikulatomas commented Apr 16, 2022

Simple usage example and API proposition:

from lnn import Predicate, Variable, And, Model, Fact

model = Model()

x = Variable("x")

p1 = Predicate(name="p1")
p2 = Predicate(name="p2")

formula = And(p1(x), p2(x))

model.add_formulae(p1, p2, formula)

model.add_facts(
    {"p1": {"a": Fact.TRUE, "b": Fact.FALSE}, "p2": {"a": Fact.FALSE, "b": Fact.FALSE}}
)

model.infer()

model.save("my_model")

loaded_model = Model.from_file("my_model")

assert model == loaded_model

@NaweedAghmad Possible problem is that we do not have __eq__ implemented for Model class, so not sure about the assert statement.

The Model.from_file is @classmethod and they can be understand as alternative constructors. Alternative name can be Model.load.

@anomius
Copy link

anomius commented Aug 13, 2022

Would Pickle Work Like:

def save(self, filename):
    with open(filename, 'wb') as outp:  # Overwrites any existing file.
        pickle.dump(self, outp, pickle.HIGHEST_PROTOCOL)

def from_file(self,filename):
    with open(filename, 'rb') as inp:
        return pickle.load(inp)
    

if so i would be happy to contribute @NaweedAghmad

@NaweedAghmad NaweedAghmad removed the good first issue Good for newcomers label Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants