Skip to content

Commit

Permalink
PY: Add support for Python 3.12 with HDF5 1.14. (#861)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Feb 19, 2024
1 parent 1d0a733 commit 5b24757
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 32 deletions.
1 change: 1 addition & 0 deletions conda/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cxx_compiler_version:
- 10.4.0 # [linux]

python:
- 3.12
- 3.11
- 3.10
- 3.9
8 changes: 5 additions & 3 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build:
requirements:
build:
- {{ compiler('cxx') }}
- cmake >=3.26
- cmake =3.26
- ninja
- git
host:
Expand All @@ -50,7 +50,8 @@ requirements:
- boost_mp11
- eigen
- fmt =10
- hdf5 =1.12
- hdf5 >=1.14.3 # [py>=312]
- hdf5 =1.12 # [py<=311]
- nlohmann_json
- pybind11 >=2.10
- reproc-cpp
Expand All @@ -66,7 +67,8 @@ requirements:
- python
- numpy
- fmt =10
- hdf5 =1.12
- hdf5 >=1.14.3 # [py>=312]
- hdf5 =1.12 # [py<=311]
- reproc-cpp
- tbb
- zlib
Expand Down
10 changes: 8 additions & 2 deletions conda/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ requirements:
- boost_mp11
- eigen
- fmt =10
- hdf5 =1.12
- sel(py>=312):
- hdf5 >=1.14.3
- sel(py>=39 and py<312):
- hdf5 >=1.12
- nlohmann_json
- pybind11 >=2.10
- reproc-cpp
Expand All @@ -66,7 +69,10 @@ requirements:
- python
- numpy
- fmt =10
- hdf5 =1.12
- sel(py>=312):
- hdf5 >=1.14.3
- sel(py>=39 and py<312):
- hdf5 >=1.12
- reproc-cpp
- tbb
- zlib
Expand Down
14 changes: 7 additions & 7 deletions src/simplnx/DataStructure/IO/HDF5/DataStoreIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Chunks
constexpr int32 k_DimensionMismatchError = -2654;

template <typename T>
inline Result<> WriteDataStoreChunk(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<T>& store, const std::vector<hsize_t>& h5dims,
inline Result<> WriteDataStoreChunk(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<T>& store, const nx::core::HDF5::DatasetWriter::DimsType& h5dims,
const nx::core::HDF5::DatasetWriter::DimsType& chunkDims, const IDataStore::ShapeType& index)
{
auto rank = chunkDims.size();
Expand Down Expand Up @@ -53,7 +53,7 @@ inline Result<> WriteDataStoreChunk(nx::core::HDF5::DatasetWriter& datasetWriter
}

template <>
inline Result<> WriteDataStoreChunk<bool>(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<bool>& store, const std::vector<hsize_t>& h5dims,
inline Result<> WriteDataStoreChunk<bool>(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<bool>& store, const nx::core::HDF5::DatasetWriter::DimsType& h5dims,
const nx::core::HDF5::DatasetWriter::DimsType& chunkDims, const IDataStore::ShapeType& index)
{
auto rank = chunkDims.size();
Expand Down Expand Up @@ -83,8 +83,8 @@ inline Result<> WriteDataStoreChunk<bool>(nx::core::HDF5::DatasetWriter& dataset
}

template <typename T>
inline Result<> RecursivelyWriteChunks(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<T>& store, const std::vector<hsize_t>& h5dims,
const nx::core::HDF5::DatasetWriter::DimsType& chunkDims, IDataStore::ShapeType index, const std::vector<hsize_t>& chunkLayout, uint64 i = 0)
inline Result<> RecursivelyWriteChunks(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<T>& store, const nx::core::HDF5::DatasetWriter::DimsType& h5dims,
const nx::core::HDF5::DatasetWriter::DimsType& chunkDims, IDataStore::ShapeType index, const nx::core::HDF5::DatasetWriter::DimsType& chunkLayout, uint64 i = 0)
{
// uint64 rank = chunkLayout.size();
const uint64 rank = chunkDims.size();
Expand Down Expand Up @@ -117,7 +117,7 @@ inline Result<> RecursivelyWriteChunks(nx::core::HDF5::DatasetWriter& datasetWri
}

template <typename T>
inline Result<> WriteDataStoreChunks(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<T>& store, const std::vector<hsize_t>& h5dims)
inline Result<> WriteDataStoreChunks(nx::core::HDF5::DatasetWriter& datasetWriter, const AbstractDataStore<T>& store, const nx::core::HDF5::DatasetWriter::DimsType& h5dims)
{
auto shapeDims = store.getTupleShape();
const auto componentDims = store.getComponentShape();
Expand All @@ -128,7 +128,7 @@ inline Result<> WriteDataStoreChunks(nx::core::HDF5::DatasetWriter& datasetWrite

usize rank = shapeDims.size();

std::vector<hsize_t> chunkLayout(rank);
nx::core::HDF5::DatasetWriter::DimsType chunkLayout(rank);
for(usize i = 0; i < rank; i++)
{
const bool hasRemainder = (shapeDims[i] % chunkDims[i] != 0);
Expand Down Expand Up @@ -163,7 +163,7 @@ inline Result<> WriteDataStore(nx::core::HDF5::DatasetWriter& datasetWriter, con

// Consolidate the Tuple and Component Dims into a single array which is used
// to write the entire data array to HDF5
std::vector<hsize_t> h5dims;
nx::core::HDF5::DatasetWriter::DimsType h5dims;
for(const auto& value : dataStore.getTupleShape())
{
h5dims.push_back(static_cast<hsize_t>(value));
Expand Down
2 changes: 1 addition & 1 deletion src/simplnx/Utilities/FileUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int64 LinesInFile(const std::string& filepath)
// Check if the very last character is NOT a newline character
fseek(fd, -1, SEEK_END);
char last[1];
fread(last, 1, 1, fd);
auto bytsRead = fread(last, 1, 1, fd);
if(last[0] != '\n')
{
lines++;
Expand Down
6 changes: 5 additions & 1 deletion src/simplnx/Utilities/Parsing/HDF5/IO/AttributeIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <H5Apublic.h>

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
Expand Down Expand Up @@ -414,7 +415,10 @@ Result<> AttributeIO::writeVector(const DimsVector& dims, const std::vector<T>&
return MakeErrorResult(-102, "DataType was unkown");
}

hid_t dataspaceId = H5Screate_simple(rank, dims.data(), nullptr);
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsVector::value_type x) { return static_cast<hsize_t>(x); });
hid_t dataspaceId = H5Screate_simple(rank, hDims.data(), nullptr);

if(dataspaceId >= 0)
{
// Delete any existing attribute
Expand Down
14 changes: 10 additions & 4 deletions src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,12 @@ std::vector<hsize_t> DatasetIO::getDimensions() const
return dims;
}

IdType DatasetIO::CreateDatasetChunkProperties(nonstd::span<const hsize_t> dims)
IdType DatasetIO::CreateDatasetChunkProperties(const DimsType& dims)
{
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsType::value_type x) { return static_cast<hsize_t>(x); });
auto cparms = H5Pcreate(H5P_DATASET_CREATE);
auto status = H5Pset_chunk(cparms, dims.size(), dims.data());
auto status = H5Pset_chunk(cparms, hDims.size(), hDims.data());
if(status < 0)
{
return H5P_DEFAULT;
Expand Down Expand Up @@ -505,7 +507,9 @@ Result<> DatasetIO::writeSpan(const DimsType& dims, nonstd::span<const T> values
return MakeErrorResult(-105, "DataType was unknown");
}

hid_t dataspaceId = H5Screate_simple(rank, dims.data(), nullptr);
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsType::value_type x) { return static_cast<hsize_t>(x); });
hid_t dataspaceId = H5Screate_simple(rank, hDims.data(), nullptr);
if(dataspaceId >= 0)
{
Result<> result = findAndDeleteAttribute();
Expand Down Expand Up @@ -558,7 +562,9 @@ Result<> DatasetIO::writeChunk(const DimsType& dims, nonstd::span<const T> value
return MakeErrorResult(-100, "DataType was unknown");
}

hid_t dataspaceId = H5Screate_simple(rank, dims.data(), nullptr);
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsType::value_type x) { return static_cast<hsize_t>(x); });
hid_t dataspaceId = H5Screate_simple(rank, hDims.data(), nullptr);
if(dataspaceId >= 0)
{
Result<> result = findAndDeleteAttribute();
Expand Down
2 changes: 1 addition & 1 deletion src/simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class SIMPLNX_EXPORT DatasetIO : public ObjectIO
* @param dims
* @return Returns the property ID if successful. Returns H5P_DEFAULT otherwise.
*/
static IdType CreateDatasetChunkProperties(nonstd::span<const hsize_t> dims);
static IdType CreateDatasetChunkProperties(const DimsType& dims);

static IdType CreateTransferChunkProperties(const DimsType& chunkDims);

Expand Down
4 changes: 2 additions & 2 deletions src/simplnx/Utilities/Parsing/HDF5/IO/GroupIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ size_t GroupIO::getNumChildren() const
return 0;
}

SizeType numChildren;
hsize_t numChildren;
auto err = H5Gget_num_objs(getId(), &numChildren);
if(err < 0)
{
return 0;
}
return numChildren;
return static_cast<size_t>(numChildren);
}

std::vector<std::string> GroupIO::getChildNames() const
Expand Down
4 changes: 2 additions & 2 deletions src/simplnx/Utilities/Parsing/HDF5/Readers/GroupReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ size_t GroupReader::getNumChildren() const
return 0;
}

SizeType numChildren;
hsize_t numChildren;
auto err = H5Gget_num_objs(getId(), &numChildren);
if(err < 0)
{
return 0;
}
return numChildren;
return static_cast<size_t>(numChildren);
}

std::vector<std::string> GroupReader::getChildNames() const
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <algorithm>
#include <any>
#include <string>
#include <vector>
Expand Down Expand Up @@ -161,8 +162,9 @@ class SIMPLNX_EXPORT AttributeWriter
{
return MakeErrorResult(-101, "Unknown data type");
}

hid_t dataspaceId = H5Screate_simple(rank, dims.data(), nullptr);
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsVector::value_type x) { return static_cast<hsize_t>(x); });
hid_t dataspaceId = H5Screate_simple(rank, hDims.data(), nullptr);
if(dataspaceId >= 0)
{
// Delete any existing attribute
Expand Down
6 changes: 4 additions & 2 deletions src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ void DatasetWriter::createOrOpenDataset(IdType typeId, IdType dataspaceId, IdTyp
}
}

IdType DatasetWriter::CreateDatasetChunkProperties(nonstd::span<const hsize_t> dims)
IdType DatasetWriter::CreateDatasetChunkProperties(const DimsType& chunkDims)
{
std::vector<hsize_t> hDims(chunkDims.size());
std::transform(chunkDims.begin(), chunkDims.end(), hDims.begin(), [](DimsType::value_type x) { return static_cast<hsize_t>(x); });
auto cparms = H5Pcreate(H5P_DATASET_CREATE);
auto status = H5Pset_chunk(cparms, dims.size(), dims.data());
auto status = H5Pset_chunk(cparms, hDims.size(), hDims.data());
if(status < 0)
{
return H5P_DEFAULT;
Expand Down
18 changes: 13 additions & 5 deletions src/simplnx/Utilities/Parsing/HDF5/Writers/DatasetWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ class SIMPLNX_EXPORT DatasetWriter : public ObjectWriter
{
return MakeErrorResult(-1, "DataType was unknown");
}
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsType::value_type x) { return static_cast<hsize_t>(x); });
hid_t dataspaceId = H5Screate_simple(rank, hDims.data(), nullptr);

hid_t dataspaceId = H5Screate_simple(rank, dims.data(), nullptr);
if(dataspaceId >= 0)
{
auto result = findAndDeleteAttribute();
Expand Down Expand Up @@ -144,8 +146,9 @@ class SIMPLNX_EXPORT DatasetWriter : public ObjectWriter
{
return MakeErrorResult(-100, "DataType was unkown");
}

hid_t dataspaceId = H5Screate_simple(rank, dims.data(), nullptr);
std::vector<hsize_t> hDims(dims.size());
std::transform(dims.begin(), dims.end(), hDims.begin(), [](DimsType::value_type x) { return static_cast<hsize_t>(x); });
hid_t dataspaceId = H5Screate_simple(rank, hDims.data(), nullptr);
if(dataspaceId >= 0)
{
auto result = findAndDeleteAttribute();
Expand Down Expand Up @@ -221,11 +224,16 @@ class SIMPLNX_EXPORT DatasetWriter : public ObjectWriter

/**
* @brief Applies chunking to the dataset and sets the chunk dimensions.
* @param dims
* @param chunkDims
* @return Returns the property ID if successful. Returns H5P_DEFAULT otherwise.
*/
static IdType CreateDatasetChunkProperties(nonstd::span<const hsize_t> dims);
static IdType CreateDatasetChunkProperties(const DimsType& chunkDims);

/**
* @brief
* @param chunkDims
* @return Returns the property ID if successful. Returns H5P_DEFAULT otherwise.
*/
static IdType CreateTransferChunkProperties(const DimsType& chunkDims);

/**
Expand Down

0 comments on commit 5b24757

Please sign in to comment.