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

Gui options #25

Merged
merged 24 commits into from
Apr 28, 2020
Merged

Gui options #25

merged 24 commits into from
Apr 28, 2020

Conversation

johnomotani
Copy link
Collaborator

@johnomotani johnomotani commented Apr 26, 2020

Use Options objects to store options in HypnotoadGui. This means we can directly modify the user_options of the TokamakEquilibrium object when settings are changed.

  • Updated doc/whats-new.md with a summary of the changes

Only options defined in TokamakEquilibrium.default_options make sense to
set, so do not allow option names in options table to be edited.
Means the gui can modify a reference to the TokamakEquilibrium's
user_options object, so we can modify the options after self.eq is
constructed.
"_magic" is an internal implementation detail of the Options class, so
should not be modified by the user.
Call self.update_options_form() after setting
self.options=self.eq.user_options.
@johnomotani johnomotani removed the enhancement New feature or request label Apr 26, 2020
@johnomotani johnomotani mentioned this pull request Apr 26, 2020
1 task
hypnotoad/gui/gui.py Outdated Show resolved Hide resolved
hypnotoad/gui/gui.py Outdated Show resolved Hide resolved
hypnotoad/gui/gui.py Outdated Show resolved Hide resolved
Resulted from mistake when rebasing changes
@johnomotani
Copy link
Collaborator Author

@ZedThree could you mention the preferences dialog in whats-new.md and give yourself a credit?

@ZedThree
Copy link
Member

ZedThree commented Apr 27, 2020

The preferences dialog is "hand built", that is, it's not created automatically from the gui_options. This is so we can have the "appropriate" widget:

hypnotoad_preferences

I did this only because there's currently a small number of options. If we want to have lots of options here, this is where we want something like: https://github.com/learnpyqt/pyqtconfig

Also, it doesn't save settings between runs. That's a wishlist item :)

ZedThree and others added 4 commits April 27, 2020 14:57
If a self.mesh object has already been created in the gui, delete it
when loading a new geqdsk file, since we create a new self.eq, so the
existing self.mesh is invalid.

Also move statements out of the try/except block in read_geqdsk() that
do not need to be in there.
@johnomotani
Copy link
Collaborator Author

Plot window is now redrawn when the preferences dialog is closed. Also refactored the plotting into a single method to remove code duplicaction.

@ZedThree
Copy link
Member

Changing an option value no longer updates the equlibrium. I've been testing with a disconnected double null, and changing psinorm_sol to include/exclude the outer X-point no longer does anything after loading the geqdsk file.

hypnotoad/gui/gui.py Outdated Show resolved Hide resolved
hypnotoad/gui/gui.py Outdated Show resolved Hide resolved
@johnomotani
Copy link
Collaborator Author

Changing an option value no longer updates the equlibrium. I've been testing with a disconnected double null, and changing psinorm_sol to include/exclude the outer X-point no longer does anything after loading the geqdsk file.

I think the issue here is that when the self.eq object is created, the unnormalised options, e.g. psi_sol, are given values from psinorm_sol if they are None, which are saved in self.eq.options (which is self.options) and the unnormalised values are the ones actually used. So after reading the geqdsk file for the first time and creating self.eq the unnormalised values are set and then (as they are supposed to) override the normalised values. This is somewhere we could do with better handling of default values that should be equal to another option - other than implementing a better Options class, not sure what we can do. Workaround would be to revert the options (or re-load an input file) before running grid again, but then you have to manually re-apply any changes which is awful, but I don't see a simple fix...

Store the HypnotoadGui options in a dict, which contains only values
read from an input file or set by the user. This means that defaults can
be kept, and regenerated when the equilibrium or mesh objects are
recreated, since values changed by defaults in the internal options of
the equilibrium or mesh are not stored.
Previously passing an empty string caused a crash. Now reset the option
to its default value. Might be better to keep the old value, but don't
see a simple way of doing that.
Calls base Equilibrium class's updateOptions() and also updates some
more defaults.
Otherwise there are multiple layers that might contain an option, which
can cause problems when for example we want to do something like
'del eq.user_options[key]'.
Need to only ever call the Equilibrium method, never a method of a
subclass.
@johnomotani
Copy link
Collaborator Author

As discussed on Slack, HypnotoadGui now uses a dict again to store the options, and stores only the ones that have been changed either by the user or reading an input file. This allows all default values to be re-applied consistently when options are updated.

johnomotani and others added 4 commits April 27, 2020 19:52
Adds a checkbox in the GUI's Preferences dialog which if checked saves
all options when writing the options to YAML.
Should not make a difference, but deepcopy is safer than shallow copy.
@ZedThree
Copy link
Member

@johnomotani I hope 1d6f758 is ok, I was getting things like _magic: {} in the saved file.

I like how default options are displayed now. 3662725 removes (default) from the text when the user double clicks. It's not magic enough to put it back if the text is unchanged, which is a little annoying.

@johnomotani
Copy link
Collaborator Author

Looks good to me! Thanks @ZedThree

@johnomotani johnomotani merged commit eda04bb into master Apr 28, 2020
@johnomotani johnomotani deleted the gui-Options branch April 28, 2020 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants