Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 20, 2025

When Quantum Espresso cp.x trajectory files contain only a single timestep, the .evp energy file has just one data line. This caused np.loadtxt() to return a 1D array instead of the expected 2D array, leading to an IndexError when the code attempted 2D indexing operations.

# Before: This would fail with single-line .evp files
data = np.loadtxt(fname)  # Returns 1D array for single line
steps = []
for ii in data[begin::step, 0]:  # IndexError: too many indices for array
    steps.append("%d" % ii)

# After: Works consistently for both single and multi-line files  
data = np.loadtxt(fname, ndmin=2)  # Always returns at least 2D array
steps = []
for ii in data[begin::step, 0]:  # Works correctly
    steps.append("%d" % ii)

The fix uses numpy's ndmin=2 parameter to ensure the loaded data is always at least 2-dimensional, maintaining consistency between single-line and multi-line energy files without requiring additional reshaping logic.

Changes:

  • Added ndmin=2 parameter to np.loadtxt() call in load_energy() function
  • Added comprehensive test case to prevent regression

Testing:

  • All existing QE tests continue to pass (63 tests)
  • New test specifically validates single-line .evp file handling
  • CLI functionality verified to work end-to-end

Fixes #899.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [BUG] Converting from Quantum Espresso cp.x traj gives error when there is only one line in the energy output file fix(qe): use ndmin=2 in np.loadtxt to handle single-line .evp files Sep 20, 2025
@Copilot Copilot AI requested a review from njzjz September 20, 2025 14:33
Copilot finished work on behalf of njzjz September 20, 2025 14:33
@njzjz
Copy link
Member

njzjz commented Sep 20, 2025

pre-commit.ci autofix

Copy link

codspeed-hq bot commented Sep 20, 2025

CodSpeed WallTime Performance Report

Merging #900 will not alter performance

Comparing copilot/fix-899 (e038715) with devel (7212c33)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 2 untouched

Copy link

codecov bot commented Sep 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.06%. Comparing base (7212c33) to head (e038715).
⚠️ Report is 1 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel     #900   +/-   ##
=======================================
  Coverage   86.06%   86.06%           
=======================================
  Files          83       83           
  Lines        7886     7886           
=======================================
  Hits         6787     6787           
  Misses       1099     1099           

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

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

@njzjz njzjz marked this pull request as ready for review September 20, 2025 15:37
@njzjz njzjz requested a review from wanghan-iapcm September 20, 2025 15:38
Copy link
Member

@njzjz njzjz left a comment

Choose a reason for hiding this comment

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

good

@wanghan-iapcm wanghan-iapcm merged commit 497a474 into devel Sep 23, 2025
22 checks passed
@wanghan-iapcm wanghan-iapcm deleted the copilot/fix-899 branch September 23, 2025 00:55
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.

[BUG] Converting from Quantum Espresso cp.x traj gives error when there is only one line in the energy output file

3 participants