BUG: Write LAMMPS File crashes when exporting fewer than 1000 atoms
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 80/100
Direzione di ricerca
La divisione per zero si verifica in WriteLAMMPSFile::operator() in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteLAMMPSFile.cpp, dove l'incremento di avanzamento è numVerts / 1000 e viene poi usato in i % increment. Proteggi l'incremento in modo che valga almeno uno, oppure elimina il controllo del modulo, quindi aggiungi il caso con otto atomi in src/Plugins/SimplnxCore/test/WriteLAMMPSFileTest.cpp. È completato quando quel test passa e gli input con 1, 999 e 1.000 atomi vengono esportati correttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 18
- Fork
- 15
- Merge medio
- 3g 22h
- PR unite (30g)
- 20
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di BlueQuartzSoftware/simplnx
-
bug Filter
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BlueQuartzSoftware/simplnx#1860 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
documentation
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
BlueQuartzSoftware/simplnx#1847 ·
I maintainer di solito rispondono entro 3 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
BlueQuartzSoftware/simplnx#1846 ·
I maintainer di solito rispondono entro 3 giorni
-
bug Filter
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BlueQuartzSoftware/simplnx#1844 ·
I maintainer di solito rispondono entro 3 giorni
-
bug Filter
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
BlueQuartzSoftware/simplnx#1843 ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di BlueQuartzSoftware/simplnx
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
KhronosGroup/Vulkan-Tutorial#534 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 2 giorni
-
bug IO
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
MrNeRF/LichtFeld-Studio#3824 ·
I maintainer di solito rispondono entro 1 giorno
-
pnnx: manual tanh GELU fusion loses the approximation modeForse già presa @ktz03 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Tencent/ncnn#7175 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
throneproj/Throne#2043 ·
I maintainer di solito rispondono entro 2 giorni