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

Docs for manipulating and serializing schemas #27

Closed
jpfairbanks opened this issue May 17, 2023 · 4 comments
Closed

Docs for manipulating and serializing schemas #27

jpfairbanks opened this issue May 17, 2023 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@jpfairbanks
Copy link
Member

From a conversation with Nelson in ASKEM:

acset_schema expects an instance of the schema (a concrete database). I am using the default constructor to make an empty database. LabeledGraph{Symbol}() . In order to use a database that has attributes, you have to give it type parameters for those attribute types. so LabeledGraph{Symbol}()  is saying "make the empty LabeledGraph, where the labels are Symbols" you could replace Symbol with Any  and it will still work. 

Then you call acset_schema on that database instance (which has no rows in any of the tables) to get a basic schema. Which has the data you want.  You can just use it by indexing s.ob etc

julia> s = acset_schema(LabeledGraph{Symbol}())
BasicSchema{Symbol}([:V, :E], [(:src, :E, :V), (:tgt, :E, :V)], [:Label], [(:label, :V, :Label)])

julia> s.
attrs      attrtypes  homs       obs

s.homs is the edge list representation of the schema 

julia> s.homs
2-element Vector{Tuple{Symbol, Symbol, Symbol}}:
 (:src, :E, :V)
 (:tgt, :E, :V)

Then you can serialize s to json using the default serializer in JSON3
julia> JSON3.write(s)
"{\"obs\":[\"V\",\"E\"],\"homs\":[[\"src\",\"E\",\"V\"],[\"tgt\",\"E\",\"V\"]],\"attrtypes\":[\"Label\"],\"attrs\":[[\"label\",\"V\",\"Label\"]]}"

This should be in the docs somewhere.

@liunelson
Copy link

The workflow that I'm imagining from integration would involve either:

  • reading the string "LabelledPetriNet" from a model's schema (currently, there is only the URL to the framework schema "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/petrinet_v0.1/petrinet/petrinet_schema.json")
  • loading the model, having an instance of it in Catlab, and getting the framework name string "LabelledPetriNet"
model = read_json_acset(LabelledPetriNet, "model.json")
framework_name = acset_name(model)

(how to know that model.json is a LabelledPetriNet to make this call is another question)

Then, to get the schema of the framework associated with the given model, I'd do as you described:

s = acset_schema(constructor_for_LabelledPetriNet{Symbol}())
JSON3.write(s)

However, how do I get the constructor for a given model framework if all I have its string name framework_name?
i.e.

constructor_for_LabelledPetriNet = ???("LabelledPetriNet")

I can do this but I'd need to have loaded the model:

s = acset_schema(model)
JSON3.write(s)

@jpfairbanks
Copy link
Member Author

The name of a type is the constructor for that type. Given a string, if you want to look up what julia type that string refers to, I guess you could eval it. This doesn't handle the fact that you would need to have imported the right module into your namespace. For example eval("LabelledPetriNet") won't resolve unless you have done using AlgebraicPetri in your julia session.

But since this is related to designing software around schemas. It might be better if we just collected all the schemas and made a documentation page with the Catlab representation, edge list representation, and the graphviz drawing of the schema.

Trying to do this at runtime seems weird, since after you get this information, you are going to do human initiated software development to customize the application to the schema, right?

@liunelson
Copy link

The name of a type is the constructor for that type. Given a string, if you want to look up what julia type that string refers to, I guess you could eval it. This doesn't handle the fact that you would need to have imported the right module into your namespace. For example eval("LabelledPetriNet") won't resolve unless you have done using AlgebraicPetri in your julia session.

using AlgebraicPetri; eval("LabelledPetriNet") just returns the string itself. I don't understand what you mean by 'name of type = constructor of that type'.

A documentation page with the schemas etc. could be quite handy.

After we get this info, I think that's when the human user is going to start doing model operations (build, edit, transform, etc.) with constraints that we'd hypothetically infer from the schemas.

@jpfairbanks
Copy link
Member Author

I think you would have to put the parenthesis in there to get eval to try and call the constructor.

@epatters epatters transferred this issue from AlgebraicJulia/Catlab.jl May 30, 2023
@epatters epatters added the documentation Improvements or additions to documentation label May 30, 2023
@epatters epatters changed the title Add Docs for Manipulating and Serializing Schemas Docs for manipulating and serializing schemas May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants