Sunday, February 2, 2020

significant changes to the Physics Derivation Graph

This weekend I initiated a significant rewrite of the Physics Derivation Graph.
  • I revised the data structures, the level of details present in the data structure, and how the data structure is accessed. 
  • I also better understand the model-view-controller paradigm; this led to a better workflow. 
  • I improved the logging used in the Python code.

Improved Data Structures

I've investigated many different file formats (XML, CSV, plain text, SQL), each of which impose different constraints on the data structure, as well as imposing a translation between the file format and the representation internal to Python. I recently arrived at the insight that I could avoid both file format choices and the associated translation work by using Python's serialization -- the pickles module.

In addition to eliminating work associated with translation, it freed my cognitive focus. This second aspect was vital as it led to improved mental agility in analyzing other options. Once I didn't have to worry about choosing the best file format, I could identify what work would lead to rapid progress. 

The first big change was having a single data structure (the dictionary "dat") which had all the other data structures (expressions, inference rules, derivations) as keys. Each of those was initially a list of dictionaries, but this proved to be cumbersome in implementing data access. I realized I could leverage the unique identifiers present in the Physics Derivation Graph as keys. That lead to a dictionary (top level "dat") of dictionaries (expressions, inference rules, derivations) of dictionaries (each expression, each inference rule, each derivation, respectively). While this may sound messy, accessing specific elements of the PDG is now much easier. 

Motivated by a conversation about how the PDG will integrate with a Computer algebra system, I decided to include a few additional keys in the top level data structure. Enabling validation of steps requires supporting a computer algebra system (CAS). To enable an arbitrary choice of CAS, I need to support abstract syntax trees (ASTs). To enable an AST, I need to define symbols and operators. To enable symbols, I need units and measures. To summarize, I now track the following:

  • derivations
  • expressions
    • latex
    • AST
  • inference rules
  • symbols
  • operators
  • units
  • measures

Improved understanding of the model-view-controller paradigm

Previously I had web form actions that led to a follow-on page. While technically possible, this turned out to be a bad decision. The problems are in tracking state (which variables get passed between pages) and poor visibility on the state changes. I updated the web forms to pass their action back to the "controller.py" which maintains both the variable passing and flow control (which page calls another page).

By adhering to the model-view-controller paradigm, troubleshooting and implementation were made much easier. This ease resulted in faster implementation of ideas. 

Improved logging in Python

I use print statements throughout my code to help in troubleshooting. There are different categories of print statements: trace, debug, error. These are now present in (almost) every print statement. I've also included the name of the file (either "compute" or "controller") in print statements, as well as the function the print statement is in. These changes help track the state of the application. 

Monday, December 30, 2019

Use of MathJax for expressions

Now that I've migrated my interface to Flask web page hosted in a Docker container, I could use MathJax to display LaTeX expressions.

http://localhost:5000/list_all_expressions could use MathJax

Automated web interface testing


https://robotframework.org/
 is better than Selenium because it produce reports

UML to Python Flask and WTForms

UML to Python Flask and WTForms rather than iterative form development

lesson learned for model-view-controller: form workflows

Model-view-controller (MVC) is a way to separate presentation from the backend computation and data transformation.

For my application, "model" = compute.py; "view" = a collection of webpages; "controller" = controller.py

MVC nuances with Flask and WTForms --

  • The business logic workflow is captured exclusively in controller.py
  • Upon form submission the workflow should return back to controller.py rather than linking to next page. The controller.py uses redirect(url_for()) to transition between pages.
  • Form data extraction occurs in the controller; manipulations to the form data are made in compute.py (the model). 

Using OCaml to identify equivalent expressions

OCaml: simplify expressions to basis for equivalence class
LaTeX --> OCaml AST, then compare against all other OCaml ASTs

Scope is for +, -, * for integers
Next steps would be expand to real, then complex

Use case: find other equivalent expressions

Use case: validation

This requires typed variables (eg int, real, constant, real, complex, matrix, vector

Rules:
  • addition rule of equality
  • multiplication rule of equality
  • substitution property of equality
  • associative property
  • commutative property
  • transitive property
  • symmetric property
  • additive inverse property

Wednesday, December 25, 2019

when to use a dropdown menu versus list of links in the web interface

For the web interface, there are multiple pages that have a list from which a user can select. One way to render the list would be a set of hyperlinks; another way would be a dropdown menu.

Suppose the user needs to select an inference rule for a step. They should only chose one, so a dropdown is the preferred method.
--> when the user should be restricted to one option, use a dropdown menu.

Suppose the user is presented with a list of derivations to view. They could chose one or more (to open in new tabs), so a list is the preferred method.
--> when the user can chose one or more options, use a dynamically generated list of hyperlinks.