BUG: Write LAMMPS File crashes when exporting fewer than 1000 atoms
メンテナーはふだん 3 日以内に返信
評価
調査の方向性
ゼロ除算は src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteLAMMPSFile.cpp の WriteLAMMPSFile::operator() で発生します。進捗の増分は numVerts / 1000 で、その後 i % increment で使われています。増分が少なくとも 1 になるようガードするか、剰余によるゲートを削除してください。そのうえで、8 原子のケースを src/Plugins/SimplnxCore/test/WriteLAMMPSFileTest.cpp に追加します。そのテストが通り、1、999、1,000 原子の入力が正しくエクスポートされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Problem
WriteLAMMPSFileFilter accepts a valid eight-atom vertex geometry in preflight, then crashes during execution with an integer divide-by-zero error. It should write a LAMMPS data file containing eight atom records.
This was reproduced against simplnx commit fe6c4a15e5a5bffef2523f52cec01be33b1e62a9. The same algorithm and filter source are unchanged at 84c66066a26b9e098ab58748dc2f8e7bee8b01e9.
Steps to Reproduce
- Create a
VertexGeomwith the eight corners of a unit cube:(0,0,0),(1,0,0),(0,1,0),(1,1,0),(0,0,1),(1,0,1),(0,1,1), and(1,1,1). - Create an
int32atom-label array with eight tuples, one component, and every value set to1. - Set Input Vertex Geometry and Atom Feature Labels to those objects, and set Output File Path to a writable path.
- Preflight succeeds without warnings. Execute the filter.
- The process terminates with a divide-by-zero error before it writes the first atom record.
The unit test below constructs these inputs directly; it needs no downloaded fixture.
Cause
usize numVerts = verts.getNumberOfTuples();
usize increment = numVerts / 1000;
for(usize i = 0; i < numVerts; i++)
{
if(m_ShouldCancel)
{
return {};
}
if(i % increment == 0)
{
progressThrottle.updatePercent("Exporting Data", i, numVerts);
}
For the eight-atom input, increment is zero and the first iteration evaluates 0 % 0. The same source condition applies to every nonempty input containing fewer than 1,000 atoms; the executed reproduction used eight atoms. The filter calls this algorithm before committing its atomic output file.
Verification Unit Test
Add this case to src/Plugins/SimplnxCore/test/WriteLAMMPSFileTest.cpp. It asserts successful execution and the expected eight atom records, labels, coordinates, and image flags.
#include "SimplnxCore/Filters/WriteLAMMPSFileFilter.hpp"
#include "simplnx/DataStructure/AttributeMatrix.hpp"
#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/DataStructure/Geometry/VertexGeom.hpp"
#include "simplnx/Parameters/FileSystemPathParameter.hpp"
#include "simplnx/UnitTest/UnitTestCommon.hpp"
#include <catch2/catch.hpp>
#include <array>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace nx::core;
TEST_CASE("SimplnxCore::WriteLAMMPSFileFilter: Export eight atoms", "[SimplnxCore][WriteLAMMPSFileFilter][LAMMPSSmallVertexCount]")
{
UnitTest::LoadPlugins();
constexpr usize k_NumAtoms = 8;
constexpr std::array<std::array<float32, 3>, k_NumAtoms> k_Positions = {
{{0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f}}};
const DataPath geometryPath({"Atoms"});
const DataPath atomLabelsPath({"Atoms", "Vertex Data", "Atom Labels"});
DataStructure dataStructure;
auto* geometry = VertexGeom::Create(dataStructure, "Atoms");
REQUIRE(geometry != nullptr);
auto* vertices = Float32Array::CreateWithStore<Float32DataStore>(dataStructure, VertexGeom::k_SharedVertexListName, {k_NumAtoms}, {3}, geometry->getId());
REQUIRE(vertices != nullptr);
geometry->setVertices(*vertices);
for(usize atom = 0; atom < k_NumAtoms; atom++)
{
for(usize component = 0; component < 3; component++)
{
(*vertices)[3 * atom + component] = k_Positions[atom][component];
}
}
auto* vertexData = AttributeMatrix::Create(dataStructure, "Vertex Data", {k_NumAtoms}, geometry->getId());
REQUIRE(vertexData != nullptr);
geometry->setVertexAttributeMatrix(*vertexData);
auto* labels = Int32Array::CreateWithStore<Int32DataStore>(dataStructure, "Atom Labels", {k_NumAtoms}, {1}, vertexData->getId());
REQUIRE(labels != nullptr);
labels->fill(1);
UnitTest::CheckArraysInheritTupleDims(dataStructure);
const auto outputPath = std::filesystem::current_path() / "lammps_eight_atoms.txt";
std::filesystem::remove(outputPath);
WriteLAMMPSFileFilter filter;
auto args = filter.getDefaultArguments();
args.insertOrAssign(WriteLAMMPSFileFilter::k_OutputFile_Key, std::make_any<FileSystemPathParameter::ValueType>(outputPath));
args.insertOrAssign(WriteLAMMPSFileFilter::k_VertexGeomPath, std::make_any<DataPath>(geometryPath));
args.insertOrAssign(WriteLAMMPSFileFilter::k_AtomLabelsPath_Key, std::make_any<DataPath>(atomLabelsPath));
const auto preflight = filter.preflight(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_VALID(preflight.outputActions);
REQUIRE(preflight.outputActions.warnings().empty());
std::cout << "Preflight succeeded for eight vertices and eight int32 labels." << std::endl;
const auto execution = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_VALID(execution.result);
REQUIRE(std::filesystem::exists(outputPath));
std::ifstream stream(outputPath);
REQUIRE(stream.is_open());
bool foundAtomCount = false;
bool foundAtomSection = false;
usize atomRecords = 0;
for(std::string line; std::getline(stream, line);)
{
if(line == "8 atoms")
{
foundAtomCount = true;
}
if(line == "Atoms")
{
foundAtomSection = true;
continue;
}
if(!foundAtomSection || line.empty())
{
continue;
}
REQUIRE(atomRecords < k_NumAtoms);
std::istringstream row(line);
usize atomId = 0;
int32 atomType = 0;
std::array<float32, 3> position{};
std::array<int32, 3> imageFlags{};
REQUIRE(static_cast<bool>(row >> atomId >> atomType >> position[0] >> position[1] >> position[2] >> imageFlags[0] >> imageFlags[1] >> imageFlags[2]));
CHECK(atomId == atomRecords + 1);
CHECK(atomType == 1);
CHECK(position == k_Positions[atomRecords]);
const std::array<int32, 3> expectedImageFlags = {0, 0, 0};
CHECK(imageFlags == expectedImageFlags);
atomRecords++;
}
CHECK(foundAtomCount);
CHECK(foundAtomSection);
CHECK(atomRecords == k_NumAtoms);
}
The complete test above was compiled in a standalone Catch2 target, linked to the unmodified Release simplnx and SimplnxCore libraries built from the reported commit. The runtime DLL and plugin hashes matched the source runtime. The standalone target registers one CTest case named LAMMPSSmallVertexCount.
Run only that registered reproduction:
cmake --build <reproduction-build> --config Release
ctest --test-dir <reproduction-build> -C Release -j 1 -R "^LAMMPSSmallVertexCount$" --output-on-failure --timeout 30
After adding the case to the repository test file and building the normal SimplnxCore test target, select it through the repository's Catch2 CTest registration:
ctest --test-dir <simplnx-build> -C Release -j 1 -R "WriteLAMMPSFileFilter: Export eight atoms" --output-on-failure
Observed failure:
Start 1: LAMMPSSmallVertexCount
1/1 Test #1: LAMMPSSmallVertexCount ...........***Exception: Numerical 0.03 sec
Preflight succeeded for eight vertices and eight int32 labels.
failed: fatal error condition with message: 'Divide by zero error'
Failed 1 test case, failed 1 assertion.
0% tests passed, 1 tests failed out of 1
CTest returned exit code 8. The test compiled successfully; this failure occurred during execution after successful preflight.
Proposed Fix
In WriteLAMMPSFile::operator(), ensure the progress interval is at least one before evaluating i % increment, or remove this extra modulo gate and let ThrottledMessageHandler control progress-message frequency. Keep the small-input regression test and cover the 1, 999, and 1,000 atom boundaries when implementing the fix.
No production fix was applied or tested for this report.
Notes
- Reproduction environment: Windows x64, Visual Studio 2022, MSVC 19.44.35229, Release configuration.
- This verifies the file export path. It does not run a LAMMPS simulation or validate simulation setup.
- 主要言語
- C++
- スター
- 18
- フォーク
- 15
- 平均マージ
- 3日 35分
- マージ済み PR(30日)
- 25
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
BlueQuartzSoftware/simplnx のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
BlueQuartzSoftware/simplnx#1912 ·
メンテナーはふだん 3 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
BlueQuartzSoftware/simplnx#1906 ·
メンテナーはふだん 3 日以内に返信
-
bug Filter
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
BlueQuartzSoftware/simplnx#1891 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
bug Filter
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
BlueQuartzSoftware/simplnx#1860 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
documentation
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
BlueQuartzSoftware/simplnx#1847 ·
メンテナーはふだん 3 日以内に返信
BlueQuartzSoftware/simplnx の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
ROCm/AMDMIGraphX#5490 ·
メンテナーはふだん 3 日以内に返信
-
符号半角全角问题オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
arvidn/libtorrent#9126 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Sunrisepeak/mcpp-language-server#80 ·
メンテナーはふだん 1 日以内に返信