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

[WIP] Unify Random-Access API and Streaming API into Series::snapshots() #1592

Open
wants to merge 93 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
e52155b
Introduce SharedAttributableData
franzpoeschel Jun 28, 2023
9e31b09
Add AbstractSeriesIterator
franzpoeschel Jan 25, 2024
16fe71c
Derive SeriesIterator from AbstractSeriesIterator
franzpoeschel Jan 25, 2024
8ceec08
Little fix
franzpoeschel Jan 26, 2024
8ba9820
Introduce Snapshots.hpp
franzpoeschel Jan 26, 2024
37bd136
Make AbstractSeriesIterator non-virtual
franzpoeschel Jan 26, 2024
8cbd84b
Working commit for Series::snapshots()
franzpoeschel Jan 26, 2024
71065ad
No virtual operator[]
franzpoeschel Jan 26, 2024
52d8d3e
Remove random-accessing from iterator
franzpoeschel Jan 26, 2024
24ed6fa
Introduce AbstractSnapshotsContainer
franzpoeschel Jan 26, 2024
6be640a
basic random-access iteration
franzpoeschel Jan 26, 2024
118c47f
RandomAccessSnapshots.hpp -> snapshots/RandomAccessIterator.hpp
franzpoeschel Jan 29, 2024
cbe73e9
ReadIterations.hpp -> snapshots/StatefulIterator.hpp
franzpoeschel Jan 29, 2024
0388466
SeriesIterator.hpp -> snapshots/IteratorTraits.hpp
franzpoeschel Jan 29, 2024
9bf0a2e
Snapshots.hpp -> snapshots/Snapshots.hpp
franzpoeschel Jan 29, 2024
033e9a7
Move AbstractSnapshotsContainer to ContainerTraits.hpp
franzpoeschel Jan 29, 2024
ed689f7
Move Container implementations to ContainerImpls.(h|c)pp
franzpoeschel Jan 29, 2024
bf32dfe
Fix: parsePreference is not set in file-based iteratione encoding
franzpoeschel Jan 29, 2024
c619545
Temporarily fix test
franzpoeschel Jan 29, 2024
2b05425
Const iteration
franzpoeschel Jan 29, 2024
2e26222
Extract stuff to .cpp
franzpoeschel Jan 29, 2024
890dc89
Reverse iteration
franzpoeschel Jan 29, 2024
4fc2083
Commit missing Snapshots.cpp file
franzpoeschel Jan 29, 2024
8aefaff
empty()
franzpoeschel Jan 29, 2024
0bbdb33
Revert wrong renaming ReadIterations/StatefulIterator
franzpoeschel Jan 29, 2024
ab631bc
Rename SeriesIterator -> StatefulIterator
franzpoeschel Jan 29, 2024
80e8aa0
Add ::at, operator[]
franzpoeschel Jan 30, 2024
aef260e
beginStep(): always return relevant iteration indices
franzpoeschel Jan 30, 2024
ba05ee2
Basically working example for snapshots() in write access
franzpoeschel Jan 30, 2024
0c7c04b
Extract some methods to .cpp
franzpoeschel Jan 31, 2024
559658b
Fully replace WriteIterations class with the new one
franzpoeschel Jan 31, 2024
0e8e994
Fix nullpointer issue
franzpoeschel Jan 31, 2024
b9b7187
Little fixes
franzpoeschel Feb 6, 2024
05f9c27
Add some further API calls
franzpoeschel Feb 6, 2024
465a2ae
Some postfix form transformations
franzpoeschel Feb 6, 2024
894014f
Use snapshots() in read example 2
franzpoeschel Feb 7, 2024
937a5d3
Simplify ReadIterations implementation
franzpoeschel Feb 7, 2024
913c1cd
Further cleanup
franzpoeschel Feb 7, 2024
a7d75c8
Change representation of iterations in current step
franzpoeschel Feb 7, 2024
43c3ab0
Initiate reading of group/variable-based encoding with nextStep()
franzpoeschel Feb 8, 2024
26d87be
Prepare internal representation to be aware of steps
franzpoeschel Feb 14, 2024
8ac9d38
Windows fixes
Feb 16, 2024
402cc5b
Adapt tests
franzpoeschel Feb 15, 2024
1391534
Unify close status
franzpoeschel Feb 15, 2024
304ae4b
Add basic test for opening after closing
franzpoeschel Feb 15, 2024
cf5b097
Add new end() iterator representations
franzpoeschel Feb 16, 2024
a5f30a8
Reopening logic in Iterator, not yet in Series itself
franzpoeschel Feb 16, 2024
5202939
Reopening fundamentally working in READ_LINEAR
franzpoeschel Feb 16, 2024
27ba327
Extend test
franzpoeschel Feb 16, 2024
bb0a776
For now, adapt the append_mode test
franzpoeschel Feb 19, 2024
849fb91
fixes
franzpoeschel Feb 19, 2024
5ebdab3
BUGFIX: modifiable attributes, maybe extract this to dev
franzpoeschel Feb 19, 2024
01d065d
Ensure that iterations are never parsed twice
franzpoeschel Feb 19, 2024
29ff452
Move currently_available_iterations to During_t
franzpoeschel Feb 19, 2024
64027e7
Revert "For now, adapt the append_mode test"
franzpoeschel Feb 19, 2024
f0bb16c
Remember where we saw what iteration
franzpoeschel Feb 19, 2024
0d3b96d
Bit of cleanup
franzpoeschel Feb 19, 2024
e78d5be
[wip] Groupbased writing: close and reopen
franzpoeschel Feb 19, 2024
5bbb79d
Further test and implement reopening of Iterations
franzpoeschel Feb 20, 2024
b785148
Unused variable
franzpoeschel Feb 21, 2024
95798b0
some fixes to groupbased reopen test
franzpoeschel Feb 21, 2024
00f149f
Filebased reopen in ADIOS2 (no READ_WRITE support yet)
franzpoeschel Feb 21, 2024
c03ba19
Now supports READ_WRITE too in filebased mode
franzpoeschel Feb 21, 2024
28c0516
Some exceptions for unimplemented stuff
franzpoeschel Feb 21, 2024
0ed110f
Works in JSON and HDF5 now too
franzpoeschel Feb 22, 2024
27e02bf
CI fixes
franzpoeschel Feb 23, 2024
99d8146
Virtual destructors
franzpoeschel Feb 26, 2024
49787c3
CI fixes continued
franzpoeschel Feb 26, 2024
3584de6
Some fixes for noexcept specifications
franzpoeschel Feb 26, 2024
3dc2ea3
Further CI Fixes
franzpoeschel Feb 26, 2024
aa2866f
CI FIXES
franzpoeschel Feb 27, 2024
14267e5
Fixes for ADIOS2 v2.7
franzpoeschel Feb 29, 2024
0139fa5
placate the intel compiler
franzpoeschel Mar 5, 2024
d815632
noexcept details for MSVC
franzpoeschel Mar 5, 2024
8e9248a
Fix ulimit test
franzpoeschel Mar 6, 2024
5fa0525
Fix after rebase: dirtyRecursive
franzpoeschel Mar 26, 2024
0374f31
Fixes after rebase
franzpoeschel Mar 26, 2024
32040ac
remove conflict markers...
franzpoeschel Jun 7, 2024
7a58e28
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 7, 2024
684168f
Better defaults?
franzpoeschel Jun 10, 2024
467b90b
Parameterize Series::snapshots()
franzpoeschel Jun 10, 2024
86d6ed3
Use enum class for last commit
franzpoeschel Jun 10, 2024
19e97f5
Add some missing minor function implementations
franzpoeschel Jun 10, 2024
ab81b91
Don't use globbing
franzpoeschel Jun 24, 2024
cc52cd1
Add missing include
franzpoeschel Jul 1, 2024
ffd802d
Better include structure, put Legacy stuff to Legacy headers
franzpoeschel Jul 4, 2024
3dce4b6
Bugfix
franzpoeschel Jul 5, 2024
2e77dd3
Documentation, cleanup
franzpoeschel Jul 4, 2024
09c0a64
Add check_recursive_include script
franzpoeschel Jul 8, 2024
de4b662
Fixes after rebase
franzpoeschel Jul 11, 2024
655c932
Fix bug that hindered files from being properly closed
franzpoeschel Jul 16, 2024
0099010
Will this fix the Windows CI errors I dont think so
franzpoeschel Jul 17, 2024
bfc9897
Use macro instead of function
franzpoeschel Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,11 @@ set(CORE_SOURCE
src/Mesh.cpp
src/ParticlePatches.cpp
src/ParticleSpecies.cpp
src/ReadIterations.cpp
src/Record.cpp
src/ReadIterations.cpp
src/RecordComponent.cpp
src/Series.cpp
src/version.cpp
src/WriteIterations.cpp
src/auxiliary/Date.cpp
src/auxiliary/Filesystem.cpp
src/auxiliary/JSON.cpp
Expand All @@ -476,11 +475,19 @@ set(CORE_SOURCE
src/backend/PatchRecordComponent.cpp
src/backend/Writable.cpp
src/benchmark/mpi/OneDimensionalBlockSlicer.cpp
src/helper/list_series.cpp)
src/helper/list_series.cpp
src/snapshots/ContainerImpls.cpp
src/snapshots/ContainerTraits.cpp
src/snapshots/IteratorHelpers.cpp
src/snapshots/IteratorTraits.cpp
src/snapshots/RandomAccessIterator.cpp
src/snapshots/Snapshots.cpp
src/snapshots/StatefulIterator.cpp)
set(IO_SOURCE
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/IO/AbstractIOHandlerHelper.cpp
src/IO/Access.cpp
src/IO/DummyIOHandler.cpp
src/IO/IOTask.cpp
src/IO/FlushParams.cpp
Expand Down Expand Up @@ -848,8 +855,20 @@ if(openPMD_BUILD_TESTING)
target_compile_definitions(CatchRunner PUBLIC openPMD_HAVE_MPI=1)
endif()

macro(additional_testing_sources test_name out_list)
if(${test_name} STREQUAL "SerialIO")
list(APPEND ${out_list}
test/Files_SerialIO/close_iteration_test.cpp
test/Files_SerialIO/filebased_write_test.cpp
)
endif()
endmacro()

foreach(testname ${openPMD_TEST_NAMES})
add_executable(${testname}Tests test/${testname}Test.cpp)
set(ADDITIONAL_SOURCE_FILES "")
additional_testing_sources(${testname} ADDITIONAL_SOURCE_FILES)
add_executable(${testname}Tests test/${testname}Test.cpp ${ADDITIONAL_SOURCE_FILES})
target_include_directories(${testname}Tests PRIVATE test/Files_${testname}/)
openpmd_cxx_required(${testname}Tests)
set_target_properties(${testname}Tests PROPERTIES
COMPILE_PDB_NAME ${testname}Tests
Expand Down
50 changes: 50 additions & 0 deletions check_recursive_include.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3

import re
import subprocess
import sys


def track_includes(start_file):
remove_start = re.compile("include/")

def clean(file):
return re.sub(remove_start, "", file)

unseen_files = [start_file]
res = {}
# import ipdb
# ipdb.set_trace(context=30)
while unseen_files:
current_file = unseen_files[0]
del unseen_files[0]

cmd = ["grep", "-Rl", clean(current_file), "include/"]
try:
next_files = subprocess.check_output(cmd)
lines = [line for line in next_files.decode().splitlines() if line]
except subprocess.CalledProcessError:
lines = []

res[current_file] = lines
for line in lines:
if line not in res:
unseen_files.append(line)
return res


if __name__ == "__main__":

remove_start = re.compile("include/(openPMD/)?")
remove_slash = re.compile("/|\\.")

def clean(file):
return re.sub(remove_slash, "_", re.sub(remove_start, "", file))

res = track_includes(sys.argv[1])
print("digraph {")
for key, values in res.items():
key = clean(key)
for target in values:
print("\t{} -> {};".format(key, clean(target)))
print("}")
5 changes: 2 additions & 3 deletions examples/10_streaming_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ int main()
// in streaming setups, e.g. an iteration cannot be opened again once
// it has been closed.
// `Series::iterations` can be directly accessed in random-access workflows.
for (IndexedIteration iteration : series.readIterations())
for (auto &[index, iteration] : series.snapshots())
{
std::cout << "Current iteration: " << iteration.iterationIndex
<< std::endl;
std::cout << "Current iteration: " << index << std::endl;
Record electronPositions = iteration.particles["e"]["position"];
std::array<RecordComponent::shared_ptr_dataset_types, 3> loadedChunks;
std::array<Extent, 3> extents;
Expand Down
4 changes: 3 additions & 1 deletion examples/10_streaming_write.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "openPMD/Series.hpp"
#include "openPMD/snapshots/Snapshots.hpp"
#include <openPMD/openPMD.hpp>

#include <algorithm>
Expand Down Expand Up @@ -43,7 +45,7 @@ int main()
// in streaming setups, e.g. an iteration cannot be opened again once
// it has been closed.
// `Series::iterations` can be directly accessed in random-access workflows.
WriteIterations iterations = series.writeIterations();
auto iterations = series.snapshots(SnapshotWorkflow::Synchronous);
for (size_t i = 0; i < 100; ++i)
{
Iteration iteration = iterations[i];
Expand Down
6 changes: 3 additions & 3 deletions examples/2_read_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ int main()
cout << "Read a Series with openPMD standard version " << series.openPMD()
<< '\n';

cout << "The Series contains " << series.iterations.size()
cout << "The Series contains " << series.snapshots().size()
<< " iterations:";
for (auto const &i : series.iterations)
for (auto const &i : series.snapshots())
cout << "\n\t" << i.first;
cout << '\n';

Iteration i = series.iterations[100];
Iteration i = series.snapshots()[100];
cout << "Iteration 100 contains " << i.meshes.size() << " meshes:";
for (auto const &m : i.meshes)
cout << "\n\t" << m.first;
Expand Down
15 changes: 15 additions & 0 deletions include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ namespace adios_defs
Yes,
No
};

/*
* Necessary to implement the `reopen` flag of
* `Parameter<Operation::OPEN_FILE>`. The distinction between Open and
* Reopen is necessary for Write workflows in file-based encoding. In order
* to write new data to an Iteration that was created and closed previously,
* the only applicable access mode is Append mode, ideally in conjunction
* with `SetParameter("FlattenSteps", "ON")`.
*/
enum class OpenFileAs
{
Create,
Open,
Reopen
};
} // namespace adios_defs

/*
Expand Down
5 changes: 4 additions & 1 deletion include/openPMD/IO/ADIOS/ADIOS2File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ class ADIOS2File

using AttributeMap_t = std::map<std::string, adios2::Params>;

ADIOS2File(ADIOS2IOHandlerImpl &impl, InvalidatableFile file);
ADIOS2File(
ADIOS2IOHandlerImpl &impl,
InvalidatableFile file,
adios_defs::OpenFileAs);

~ADIOS2File();

Expand Down
7 changes: 5 additions & 2 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class ADIOS2IOHandlerImpl
* @brief The ADIOS2 access type to chose for Engines opened
* within this instance.
*/
adios2::Mode adios2AccessMode(std::string const &fullPath);
adios2::Mode
adios2AccessMode(std::string const &fullPath, adios_defs::OpenFileAs);

FlushTarget m_flushTarget = FlushTarget::Disk;

Expand Down Expand Up @@ -403,9 +404,11 @@ class ADIOS2IOHandlerImpl
*/
GroupOrDataset groupOrDataset(Writable *);

enum class IfFileNotOpen : bool
enum class IfFileNotOpen : char
{
ReopenImplicitly,
OpenImplicitly,
CreateImplicitly,
ThrowError
};

Expand Down
4 changes: 4 additions & 0 deletions include/openPMD/IO/AbstractIOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class AbstractIOHandler
break;
}
}
else
{
m_backendAccess = m_frontendAccess;
}

m_encoding = encoding;
}
Expand Down
2 changes: 2 additions & 0 deletions include/openPMD/IO/Access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ enum class Access
APPEND //!< write new iterations to an existing series without reading
}; // Access

std::ostream &operator<<(std::ostream &o, Access const &a);

namespace access
{
inline bool readOnly(Access access)
Expand Down
2 changes: 2 additions & 0 deletions include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::OPEN_FILE>
}

std::string name = "";
// true <-> file was previously created and is now opened again
bool reopen = false;
using ParsePreference = internal::ParsePreference;
std::shared_ptr<ParsePreference> out_parsePreference =
std::make_shared<ParsePreference>(ParsePreference::UpFront);
Expand Down
58 changes: 31 additions & 27 deletions include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ namespace internal
Open, //!< Iteration has not been closed
ClosedInFrontend, /*!< Iteration has been closed, but task has not yet
been propagated to the backend */
ClosedInBackend, /*!< Iteration has been closed and task has been
Closed, /*!< Iteration has been closed and task has been
propagated to the backend */
ClosedTemporarily /*!< Iteration has been closed internally and may
be reopened later */
};

struct DeferredParseAccess
Expand All @@ -71,11 +69,6 @@ namespace internal
* (Group- and variable-based parsing shares the same code logic.)
*/
bool fileBased = false;
/**
* If fileBased == true, the file name (without file path) of the file
* containing this iteration.
*/
std::string filename;
bool beginStep = false;
};

Expand All @@ -92,6 +85,14 @@ namespace internal
* overwritten.
*/
CloseStatus m_closed = CloseStatus::Open;
/*
* While parsing a file-based Series, each file is opened, read, then
* closed again. Explicitly `Iteration::open()`ing a file should only be
* necessary after having explicitly closed it (or in
* defer_iteration_parsing mode). So, the parsing procedures will set
* this flag as true when closing an Iteration.
*/
bool allow_reopening_implicitly = false;

/**
* Whether a step is currently active for this iteration.
Expand All @@ -107,14 +108,6 @@ namespace internal
* Otherwise empty.
*/
std::optional<DeferredParseAccess> m_deferredParseAccess{};

/**
* Upon reading a file, set this field to the used file name.
* In inconsistent iteration paddings, we must remember the name of the
* file since it cannot be reconstructed from the filename pattern
* alone.
*/
std::optional<std::string> m_overrideFilebasedFilename{};
};
} // namespace internal
/** @brief Logical compilation of data from one snapshot (e.g. a single
Expand All @@ -128,15 +121,17 @@ class Iteration : public Attributable
template <typename T, typename T_key, typename T_container>
friend class Container;
friend class Series;
friend class WriteIterations;
friend class SeriesIterator;
friend class internal::AttributableData;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
friend class StatefulIterator;
friend class StatefulSnapshotsContainer;

public:
Iteration(Iteration const &) = default;
Iteration(Iteration &&) = default;
Iteration &operator=(Iteration const &) = default;
Iteration &operator=(Iteration &&) = default;

using IterationIndex_t = uint64_t;

Expand Down Expand Up @@ -219,12 +214,19 @@ class Iteration : public Attributable

/**
* @brief Has the iteration been closed?
* A closed iteration may not (yet) be reopened.
*
* @return Whether the iteration has been closed.
*/
bool closed() const;

/**
* @brief Has the iteration been parsed yet?
If not, it will contain no structure yet.
*
* @return Whether the iteration has been parsed.
*/
bool parsed() const;

/**
* @brief Has the iteration been closed by the writer?
* Background: Upon calling Iteration::close(), the openPMD API
Expand Down Expand Up @@ -298,6 +300,7 @@ class Iteration : public Attributable
*/
void reread(std::string const &path);
void readFileBased(
IterationIndex_t,
std::string const &filePath,
std::string const &groupPath,
bool beginStep);
Expand All @@ -313,7 +316,7 @@ class Iteration : public Attributable
*/
struct BeginStepStatus
{
using AvailableIterations_t = std::optional<std::deque<uint64_t> >;
using AvailableIterations_t = std::vector<uint64_t>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplification: beginStep() always returns the available Iterations


AdvanceStatus stepStatus{};
/*
Expand Down Expand Up @@ -355,11 +358,8 @@ class Iteration : public Attributable
* Useful in group-based iteration encoding where the Iteration will only
* be known after opening the step.
*/
static BeginStepStatus beginStep(
std::optional<Iteration> thisObject,
Series &series,
bool reread,
std::set<IterationIndex_t> const &ignoreIterations = {});
static BeginStepStatus
beginStep(std::optional<Iteration> thisObject, Series &series, bool reread);

/**
* @brief End an IO step on the IO file (or file-like object)
Expand Down Expand Up @@ -433,13 +433,17 @@ inline T Iteration::dt() const
*/
class IndexedIteration : public Iteration
{
friend class SeriesIterator;
friend class WriteIterations;
friend class StatefulIterator;
friend class LegacyIteratorAdaptor;

public:
using index_t = Iteration::IterationIndex_t;
index_t const iterationIndex;

inline IndexedIteration(std::pair<index_t const, Iteration> pair)
: Iteration(std::move(pair.second)), iterationIndex(pair.first)
{}

private:
template <typename Iteration_t>
IndexedIteration(Iteration_t &&it, index_t index)
Expand Down
Loading
Loading