The CSV files are sufficient to build a proof of concept. Given that sufficiency, and my lack of familiarity with SQL, perhaps I shouldn't focus on using sqlite for the MVP.
(See https://physicsderivationgraph.blogspot.com/2019/12/mvp-for-pdg-with-sql.html)
CSVs feel hacky and don't enable enforcement of consistency checks. However, they are easier to view and decrease the dependencies.
The easiest solution might be using Pickle (PKL) files rather than converting from Python variables in-memory to a distinct off-line representation. A Pickle file is enables consolidation.
Thursday, December 12, 2019
Wednesday, December 11, 2019
mathematical bases for inference rules
"add x to both sides" = addition property of equality
"multiply both sides by x" = multiplication property of equality
"divide both sides by x" = division property of equality
abstract syntax trees for expressions
https://tug.org/TUGboat/tb12-3-4/tb33arnon.pdf
https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.32.5712&rep=rep1&type=pdf
https://pdfs.semanticscholar.org/7214/d4805660042521d4b825eb3324742b215072.pdf
http://mathlex.org/doc/how-mathlex-works
https://calculem.us/abstract-binding-trees-1/
https://semantic-domain.blogspot.com/2015/03/abstract-binding-trees.html
https://arxiv.org/abs/1601.06298
https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.32.5712&rep=rep1&type=pdf
https://pdfs.semanticscholar.org/7214/d4805660042521d4b825eb3324742b215072.pdf
http://mathlex.org/doc/how-mathlex-works
https://calculem.us/abstract-binding-trees-1/
https://semantic-domain.blogspot.com/2015/03/abstract-binding-trees.html
https://arxiv.org/abs/1601.06298
MVP for PDG with SQL
Currently I have a Docker container that runs flask on Ubuntu to present a web interface that uses forms to enter information.
sandbox/docker_images/flask_ubuntu/web
A Python script on the backend handles conversion from string LaTeX to PNG using dvipng, with graphviz generating the static graph PNG.
The other major component of the backend is an sqlite3 database that holds the data when the container is offline. I don't have experience with SQL, so I need a plan to get to the minimum viable product.
The purpose of the sqlite3 file is to store the multiple tables offline. I could use a Python Pickle file, but that would be specific to Python; the sqlite approach seems more portable and generic.
The only actions I need are
SQL tables <--> Python data structures <--> graph structure <--> graph viz, website generation, UI web
On startup, read data into Python from sqlite.
After that, every time there is a change to the structure in Python, write to sqlite.
This approach is not elegant compared to "write only diff" or "write at end of session" but it eliminates any possibility of inconsistency.
This approach doesn't scale for large databases or multiple users, but those aren't problems I need to solve right now (I'm intentionally incurring technical debt).
If I'm using SQL to store data structures from Python, I'll need to enumerate the table schemas. See
https://allofphysicsgraph.github.io/proofofconcept/site/how_to_build_the_physics_derivation.html
which shows the tables
Reviewing the options described on
https://stackoverflow.com/questions/695752/how-to-design-a-product-table-for-many-kinds-of-product-where-each-product-has-m
I don't know which is applicable.
Motives for SQLite use:
sandbox/docker_images/flask_ubuntu/web
A Python script on the backend handles conversion from string LaTeX to PNG using dvipng, with graphviz generating the static graph PNG.
The other major component of the backend is an sqlite3 database that holds the data when the container is offline. I don't have experience with SQL, so I need a plan to get to the minimum viable product.
The purpose of the sqlite3 file is to store the multiple tables offline. I could use a Python Pickle file, but that would be specific to Python; the sqlite approach seems more portable and generic.
The only actions I need are
- write data structure from memory (in Python) to sqlite
- read data structure from sqlite into Python
SQL tables <--> Python data structures <--> graph structure <--> graph viz, website generation, UI web
On startup, read data into Python from sqlite.
After that, every time there is a change to the structure in Python, write to sqlite.
This approach is not elegant compared to "write only diff" or "write at end of session" but it eliminates any possibility of inconsistency.
This approach doesn't scale for large databases or multiple users, but those aren't problems I need to solve right now (I'm intentionally incurring technical debt).
If I'm using SQL to store data structures from Python, I'll need to enumerate the table schemas. See
https://allofphysicsgraph.github.io/proofofconcept/site/how_to_build_the_physics_derivation.html
which shows the tables
- per derivation
- edge list (expression local ID to inference local ID)
- expression identifiers (expression ID to local ID)
- feeds (latex to local ID)
- inference rule identifiers (inference rule to local ID)
- global expression latex to expression ID
- global inference rule to latex, description, CAS representation
Reviewing the options described on
https://stackoverflow.com/questions/695752/how-to-design-a-product-table-for-many-kinds-of-product-where-each-product-has-m
I don't know which is applicable.
Motives for SQLite use:
- enforce column consistency (each row has N columns)
- enforce column types (e.g., string, integer)
- enforce entry length (e.g., local ID must be an integer with M digits)
SQLite options
From the perspective of file management, having one file feels cleaner than a file per derivation.
5 tables in 1 SQLite file
One option is to implement 5 table schemas:- expression latex to expression ID. Columns:
- expression_latex (string)
- expression ID (integer)
- inference rule to latex, description, CAS representation
- inference rule (string)
- inference rule latex (string)
- inference rule description (string)
- CAS representation (string)
- derivation edges. Columns:
- derivation name (string)
- from local ID (integer)
- to local ID (integer)
- derivation feeds. Columns:
- derivation name (string)
- latex (string)
- local ID (integer)
- derivation expressions. Columns:
- derivation name (string)
- expression ID (integer)
- local ID (integer)
- derivation inference rules. Columns:
- derivation name (string)
- inference rule (string)
- local ID (integer)
2+3*D tables in 1 SQLite file
Two tables are independent of derivations:
- expression latex to expression ID. Columns:
- expression_latex (string)
- expression ID (integer)
- inference rule to latex, description, CAS representation
- inference rule (string)
- inference rule latex (string)
- inference rule description (string)
- CAS representation (string)
2 tables in 1 SQLite file; 3 tables in D SQLite files
Same as previous option, except instead of a single SQLite file, the derivations are in separate files.
SQLite to Python
These tables in SQL are equivalently stored in Python as three data structures:- list of inference rules = [{'inf rule':'inf rule 1','in':1, 'out': 0},{'inf rule':'inf rule 2', 'in':2, 'out': 3}]
- list of expressions = [{'expr 1':59285924, 'expr 2': 954849, 'expr 3': 948299}]
- dict of derivations = {'derivation name 1':[<step1>, <step2>, <step3>]}
where each <step> has the structure
{'inf rule': 'this inf rule',
input: [{'expr local ID': 942, 'expr ID': 59285924}],
output: [{'expr local ID': 218, 'expr ID': 954849}]}
Friday, August 9, 2019
updated task list for August 2019: SQL, arxiv
Since posting my previous task list in May I made good progress with Docker and a Flask-based web interface. The Flask web interface progressed far enough that I need to connect the front end with the SQL database backend. Listing out next steps,
A colleague found that Latex source for arxiv articles is available in bulk in S3 buckets. As an alternative to S3 arxiv points to a subset that's available without going through AWS: https://www.cs.cornell.edu/projects/kddcup/datasets.html
- The SQL database needs to be connected to the Flask-based web frontend
- The SQL database needs to be populated with content from the CSVs (expressions and inference rules and derivations in version 6)
A colleague found that Latex source for arxiv articles is available in bulk in S3 buckets. As an alternative to S3 arxiv points to a subset that's available without going through AWS: https://www.cs.cornell.edu/projects/kddcup/datasets.html
The value of having a large number of expressions in Latex is that we could use the expressions to predict what a user wants to enter, decreasing the amount of manual entry required. Also, if a derivation contains similar expressions to what exists in the arxiv content, we could investigate whether the derivation is related to the arxiv paper.
Sunday, July 28, 2019
improving efficiency of manually entered content
One of the major barriers to growth for the Physics Derivation Graph will be manual entry of expressions in support of derivations. Reducing "minor" inconveniences and adding "minor" help features can improve the user experience, the consistency of content, and the throughput of content creation.
As an example, for a given step in a derivation the user will need to specify the inference rule. Manually typing the name is laborious and induces cognitive burden. An "autocomplete" feature reduces labor but still requires thinking. A dropdown menu of all possible inference rules could be used, but a reduction to a dropdown with only relevant inference rules is better.
Similarly for manually entering expressions, autocompletion is helpful. Being able to specify which expression that has been previously entered is better.
A drag-and-drop interface for connecting nodes in the graph would be ideal.
As an example, for a given step in a derivation the user will need to specify the inference rule. Manually typing the name is laborious and induces cognitive burden. An "autocomplete" feature reduces labor but still requires thinking. A dropdown menu of all possible inference rules could be used, but a reduction to a dropdown with only relevant inference rules is better.
Similarly for manually entering expressions, autocompletion is helpful. Being able to specify which expression that has been previously entered is better.
A drag-and-drop interface for connecting nodes in the graph would be ideal.
Monday, June 3, 2019
SQL schema
Tables as bullets, columns per table as sub-bullets:
- expressions
- unique numeric ID
- Latex
- inference rules
- unique string name
- text expansion in Latex
- number of input arguments
- number of output arguments
- edge list
- source temp index
- destination temp index
- expression identifiers
- unique numeric ID
- temp index
- inference rule identifiers
- unique string name
- temp index
- feeds
- temp index
- Latex
Subscribe to:
Posts (Atom)