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

JSON Solution Save and Diff Save Format #1552

Open
Alexander-Da-Great opened this issue Jul 29, 2021 · 2 comments
Open

JSON Solution Save and Diff Save Format #1552

Alexander-Da-Great opened this issue Jul 29, 2021 · 2 comments

Comments

@Alexander-Da-Great
Copy link
Contributor

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:

json_diff_string = self.diff(pickledsol, ..., JSON=true)

json_diff_string = { array(Variables that have changed), array(Variables under Absolute Only), 
                     array(Variables under Relative Only), dict(Absolute Changes), dict(Relative Changes) }

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:

json_sol_string = sol.savejson()

json_sol_string = { array(Variables), dict(Values) }

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.

@whoburg
Copy link
Collaborator

whoburg commented Jul 29, 2021

I like this idea. Making it easier for web apps to use GPkit is a good thing.

@bqpd
Copy link
Contributor

bqpd commented Jul 30, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants