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

r.surf.fractal: Added seed option and -s flag to module #3480

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Shashankss1205
Copy link

Here is my proposed solution to the issue raised #1044.
I have written the code for adding seed and -s flag for reproducibility, along with a unit test for verifying it's functionality

@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python C Related code is in C module tests Related to Test Suite labels Mar 9, 2024
.vscode/settings.json Outdated Show resolved Hide resolved
# Set up temporary computational region
cls.use_temp_region()
# Only 100,000,000 seem to reasonably (not 100%) ensure that all values
# are generated, so exceeding of ranges actually shows up.
Copy link
Contributor

Choose a reason for hiding this comment

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

What kind of ranges you are referring to? I didn't see any range check. Usually a tiny computational region suffices to save on CI execution time.

Copy link
Author

Choose a reason for hiding this comment

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

Would you mind helping me with the test suite please, because I haven't previously worked with them and therefore I was struggling with how to write them.

Thanks @marisn

Copy link
Contributor

Choose a reason for hiding this comment

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

See for example test for r.random.cells and test documentation. Run r.surf.fractal first with certain fixed seed and save the raster statistics (computed with r.univar) for reference in the test. You can then use assertRasterFitsUnivar to ensure the test-generated raster with the same fixed seed will always give the same values. This type of test is not necessarily testing the output is correct, but it helps detect any regressions in the tool in the future and also that with a fixed seed you always get the same results.

Added the VS code settings by mistake, so removing them in this commit.
@neteler neteler changed the title r.surf.rfractal: Added seed option and -s fag to module r.surf.rfractal: Added seed option and -s flag to module Mar 10, 2024
Comment on lines 31 to 32
struct Option *seed;
struct Flag *s_flag;
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering, is the s-flag needed given that seed is optional?

Or is it added for consistency with current practice in other modules? Possibly redundand? If seed option is given, seed should be used, no?

And looking at the logic in lines 82 to 95 it seems that setting the s-flag has the same effect as not setting the s-flag...

So, maybe the s-flag can be dropped?

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked back at when this was introduced in r.mapcalc by Glynn:

My main objection to automatic seeding is that people will inevitably produce non-repeatable results without even realising it.

That's why user needs to choose -s flag or seed option explicitly. So the focus there was reproducibility. We could argue though that convenience is priority an in that case we could decide to drop the -s flag and not introduce it here.

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't following the development when the seed option was discussed for r.mapcalc. From an exterior point of view, the general trend of all software I have used yet that uses random numbers is that when you can set the seed, it is usually optional and for users who want know they want it reproducible. I almost always say it as an addition, not a requirement for just basic uses.

So, @Shashankss1205's interpretation is just like mine, and his implementation where not setting the -s flag results in a seed being generated, but with a warning with explanations, is my expected behaviour. Plus it doesn't break compatibility as well, and shows what was done. Maybe an even clearer message that makes the user aware and learn why setting a seed is wanted could be even better. If it's a pattern that we have for handling of -s flags, shouldn't these messages be common across GRASS and not specific to each module?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the consensus so far is that -s flag could be dropped. @Shashankss1205 could you please rewrite this without the -s flag?

Copy link
Member

Choose a reason for hiding this comment

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

+1 for dropping the s flag. Outside of this PR, but this will require making it optional wherever it is used.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I'll rewrite and send the code, my main aim was to keep the consistency of the previous code changes and abiding by the same rules. Will be happy to make the necessary changes.

Thank you for all of your's valuable insights.

Copy link
Author

Choose a reason for hiding this comment

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

Are there any suggestions related to the updated code, I think I have removed all occurences of -s_flag from my code, and also I wanted to seek some guidance on how to work further for getting into GSOC'24 with this organization.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! Please introduce yourself on grass-dev mailing list and let us know which idea you would like to work on so that we can further discuss it. See the tips on the idea page as well. You can also start drafting the application based on the template specified here.

@neteler neteler added this to the 8.4.0 milestone Mar 12, 2024
@wenzeslaus wenzeslaus changed the title r.surf.rfractal: Added seed option and -s flag to module r.surf.fractal: Added seed option and -s flag to module Mar 12, 2024
Copy link
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

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

Check the failed CI logs, r.surf.fractal is currently not compiling.

else {
/* default as it used to be */
seed_value = G_srand48_auto();
G_verbose_message(_("Warning set option seed. Generated "
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the first sentence and the "-s"

# Set up temporary computational region
cls.use_temp_region()
# Only 100,000,000 seem to reasonably (not 100%) ensure that all values
# are generated, so exceeding of ranges actually shows up.
Copy link
Contributor

Choose a reason for hiding this comment

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

See for example test for r.random.cells and test documentation. Run r.surf.fractal first with certain fixed seed and save the raster statistics (computed with r.univar) for reference in the test. You can then use assertRasterFitsUnivar to ensure the test-generated raster with the same fixed seed will always give the same values. This type of test is not necessarily testing the output is correct, but it helps detect any regressions in the tool in the future and also that with a fixed seed you always get the same results.

@petrasovaa
Copy link
Contributor

@Shashankss1205 do you plan to keep working on this? There is not that much missing (a simple test would suffice) and fixing the compilation error should be easy.

@wenzeslaus wenzeslaus modified the milestones: 8.4.0, Future Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants