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

Export data with TXTExport into single file #628

Merged
merged 26 commits into from
Nov 4, 2023

Conversation

KulaginVladimir
Copy link
Collaborator

@KulaginVladimir KulaginVladimir commented Nov 2, 2023

Proposed changes

This PR modifies TXTExport according to #623.

For steady-state simulations, it produces 'FileLabel_steady.txt' with header: 'x,t=steady' in it. For transient simulations, it produces 'FileLabel_transient.txt' with header: 'x,t=Time[0]s,t=Time[1]s,..' where T corresponds either to times passed to TXTExport or all timesteps, if times is None.

I also modified previous tests to catch the updated TXTExport and added some new.

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Update tests to check new TXTExport
Update tests for new TXTExport
Update tests for new TXTExport
Black format
Black format
Copy link
Collaborator

@jhdark jhdark left a comment

Choose a reason for hiding this comment

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

Hey @KulaginVladimir Congrats on your first PR 🚀. It looks great so far, just some minor refactoring things from me. I think @RemDelaporteMathurin has some comments to make too, just to potentially simplify things. Otherwise welcome! Thanks for the contribution, should be able to get this through soon without too much modification

festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
else:
return True if np.isclose(self.times[0], current_time) else False

def write(self, current_time, nb_iteration, steady):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could do with some doc strings here

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's partly on us but yes I agree!

festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
Comment on lines 124 to 142
def test_txt_export_desired_times(tmp_path):
"""
Tests that TXTExport can be exported at all timesteps
"""
my_model = F.Simulation()

my_model.mesh = F.MeshFromVertices(np.linspace(0, 1))
my_model.materials = F.Material(1, 1, 0)
my_model.settings = F.Settings(1e-10, 1e-10, final_time=1)
my_model.T = F.Temperature(500)
my_model.dt = F.Stepsize(0.1)

my_export = F.TXTExport(
"solute", label="mobile_conc", times=[0.2, 0.5], folder=tmp_path
)
my_model.exports = [my_export]

my_model.initialise()
my_model.run()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is a way to test the export without having to make a system test? but I'm not sure on this

Copy link
Collaborator

Choose a reason for hiding this comment

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

There must be a way to just call write() but I don't know if it's worth it, this does the trick

@@ -105,3 +123,33 @@ def test_there_is_a_next_time(self, my_export):
def test_last(self, my_export):
assert my_export.when_is_next_time(3) is None
assert my_export.when_is_next_time(4) is None


class TestIsItFirstTimeToExport:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could do with some doc strings here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Kinda hard to document a test class, you can document the test functions however.

Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

Hi @KulaginVladimir thanks for this PR! First of many I hope! 🎉

This is a very good quality of life feature!

I have a few comments, the main one being refactoring this by replacing the is_first_time_to_export method by a class attribute.
I'll make another PR to your branch that you can then merge to add the changes here ( ie no need to close this PR and make a new one).

else:
return True if np.isclose(self.times[0], current_time) else False

def write(self, current_time, nb_iteration, steady):
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's partly on us but yes I agree!

festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
Comment on lines 124 to 142
def test_txt_export_desired_times(tmp_path):
"""
Tests that TXTExport can be exported at all timesteps
"""
my_model = F.Simulation()

my_model.mesh = F.MeshFromVertices(np.linspace(0, 1))
my_model.materials = F.Material(1, 1, 0)
my_model.settings = F.Settings(1e-10, 1e-10, final_time=1)
my_model.T = F.Temperature(500)
my_model.dt = F.Stepsize(0.1)

my_export = F.TXTExport(
"solute", label="mobile_conc", times=[0.2, 0.5], folder=tmp_path
)
my_model.exports = [my_export]

my_model.initialise()
my_model.run()
Copy link
Collaborator

Choose a reason for hiding this comment

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

There must be a way to just call write() but I don't know if it's worth it, this does the trick

@@ -105,3 +123,33 @@ def test_there_is_a_next_time(self, my_export):
def test_last(self, my_export):
assert my_export.when_is_next_time(3) is None
assert my_export.when_is_next_time(4) is None


class TestIsItFirstTimeToExport:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Kinda hard to document a test class, you can document the test functions however.

@RemDelaporteMathurin RemDelaporteMathurin linked an issue Nov 2, 2023 that may be closed by this pull request
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (13b0959) 98.90% compared to head (f26e219) 98.91%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #628   +/-   ##
=======================================
  Coverage   98.90%   98.91%           
=======================================
  Files          56       56           
  Lines        2096     2111   +15     
=======================================
+ Hits         2073     2088   +15     
  Misses         23       23           
Files Coverage Δ
festim/exports/txt_export.py 98.48% <100.00%> (+0.44%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

Yay this looks good to me! There are just a few formatting errors like whitespaces and line-length, etc.

I've suggested a couple but there are more (see the linting check failing)

It is super easy to format your code, just run:

python -m black .

This will run the black formatter on all the files and make sure they are correctly formatted.
If you don't have black installed, you can install it with pip.

test/system/test_misc.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

Looks good to me! Congrats @KulaginVladimir on your first PR! 🎉 🚀

Feel free to join the FESTIM slack channel where we discuss about development, but also user support.

On another note, tell me if I'm wrong but by the look of your commit messages, it looks like you made the code modifications directly in github.com?
If that's so, for next time, I think it would be easier for you to clone the repository locally, do the changes, then commit and push the changes to your remote repository on github.com
It will give you more control of what you are doing and it's good practice in general.

If you are still interested in contributing to FESTIM, don't hesitate to take a look at issues tagged with "Good first issues". These are issues that can be easily fixed and that we usually leave open for newcomers!

@RemDelaporteMathurin
Copy link
Collaborator

@jhdark I'll leave this open in case you have additional things to say. The docs are failing due to a build issue, it has been fixed in another PR #630

@RemDelaporteMathurin RemDelaporteMathurin added the enhancement New feature or request label Nov 3, 2023
Copy link
Collaborator

@jhdark jhdark left a comment

Choose a reason for hiding this comment

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

Looks great to me

@RemDelaporteMathurin RemDelaporteMathurin merged commit 3e441e1 into festim-dev:main Nov 4, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Single output file for TXTExport
3 participants