Open Alexander-Da-Great opened 3 years ago
I like this idea. Making it easier for web apps to use GPkit is a good thing.
@Alexander-Da-Great, this looks great! JSON solutions seem like they could be made pretty directly from the solution dictionary with some good use of JSONencoder, but the diffing will require generalizing SolutionArray.diff a bit, adding a function that returns the various differences and changing the diff method to use it.
A feature I discussed with @pgkirsch.
As noted in the docs, tracking the changes to complex models is aided by the ability to save solutions. In particular, the ability to save solutions via sol.savetxt() has been very useful for analyzing "mid-sized" complex models. However, as the scale of the model increases these txt files can become incredibly cumbersome to read. Pickling solutions and creating diff files to analyze changes has been incredibly useful, but when thousands of variables are changing it is difficult to debug.
Certain data visualization tools within gpkit, such as the reference plots, are very effective for understanding the results of complex models and benefit from json file formats. In an effort to do more with data visualization, I have been parsing diff strings and generating my own json files to use in web apps. It would be great if there were a sol.savejson() option for solution saving and an additional parameter to sol.diff() for json file output.
Potential Avenues for JSON file saving:
JSON diffs:
For the diff json string it would be useful to have arrays for the sets of variables that would traditionally appear under the absolute and relative differences section of the diff txt files. The dictionaries to store the changes would ideally contain keys of variable names and values with both the value and unit of the change/variable.
JSON sols:
For the solutions json files I was thinking we could have something simple like an array of variable names and a dictionary that contains variable name keys and values with the value from the solution as well as its units.
Hopefully this seems like a useful addition to gpkit. I think that it would make gpkit more friendly to web apps and enable more data visualization while developing larger / complex models. I would love to hear more about the implementation of these jsons as well as how to improve / flesh out these ideas. I assume there will be issues with vectorized variables and maybe a few other edge cases.