Skip to content

Commit

Permalink
Merge pull request #1349 from williamfgc/hl_py_shape
Browse files Browse the repository at this point in the history
High level Python API to allow changing shape of global array
  • Loading branch information
williamfgc authored Apr 3, 2019
2 parents 2a711df + c1535bc commit e306c38
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
6 changes: 3 additions & 3 deletions source/adios2/core/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ std::map<std::string, Params> IO::GetAvailableVariables() noexcept
Variable<T> &variable = *InquireVariable<T>(name); \
variablesInfo[name]["AvailableStepsCount"] = \
helper::ValueToString(variable.m_AvailableStepsCount); \
variablesInfo[name]["Shape"] = helper::VectorToCSV(variable.m_Shape); \
variablesInfo[name]["Shape"] = helper::VectorToCSV(variable.Shape()); \
if (variable.m_SingleValue) \
{ \
variablesInfo[name]["SingleValue"] = "true"; \
Expand All @@ -262,9 +262,9 @@ std::map<std::string, Params> IO::GetAvailableVariables() noexcept
{ \
variablesInfo[name]["SingleValue"] = "false"; \
variablesInfo[name]["Min"] = \
helper::ValueToString(variable.m_Min); \
helper::ValueToString(variable.Min()); \
variablesInfo[name]["Max"] = \
helper::ValueToString(variable.m_Max); \
helper::ValueToString(variable.Max()); \
} \
}
ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
Expand Down
7 changes: 2 additions & 5 deletions source/adios2/core/Stream.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ void Stream::Write(const std::string &name, const T *data, const Dims &shape,
}
else
{
if (!shape.empty())
if (!shape.empty() && !variable->m_SingleValue)
{
if (!(shape.size() == 1 && shape.front() == adios2::LocalValueDim))
{
variable->SetShape(shape);
}
variable->SetShape(shape);
}

if (!start.empty() && !count.empty())
Expand Down
8 changes: 4 additions & 4 deletions source/adios2/core/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ class Variable : public VariableBase

size_t SubStreamsInfoSize();

Dims Shape(const size_t step) const;
Dims Shape(const size_t step = adios2::EngineCurrentStep) const;

Dims Count() const;

size_t SelectionSize() const;

std::pair<T, T> MinMax(const size_t step) const;
std::pair<T, T> MinMax(const size_t step = adios2::DefaultSizeT) const;

T Min(const size_t step) const;
T Min(const size_t step = adios2::DefaultSizeT) const;

T Max(const size_t step) const;
T Max(const size_t step = adios2::DefaultSizeT) const;

std::vector<std::vector<typename Variable<T>::Info>>
AllStepsBlocksInfo() const;
Expand Down
2 changes: 2 additions & 0 deletions testing/adios2/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ if(ADIOS2_HAVE_MPI)
SCRIPT TestBPReadMultisteps.py)
python_add_test(NAME PythonBPWriteRead2D ${test_parameters}
SCRIPT TestBPWriteRead2D.py)
python_add_test(NAME PythonBPChangingShapeHighLevelAPI ${test_parameters}
SCRIPT TestBPChangingShapeHighLevelAPI.py)
if (ADIOS2_HAVE_HDF5)
python_add_test(NAME PythonBPWriteReadHighLevelAPI_HDF5
SCRIPT TestBPWriteTypesHighLevelAPI_HDF5.py)
Expand Down
37 changes: 37 additions & 0 deletions testing/adios2/bindings/python/TestBPChangingShapeHighLevelAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#
# TestChangingShape.py
#
# Created on: April 2nd, 2019
# Author: Jeremy Logan

import numpy as np
from mpi4py import MPI
import adios2

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

# Test data
nx = [10, 15]
data = [np.zeros(nx[0]), np.ones(nx[1])]
shape = [[size * nx[0]], [size * nx[1]]]
start = [[rank * nx[0]], [rank * nx[1]]]
count = [[nx[0]], [nx[1]]]

# Write different sized arrays as separate steps
with adios2.open('out.bp', 'w', comm) as f:
f.write('z', data[0], shape[0], start[0], count[0], end_step=True)
f.write('z', data[1], shape[1], start[1], count[1], end_step=True)

# Read back arrays
with adios2.open('out.bp', 'r', comm) as f:
for f_step in f:
shape_z = int(f_step.available_variables()['z']['Shape'])
print(shape_z)
assert(shape_z == int(shape[f_step.current_step()][0]))

0 comments on commit e306c38

Please sign in to comment.