From 8571a09103e1be6dba6c299882b73a1e399d3061 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 27 Sep 2023 12:05:32 -0400 Subject: [PATCH] Create SummationDecapode.json (#33) * Create SummationDecapode.json * Update SummationDecapode.json fill in title and description fields * use ty key in SummationDecapode.json * Export to jsonschema * Update setup.cfg * Update conf.py * Update conf.py * Update --------- Co-authored-by: Charles Tapley Hoyt --- docs/source/conf.py | 2 +- setup.cfg | 3 +- .../schemas/catlab/SummationDecapode.json | 154 ++++++++++++++++++ src/acsets/schemas/catlab_to_jsonschema.py | 40 +++++ .../schemas/jsonschema/SummationDecapode.json | 148 +++++++++++++++++ 5 files changed, 344 insertions(+), 3 deletions(-) create mode 100644 src/acsets/schemas/catlab/SummationDecapode.json create mode 100644 src/acsets/schemas/catlab_to_jsonschema.py create mode 100644 src/acsets/schemas/jsonschema/SummationDecapode.json diff --git a/docs/source/conf.py b/docs/source/conf.py index 19a7f90..5f9a55c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -226,7 +226,7 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - "https://docs.python.org/3/": None, + "python": ("https://docs.python.org/3/", None), } autoclass_content = "both" diff --git a/setup.cfg b/setup.cfg index 5e08d07..552b740 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,8 +49,7 @@ keywords = [options] install_requires = - pydantic - # TODO your requirements go here + pydantic<2.0 # Random options zip_safe = false diff --git a/src/acsets/schemas/catlab/SummationDecapode.json b/src/acsets/schemas/catlab/SummationDecapode.json new file mode 100644 index 0000000..4af1a3f --- /dev/null +++ b/src/acsets/schemas/catlab/SummationDecapode.json @@ -0,0 +1,154 @@ +{ + "version": { + "ACSets": "0.0.0", + "Catlab": "0.0.0", + "ACSetSchema": "0.0.1" + }, + "Ob": [ + { + "name": "Var", + "description": null, + "title": "Variable" + }, + { + "name": "TVar", + "description": null, + "title": "Tangent Variable" + }, + { + "name": "Op1", + "description": null, + "title": "Unary Operation" + }, + { + "name": "Op2", + "description": null, + "title": "Bianry Operation" + }, + { + "name": "Σ", + "description": null, + "title": "Summation" + }, + { + "name": "Summand", + "description": null, + "title": "Summand" + } + ], + "Hom": [ + { + "name": "src", + "codom": "Var", + "dom": "Op1", + "description": null, + "title": "Source" + }, + { + "name": "tgt", + "codom": "Var", + "dom": "Op1", + "description": null, + "title": "Target" + }, + { + "name": "proj1", + "codom": "Var", + "dom": "Op2", + "description": null, + "title": "First Argument" + }, + { + "name": "proj2", + "codom": "Var", + "dom": "Op2", + "description": null, + "title": "Second Argument" + }, + { + "name": "res", + "codom": "Var", + "dom": "Op2", + "description": null, + "title": "Result" + }, + { + "name": "incl", + "codom": "Var", + "dom": "TVar", + "description": null, + "title": "Inclusion of Tangent Variables" + }, + { + "name": "summand", + "codom": "Var", + "dom": "Summand", + "description": null, + "title": "summand" + }, + { + "name": "summation", + "codom": "Σ", + "dom": "Summand", + "description": null, + "title": "summation" + }, + { + "name": "sum", + "codom": "Var", + "dom": "Σ", + "description": null, + "title": "result of summation" + } + ], + "AttrType": [ + { + "name": "Type", + "description": "The DEC type of a variable, not a python type", + "title": "Variable Type", + "ty": "str" + }, + { + "name": "Operator", + "description": "The DEC operator name", + "title": "Operator", + "ty": "str" + }, + { + "name": "Name", + "description": null, + "title": "Name", + "ty": "str" + } + ], + "Attr": [ + { + "name": "op1", + "codom": "Operator", + "dom": "Op1", + "description": null, + "title": "Operation" + }, + { + "name": "op2", + "codom": "Operator", + "dom": "Op2", + "description": null, + "title": "Binary Operation" + }, + { + "name": "type", + "codom": "Type", + "dom": "Var", + "description": null, + "title": "Variable Type" + }, + { + "name": "name", + "codom": "Name", + "dom": "Var", + "description": null, + "title": "Variable Name" + } + ] +} diff --git a/src/acsets/schemas/catlab_to_jsonschema.py b/src/acsets/schemas/catlab_to_jsonschema.py new file mode 100644 index 0000000..544bdbf --- /dev/null +++ b/src/acsets/schemas/catlab_to_jsonschema.py @@ -0,0 +1,40 @@ +"""This script turns all the catlab schemata into json schemata""" + +from pathlib import Path +from acsets import ( + CATLAB_SCHEMAS_DIRECTORY, + ACSet, + Attr, + AttrType, + CatlabSchema, + Hom, + Ob, + petris, + Schema, +) + +HERE = Path(__file__).parent.resolve() +CATLAB = HERE.joinpath("catlab") +JSONSCHEMA = HERE.joinpath("jsonschema") + + +def main(): + """Convert any Catlab schemas into JSON schemas""" + for catlab_path in CATLAB.glob("*.json"): + jsonschema_path = JSONSCHEMA.joinpath(catlab_path.name) + if jsonschema_path.is_file(): + continue + print(f"Parsing Catlab Schema from {catlab_path}") + catlab_schema = CatlabSchema.parse_file(catlab_path) + print("Getting Schema from Catlab schema") + schema = Schema.from_catlab(catlab_path.name, catlab_schema) + schema.write_schema( + jsonschema_path, + uri="https://raw.githubusercontent.com/AlgebraicJulia/py-acsets/main/src/acsets/{}".format( + Path(jsonschema_path).relative_to(HERE) + ), + ) + + +if __name__ == "__main__": + main() diff --git a/src/acsets/schemas/jsonschema/SummationDecapode.json b/src/acsets/schemas/jsonschema/SummationDecapode.json new file mode 100644 index 0000000..b1a8689 --- /dev/null +++ b/src/acsets/schemas/jsonschema/SummationDecapode.json @@ -0,0 +1,148 @@ +{ + "$id": "https://raw.githubusercontent.com/AlgebraicJulia/py-acsets/main/src/acsets/jsonschema/SummationDecapode.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "Op1": { + "properties": { + "op1": { + "title": "Op1", + "type": "string" + }, + "src": { + "title": "Src", + "type": "integer" + }, + "tgt": { + "title": "Tgt", + "type": "integer" + } + }, + "title": "Op1", + "type": "object" + }, + "Op2": { + "properties": { + "op2": { + "title": "Op2", + "type": "string" + }, + "proj1": { + "title": "Proj1", + "type": "integer" + }, + "proj2": { + "title": "Proj2", + "type": "integer" + }, + "res": { + "title": "Res", + "type": "integer" + } + }, + "title": "Op2", + "type": "object" + }, + "Summand": { + "properties": { + "summand": { + "title": "Summand", + "type": "integer" + }, + "summation": { + "title": "Summation", + "type": "integer" + } + }, + "title": "Summand", + "type": "object" + }, + "TVar": { + "properties": { + "incl": { + "title": "Incl", + "type": "integer" + } + }, + "title": "TVar", + "type": "object" + }, + "Var": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "type": { + "title": "Type", + "type": "string" + } + }, + "title": "Var", + "type": "object" + }, + "_": { + "properties": { + "sum": { + "title": "Sum", + "type": "integer" + } + }, + "title": "Σ", + "type": "object" + } + }, + "properties": { + "Op1": { + "items": { + "$ref": "#/definitions/Op1" + }, + "title": "Op1", + "type": "array" + }, + "Op2": { + "items": { + "$ref": "#/definitions/Op2" + }, + "title": "Op2", + "type": "array" + }, + "Summand": { + "items": { + "$ref": "#/definitions/Summand" + }, + "title": "Summand", + "type": "array" + }, + "TVar": { + "items": { + "$ref": "#/definitions/TVar" + }, + "title": "Tvar", + "type": "array" + }, + "Var": { + "items": { + "$ref": "#/definitions/Var" + }, + "title": "Var", + "type": "array" + }, + "Σ": { + "items": { + "$ref": "#/definitions/_" + }, + "title": "Σ", + "type": "array" + } + }, + "required": [ + "Var", + "TVar", + "Op1", + "Op2", + "Σ", + "Summand" + ], + "title": "SummationDecapode.json", + "type": "object" +} \ No newline at end of file