Skip to content

Write auto generated input file to tmp - #2148

Merged
YigitElma merged 24 commits into
masterfrom
yge/writing-inputfiles
Jul 31, 2026
Merged

Write auto generated input file to tmp#2148
YigitElma merged 24 commits into
masterfrom
yge/writing-inputfiles

Conversation

@YigitElma

@YigitElma YigitElma commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Resolves #2139

InputReader.parse_inputs method now uses an in-memory buffer if it has to convert a vmec to a desc input, resulting in no files being written.

@YigitElma YigitElma self-assigned this Mar 31, 2026
@YigitElma YigitElma added the easy Short and simple to code or review label Mar 31, 2026
@github-actions

github-actions Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Memory benchmark result

|               Test Name                |      %Δ      |    Master (MB)     |      PR (MB)       |    Δ (MB)    |    Time PR (s)     |  Time Master (s)   |
| -------------------------------------- | ------------ | ------------------ | ------------------ | ------------ | ------------------ | ------------------ |
  test_objective_jac_w7x                 |   -0.16 %    |     3.940e+03      |     3.934e+03      |    -6.31     |       32.83        |       31.02        |
  test_proximal_jac_w7x_with_eq_update   |    0.06 %    |     6.605e+03      |     6.609e+03      |     4.08     |       163.95       |       162.81       |
  test_proximal_freeb_jac                |    0.57 %    |     1.334e+04      |     1.341e+04      |    76.29     |       84.58        |       83.15        |
  test_proximal_freeb_jac_blocked        |   -0.24 %    |     7.670e+03      |     7.651e+03      |    -18.45    |       73.18        |       73.36        |
  test_proximal_freeb_jac_batched        |    0.22 %    |     7.635e+03      |     7.653e+03      |    17.14     |       73.17        |       72.50        |
  test_proximal_jac_ripple               |   -3.79 %    |     3.597e+03      |     3.461e+03      |   -136.33    |       57.22        |       58.65        |
  test_proximal_jac_ripple_bounce1d      |    0.45 %    |     3.766e+03      |     3.782e+03      |    16.77     |       72.32        |       72.30        |
  test_eq_solve                          |   -1.48 %    |     2.053e+03      |     2.023e+03      |    -30.35    |       55.53        |       56.54        |
  test_objective_quadratic_flux_jac      |   -1.29 %    |     2.541e+03      |     2.508e+03      |    -32.77    |       55.13        |       55.76        |

For the memory plots, go to the summary of Memory Benchmarks workflow and download the artifact.

@YigitElma
YigitElma marked this pull request as draft March 31, 2026 05:22
@codecov

codecov Bot commented Mar 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.37%. Comparing base (d3cf3b8) to head (8557b26).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2148      +/-   ##
==========================================
+ Coverage   92.88%   94.37%   +1.49%     
==========================================
  Files         101      101              
  Lines       28930    28936       +6     
==========================================
+ Hits        26872    27309     +437     
+ Misses       2058     1627     -431     
Files with missing lines Coverage Δ
desc/__main__.py 62.50% <100.00%> (ø)
desc/input_reader.py 92.41% <100.00%> (+0.87%) ⬆️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@YigitElma
YigitElma marked this pull request as ready for review March 31, 2026 19:07
Comment thread desc/input_reader.py Outdated
print("Converting VMEC input to DESC input")
path = self.input_path + "_desc"
basename = os.path.basename(self.input_path) + "_desc"
tmpdir = tempfile.mkdtemp()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When does the delete operation occur on tmpdir? Does it do so automatically when the function ends?
Another option is to use with, i.e.

with tempfile.TemporaryDirectory() as tmpdir:
    path = os.path.join(tmpdir, basename = os.path.basename(self.input_path) + "_desc")

though it could be essentially the same.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it should be cleared after the python process is terminated or the session on the cluster is closed or the system is rebooted on personal laptop, not immediately after the function call. These are the options listed on the web for "when the tmp is cleared?".

@mishapadidar

Copy link
Copy Markdown

When I ran the test, the temp directory still existed after the code ran.

@YigitElma

Copy link
Copy Markdown
Collaborator Author

Add a flag for tmp file option

@YigitElma

Copy link
Copy Markdown
Collaborator Author

Try to pass a file-like object

@YigitElma
YigitElma marked this pull request as draft April 6, 2026 16:30
@YigitElma
YigitElma marked this pull request as ready for review May 28, 2026 17:22
@dpanici

dpanici commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Did we want to try this?

In a previous dev meeting, we said it doesn't worth the effort.

I was bored and did this. If we decide we don't like it we can revert but was surprisingly easy and clean.

dpanici
dpanici previously approved these changes Jul 23, 2026
@YigitElma

Copy link
Copy Markdown
Collaborator Author

Dario's approval is on behalf of me.

ddudt
ddudt previously approved these changes Jul 25, 2026

@ddudt ddudt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question(non-blocking)
Now if I want to convert a VMEC input file to a DESC input file, do I have to explicitly call InputReader.vmec_to_desc_input() myself? If so, that might be good to document in the Changelog, since I would often use the command-line interface to do that conversion implicitly.

Comment thread CHANGELOG.md Outdated
@YigitElma
YigitElma dismissed stale reviews from ddudt and dpanici via f484ccc July 25, 2026 20:38
@YigitElma
YigitElma requested review from ddudt and dpanici July 25, 2026 20:40
ddudt
ddudt previously approved these changes Jul 27, 2026
Comment thread CHANGELOG.md Outdated
@YigitElma

Copy link
Copy Markdown
Collaborator Author

Make this work so that the CLI run creates DESC input file for VMEC stuff

@dpanici

dpanici commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Make this work so that the CLI run creates DESC input file for VMEC stuff

Done. Now if doing python -m desc input.vmec the input.vmec_desc converted file will be created, as it does on master still. But if one is using from a script, input reader or from_input_file wont write the files.

@YigitElma

YigitElma commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

This looks good to me. @dpanici You can approve on my behalf.

@ddudt
ddudt self-requested a review July 30, 2026 20:54
@YigitElma
YigitElma merged commit c3e0b13 into master Jul 31, 2026
27 checks passed
@YigitElma
YigitElma deleted the yge/writing-inputfiles branch July 31, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

easy Short and simple to code or review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

from_input_file writing file without permissions

4 participants