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

Implement changes to make low level splishsplash simulation API call more usable #23

Merged
merged 15 commits into from
Mar 1, 2023

Conversation

luispcunha
Copy link
Contributor

@luispcunha luispcunha commented Feb 24, 2023

In this PR, the suggestions made by @fabiocruz are followed in order to make the run_simulation method more user-friendly.
The changes bowl down to:

  • allow specifying a different directory for the outputs.
  • having a better type annotation for the input of the method.

Closes #33.

@luispcunha
Copy link
Contributor Author

@begaiym-k @sarmento @hpenedones I add the simulation class for splish splash. Check the demos/splishasplash_execution.py file to see what the user interaction looks like. Wdyt?

flags.DEFINE_string("output_dir",
None,
"Directory where the outputs will be stored.",
required=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using flags.mark_flags_as_required instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will not have to set required inside each flag, and it visually looks better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using the argument required=True in each flag. IMO it's easier to read since the information about a flag being required or not is closer to its name, description, default value, etc.

None,
"Directory with the simulation inputs.",
required=True)
flags.DEFINE_string("input_file", None, "Input file.", required=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not assuming that the input file is inside the sim_dir directory already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is actually to tell the name of the file inside the directory. I will make that more explicit. I think it is better to not constrain the user to use a specific filename and allow the user to specify the name of the input file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Yes, a more explicit describtion is needed.

sim_output_path = inductiva.sph.run_simulation(
DirPath(input_temp_dir.name))
simulation._output_directory = sim_output_path.path #pylint: disable=protected-access
sim_output_path = inductiva.sph.splishsplash.run_simulation(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add simulation output directory as an optional parameter, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to .simulate() ?
yes, I think it is a good idea.

Copy link
Contributor

@fabiocruz fabiocruz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I have minor-ish comments only.

demos/dambreak_simulation.py Show resolved Hide resolved
flags.DEFINE_string("output_dir",
None,
"Directory where the outputs will be stored.",
required=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using the argument required=True in each flag. IMO it's easier to read since the information about a flag being required or not is closer to its name, description, default value, etc.

demos/splishsplash_simulation.py Show resolved Hide resolved
inductiva/fluids/scenarios/dam_break.py Outdated Show resolved Hide resolved
inductiva/fluids/splishsplash.py Show resolved Hide resolved
directory.
"""

def __init__(self, sim_dir: Path, input_file_name: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO input_file_name (or input_filename) should have a default value, e.g. splishsplash_input.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that default value to run_simulation. Tbh I think it is a bit weird to have a default value for a file name that is provided by the user. If the user provides the file, then it should explicitly specify the name.
There wouldn't be an intuitive and self-contained way inside the code to tell the user that he should name the input file "splishsplash_input.json".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think though that it is equally weird to have a default value here and on run_simulation... Not having a default value here will force the user (e.g. me ahah) to always write input_filename="splishsplash_input.json".

But that's ok, we can work without a default value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added the default value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 Thank you!

inductiva/sph/splishsplash.py Outdated Show resolved Hide resolved
inductiva/utils/data.py Outdated Show resolved Hide resolved
Comment on lines +167 to +168
if var_type == pathlib.Path:
return pathlib.Path(os.path.join(output_dir, value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we checking some types against inductiva.types.Path and others against pathlib.Path? Shouldn't we try to use only one type do describe paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My perspective is:

  • input types: be as broad as possible, so that the user is not constrained to use pathlib.Path and can also use strings or other things.
  • output types: be as specific as possible, so that the user knows exactly what it receives (receiving a pathlib.Path is different than receiving a str)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let's write it in some documentation in the future, maybe when writing #34?

None,
"Directory with the simulation inputs.",
required=True)
flags.DEFINE_string("input_file_name",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should name this input_filename, for consistency with the output_filename used in other files of the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would introduce changes in the other repository, do you think it's worth it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, consistency is definitely worth it! It saves us (or at least it saves me...) a lot of time when reading code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luispcunha luispcunha merged commit 2dc56f9 into main Mar 1, 2023
@luispcunha luispcunha deleted the lpc-improve-run-sim branch March 1, 2023 12:15
import os
from typing import TypeAlias, Union

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I come later to the party, sorry!
Good that we deleted this DirPath class, because:

  • why Inductiva would need to define its own classes to deal with paths? Are we different from the millions of python developers in the world, with respect to paths to files or folders?

I would go a step further and question the existence of this types.py file ... even though it's now simpler because it is just a TypeAlias , the same questions applies: why did the millions of developers dealing with python, filepaths etc, use the standard types and we need to define a new one?

If it is to solve an implementation issue downstream, probably that means that the mechanism downstream needs to be written in a different manner with different assumptions, but it can't work based on the fact that we defined a new Path type...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no standard type for Paths (https://peps.python.org/pep-0519/#provide-specific-type-hinting-support). If you look into the type annotation of open(), it is also a complicated TypeAlias with a Union of a bunch of types.

Fábio (the user) wanted to be able to pass the path as both a string, or as a pathlib.Path, so creating a typealias in order to not write a union everytime is better.

But yes, downstream we also use the type annotation in order to know how to pack the data correctly. we can thing of a different of doing that...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @luispcunha for the additional context, you can push back on the user request from @fabiocruz ! :) We are not yet able to run simulations in a stable manner and efficiently, and there are many P0 requests, do we believe that supporting multiple types to specify paths is a priority and it justifies increasing the code complexity to the point of creating new modules / files ??  

@fabiocruz : next time please open feature request as an issue and we will prioritize it on our meetings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this was done that system still wasn't in place.
That will still be a problem, because right now we rely on the type annotation to know that the argument is a directory and that we need to include that directory in the zip that we send to the API. So just removing this doesn't solve the issue.
A possible solution would be to use pathlib.Path as the type, and then checking if the path points to a directory. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @luispcunha for the additional context, you can push back on the user request from @fabiocruz ! :) We are not yet able to run simulations in a stable manner and efficiently, and there are many P0 requests, do we believe that supporting multiple types to specify paths is a priority and it justifies increasing the code complexity to the point of creating new modules / files ??  

@fabiocruz : next time please open feature request as an issue and we will prioritize it on our meetings?

@hpenedones this came from the prioritization defined in last week's meeting. I was supposed to identify how we could launch SPH simulations with a low-level interface and user pain points. I did that and coordinated with @luispcunha and @begaiym-k to implement the required changes.

Sorry that we didn't create an issue and discuss it before implementation took place. Issues are a recent practice here :-) Will document feature requests better from now on.

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.

Add support for lower level call of splishsplash
4 participants