Skip to content

Commit

Permalink
Gradient Descent (#181)
Browse files Browse the repository at this point in the history
* Added ArbitraryDistributionVolumeEmitter

* Updated particle weight calculation

* renamed thermionic_emission test directory to emission

* arbitrary seed from uniform distribution

* Bug fixes and changes to test

* add test for arbitrary seeding

* Changed position sampling, added test

* Removed unused imports and code

* revert traceback printout

* Added comments for binning particle positions

* increased rtol for test

* Allow input of any 2d array, add interpolation of 2d array onto current simulation grid

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated changelog

* update version

* created steady_state_descent.py file

* Added coarsening algorithm

* Added ability to read numpy data and coarsen grid

* Added regression function calculation

* Solve system of equations rather than curve fit

* Use skimage block_reduce

* Hard coded inverse exponential solve

* take mean if exponential equation can't be solved

* Added special cases to use linear regression

* Update docstring

* Added command line arguments

* Modified linear regression logic and added main function

* Added entry point

* Change output file name

* Change output file name

* Fixed interpolate grid

* updated arbitrary distribution emitter test

* Fix interpolation logic

* Changed to take in exact prediction timestep rather than a multiple

* Added ability to specify save directory

* Updated docstrings, removed unneeded files

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added gradient descent test, refactored code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Changed test parameters

* Increase rtol of arbitrary seed test by 0.01

* Update mewarpx/mewarpx/utils_store/plasma_density_oracle.py

Co-authored-by: Roelof Groenewald <[email protected]>

* Update changelog

* Update version

* Add controller for plasma density oracle

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* WIP oracle control

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Allow oracle control bins to be overridden

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added command line arguments

* Fixed bugs, added info logging

* added ability to modify run_script

* removed unnecessary code

* Cleaned up code

* Refactored code to be clearer

* Update docstrings

* Added test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added documentation about oracle_control

* Updated changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixed TOTAL_TIME calculation

* update wheel in docker build

* change numpy to oldest-supported-numpy for docker

* Updated formatting and documentation

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
KZhu-ME and pre-commit-ci[bot] authored May 31, 2022
1 parent 0d2d104 commit cc6f6d7
Show file tree
Hide file tree
Showing 18 changed files with 688 additions and 18 deletions.
17 changes: 16 additions & 1 deletion mewarpx/changelog.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
Version, Physics version, Date, List of changes
8.2.1, 2, In progress, "
8.3.0, 2, In progress, "

**Features**:

- Added
:class:`mewarpx.utils_store.plasma_density_oracle.PlasmaDensityOracle` to
predict particle densities at a given time point based on 3 input data points.
- Added :class:`mewarpx.utils_store.oracle_control.OracleControl`
as a wrapper to automate calling
:class:`mewarpx.utils_store.plasma_density_oracle.PlasmaDensityOracle`
by automatically determining the best parameters for it.

"
8.2.1, 2, 5/31/2022, "

**Other changes**:

Expand All @@ -8,12 +21,14 @@ Version, Physics version, Date, List of changes
"
8.2.0, 2, 5/11/2022, "


**Features**:

- Added :class:`mewarpx.utils_store.json_util.MEWarpXEncoder` to encode a
runinfo object into a JSON string.
- Changed runinfo to be saved as JSON file instead of dpkl file.

"
8.1.1, 2, 5/9/2022, "

**API Changes**:
Expand Down
3 changes: 2 additions & 1 deletion mewarpx/medocker/docker_shared/python_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ INSTALL_CMD="python3 -m pip install --no-build-isolation "
# internal warnings
# https://github.com/Nike-Inc/gimme-aws-creds/issues/158
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade wheel
python3 -m pip install --upgrade setuptools keyring keyrings.alt

# Build dependency of cmake
Expand All @@ -28,7 +29,7 @@ ${INSTALL_CMD} llvmlite

# The builds of scipy and h5py on aarch64 depends on having these already installed
${INSTALL_CMD} cython
${INSTALL_CMD} numpy
${INSTALL_CMD} oldest-supported-numpy
${INSTALL_CMD} pkgconfig

${INSTALL_CMD} numba
Expand Down
2 changes: 1 addition & 1 deletion mewarpx/mewarpx/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# One and only one place to store the version info
# https://stackoverflow.com/questions/458550/standard-way-to-embed-version-into-python-package
__version_info__ = (8, 2, 1)
__version_info__ = (8, 3, 0)
__version__ = '.'.join([str(x) for x in __version_info__])

# One and only one place to store the Physics version
Expand Down
19 changes: 12 additions & 7 deletions mewarpx/mewarpx/emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,8 +2067,7 @@ def _get_x_coords(self, npart):
class ArbitraryDistributionVolumeEmitter(VolumeEmitter):

"""Varies density based on given particle density array. NPPC for each
species must be an integer greater than or equal to 1. Can only be used
with FixedNumberInjector."""
species must be an integer greater than or equal to 1."""

geoms = ["XZ"]

Expand Down Expand Up @@ -2100,15 +2099,21 @@ def _interpolate_grid(input_grid):
output_grid (np.ndarray): 2d array of current simulation dimensions
interpolated values from input_grid
"""

input_shape = input_grid.shape
input_x = np.linspace(0.5, input_shape[0] - 0.5, input_shape[0])
input_z = np.linspace(0.5, input_shape[1] - 0.5, input_shape[1])
# pad edges with current edge values by 1 to avoid NaN when interpolating
input_x = np.linspace(-0.5, input_shape[0] + 0.5, input_shape[0] + 2)
input_z = np.linspace(-0.5, input_shape[1] + 0.5, input_shape[1] + 2)
input_grid = np.pad(input_grid, (1,), "linear_ramp")

input_zz, input_xx = np.meshgrid(input_z, input_x)

input_xx = input_xx * mwxrun.nx/input_shape[0]
input_zz = input_zz * mwxrun.nz/input_shape[1]
input_coord = np.column_stack([input_xx.flatten(), input_zz.flatten()])

output_xx = input_xx * mwxrun.nx/input_shape[0]
output_zz = input_zz * mwxrun.nz/input_shape[1]
output_x = np.linspace(0.5, mwxrun.nx - 0.5, mwxrun.nx)
output_z = np.linspace(0.5, mwxrun.nz - 0.5, mwxrun.nz)
output_zz, output_xx = np.meshgrid(output_z, output_x)

output_grid = scipy.interpolate.griddata(
input_coord, input_grid.flatten(), (output_xx, output_zz)
Expand Down
Loading

0 comments on commit cc6f6d7

Please sign in to comment.