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

Add example_obj_lib.py file using objects from tutorial.ipynb and use in main script #151

Closed
spencerahill opened this issue Mar 8, 2017 · 11 comments

Comments

@spencerahill
Copy link
Owner

Essentially just copy and paste the object definitions in examples.ipynb into a separate .py file that is itself a functional aospy object library. That way users have a direct example of a working object library file from the outset that they can copy elsewhere and manipulate, rather than having to cut and paste from a notebook.

Also, we should populate the main script with this object library, such that users can submit the main script and execute example calculations immediately upon installing aospy.

@spencerahill spencerahill added this to the v0.1.2 milestone Mar 8, 2017
@spencerahill spencerahill changed the title Add examples.py file using objects from example.ipynb and use in main script Add example_obj_lib.py file using objects from example.ipynb and use in main script Mar 17, 2017
@spencerahill spencerahill changed the title Add example_obj_lib.py file using objects from example.ipynb and use in main script Add example_obj_lib.py file using objects from tutorial.ipynb and use in main script Mar 17, 2017
@spencerahill
Copy link
Owner Author

Re-opening because, although #155 created the example_obj_lib.py file, I haven't yet updated the notebook (which I will rename from example.ipynb to tuotiral.ipynb) to use this package.

@spencerahill spencerahill reopened this Mar 25, 2017
@spencerahill
Copy link
Owner Author

spencerahill commented Mar 28, 2017

(edited for clarity)

Slight hiccup: the examples section of the docs, which gets compiled with $CWD being aospy/docs, is unable to do import example_obj_lib, because the latter is located in aospy/aospy/examples. A workaround is to cd to the examples directory.

This is because example_obj_lib.py is not technically included in aospy (via __init__.py) nor has it been installed otherwise, so it can only be imported from that directory. Unless there's a way to import modules not on PYTHONPATH from directories other than the current one?

Another option: this could be avoided if we explicitly included the example library in aospy: aospy.examples.example_obj_lib.

@spencerkclark any thoughts? Hope I'm being clear enough.

@spencerkclark
Copy link
Collaborator

@spencerahill are you referring to this page? http://aospy.readthedocs.io/en/latest/examples.html

@spencerkclark
Copy link
Collaborator

Are you trying to add an example of using the main script there (which I assume would benefit from using example_obj_lib)? I just want to make sure I understand, because while it needs to be updated for the updated calc.py, currently that page does not rely on example_obj_lib.

@spencerkclark
Copy link
Collaborator

spencerkclark commented Mar 28, 2017

Could creating a symbolic link to example_obj_lib.py in aospy/docs work?

(aospy-dev) bash-4.1$ ln -s ../aospy/examples/example_obj_lib.py example_obj_lib.py
(aospy-dev) bash-4.1$ ipython
Python 3.6.0 | packaged by conda-forge | (default, Feb  9 2017, 14:36:55)
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import example_obj_lib

That feels kind of hacky though. What do you think?

@spencerahill
Copy link
Owner Author

Are you trying to add an example of using the main script there (which I assume would benefit from using example_obj_lib)

Yes, or at least example_obj_lib and submit_mult_calcs. The problem is that, even if I re-define all of the needed objects locally within the examples page, an object library is required for the calc_suite_specs['library'] field. (This is what motivated #163; then we could just define the ObjLib object locally and not have this problem.)

Nice idea re: symbolic link. Another option is interactively adding the examples directory to PYTHONPATH via os (or maybe sys).

@spencerahill
Copy link
Owner Author

The least hack-ish option to me is to actually add example_obj_lib.py to aospy via aospy.__init__, such that it's accessible via from aospy.examples import example_obj_lib. I would keep the examples layer, rather than aospy.example_obj_lib, because that keeps the top-level namespace cleaner and allows us to add more examples later in a clean way if we want.

We could also include aospy_main.py, although I don't see the benefit, since we don't need anything from it in the same way we need example_obj_lib here.

@spencerkclark
Copy link
Collaborator

I agree; I think doing that would be perfectly fine.

We could also include aospy_main.py, although I don't see the benefit, since we don't need anything from it in the same way we need example_obj_lib here.

Yeah, I say hold off on adding anything else until we explicitly need it.

@spencerahill
Copy link
Owner Author

@spencerkclark perfect, going this route.

@spencerkclark
Copy link
Collaborator

@spencerahill also there are a couple spots in the tutorial notebook that need to be changed now that it's been moved to a new directory. I can create a pull request tomorrow if you'd like.

@spencerahill
Copy link
Owner Author

@spencerkclark I noticed some also. I'll have a PR in by the end of the night; feel free to push anything that I missed once it's up.

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

No branches or pull requests

2 participants