-
Notifications
You must be signed in to change notification settings - Fork 11
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
Parameter studies #265
Draft
nkoskelo
wants to merge
30
commits into
inducer:main
Choose a base branch
from
nkoskelo:uq_inner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Parameter studies #265
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e697300
Add a packer which tags the axes as uncertain.
nkoskelo 8071f8a
Prototype for interface
nkoskelo 72b9b61
Merge branch 'inducer:main' into uq_inner
nkoskelo 40e33db
Merge branch 'main' into uq_inner
nkoskelo 89ff83c
Move the parameter study definitions to their own folder and update t…
18bf0c8
Merge branch 'uq_inner' of github.com:nkoskelo/arraycontext into uq_i…
nkoskelo 48a0155
Update terminology.
nkoskelo 4106d32
Update interface.
nkoskelo 1614454
Update interface.
nkoskelo e99610b
Another iteration on the mapper.
nkoskelo 95e74ef
Add some test cases and a start on the index lambda transform.
nkoskelo 804ed42
Update the Expansion Mapper for index lambda and move the packer to p…
nkoskelo 607db79
Correct most of the type annotations.
nkoskelo d69cc00
Mypy update.
nkoskelo 904adfc
Add in the mapper for the stack operation.
nkoskelo 6a1e536
Update on concatenate and einsum operations.
nkoskelo 506dbb9
Update the packing and unpacking tests to match the decision to have …
nkoskelo 81b39bc
Add an advection example.
nkoskelo d0e806b
Fix formatting.
nkoskelo 28e5860
Move the actual transform to pytato.
nkoskelo a3739b1
Merge branch 'main' into uq_inner
nkoskelo 478fa3b
Update imports to match the location.
nkoskelo aed5080
Update.
nkoskelo 470a80c
Fix pylint errors.
nkoskelo 30ee1e8
Merge branch 'inducer:main' into uq_inner
nkoskelo 65a9e59
Add in asserts to confirm that multiple single instance programs in s…
nkoskelo c0a5fc9
Implement packing for array containers.
nkoskelo 28e7b70
Add the requirement to use the correct pytato branch.
nkoskelo 9357fc9
Update the examples.
nkoskelo ccfc9bc
Trying to get the unpack to work so that you only need to index in wi…
nkoskelo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
""" | ||
.. currentmodule:: arraycontext | ||
|
||
A :mod:`pytato`-based array context defers the evaluation of an array until its | ||
frozen. The execution contexts for the evaluations are specific to an | ||
:class:`~arraycontext.ArrayContext` type. For ex. | ||
:class:`~arraycontext.ParamStudyPytatoPyOpenCLArrayContext` | ||
uses :mod:`pyopencl` to JIT-compile and execute the array expressions. | ||
|
||
Following :mod:`pytato`-based array context are provided: | ||
|
||
.. autoclass:: ParamStudyPytatoPyOpenCLArrayContext | ||
|
||
The compiled function is stored as. | ||
.. autoclass:: ParamStudyLazyPyOpenCLFunctionCaller | ||
|
||
|
||
Compiling a Python callable (Internal) for multiple distinct instances of | ||
execution. | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: arraycontext.parameter_study | ||
""" | ||
__copyright__ = """ | ||
Copyright (C) 2020-1 University of Illinois Board of Trustees | ||
""" | ||
|
||
__license__ = """ | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
""" | ||
|
||
import sys | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
Dict, | ||
List, | ||
Mapping, | ||
Tuple, | ||
Type, | ||
) | ||
|
||
import numpy as np | ||
|
||
import pytato as pt | ||
from pytato.array import Array | ||
|
||
from arraycontext.context import ArrayContext | ||
from arraycontext.parameter_study.transform import ParameterStudyAxisTag | ||
|
||
|
||
ParamStudyTagT = Type[ParameterStudyAxisTag] | ||
|
||
if TYPE_CHECKING: | ||
import pyopencl as cl | ||
import pytato | ||
|
||
if getattr(sys, "_BUILDING_SPHINX_DOCS", False): | ||
import pyopencl as cl | ||
|
||
import logging | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def pack_for_parameter_study(actx: ArrayContext, | ||
study_name_tag_type: ParamStudyTagT, | ||
newshape: Tuple[int, ...], | ||
*args: Array) -> Array: | ||
""" | ||
Args is a list of variable names and the realized input data that needs | ||
to be packed for a parameter study or uncertainty quantification. | ||
|
||
Args needs to be in the format | ||
[v0, v1, v2, ..., vN] where N is the total number of instances you want to | ||
try. Note these may be across multiple parameter studies on the same inputs. | ||
""" | ||
|
||
assert len(args) > 0 | ||
assert len(args) == np.prod(newshape) | ||
|
||
orig_shape = args[0].shape | ||
out = actx.np.stack(args, axis=len(args[0].shape)) | ||
outshape = tuple([*list(orig_shape), newshape]) | ||
|
||
# if len(newshape) > 1: | ||
# # Reshape the object | ||
# out = out.reshape(outshape) | ||
|
||
for i in range(len(orig_shape), len(outshape)): | ||
out = out.with_tagged_axis(i, [study_name_tag_type(i - len(orig_shape), | ||
newshape[i-len(orig_shape)])]) | ||
return out | ||
|
||
|
||
def unpack_parameter_study(data: Array, | ||
study_name_tag_type: ParamStudyTagT) -> Mapping[int, | ||
List[Array]]: | ||
""" | ||
Split the data array along the axes which vary according to | ||
a ParameterStudyAxisTag whose name tag is an instance study_name_tag_type. | ||
|
||
output[i] corresponds to the values associated with the ith parameter study that | ||
uses the variable name :arg: `study_name_tag_type`. | ||
""" | ||
|
||
ndim: int = len(data.shape) | ||
out: Dict[int, List[Array]] = {} | ||
|
||
study_count = 0 | ||
for i in range(ndim): | ||
axis_tags = data.axes[i].tags_of_type(study_name_tag_type) | ||
if axis_tags: | ||
# Now we need to split this data. | ||
breakpoint() | ||
for j in range(data.shape[i]): | ||
tmp: List[Any] = [slice(None)] * ndim | ||
tmp[i] = j | ||
the_slice = tuple(tmp) | ||
# Needs to be a tuple of slices not list of slices. | ||
if study_count in out.keys(): | ||
out[study_count].append(data[the_slice]) | ||
else: | ||
out[study_count] = [data[the_slice]] | ||
if study_count in out.keys(): | ||
study_count += 1 | ||
# yield data[the_slice] | ||
|
||
return out |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you looked at this docstring rendered?