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

pyzag integration #162

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a04e057
Working on basic interface
reverendbedford Aug 6, 2024
4e8667c
Not working, need to figure out new bindings
reverendbedford Aug 6, 2024
8fc632d
Almost there, need some help from gary
reverendbedford Aug 7, 2024
feb3852
Fixed LabeledMatrix::fill, worked around other issue
reverendbedford Aug 7, 2024
57ad0dd
Gary's fix for the segfault thing
reverendbedford Aug 7, 2024
ad0adec
On to the next random error
reverendbedford Aug 7, 2024
6e9db73
Fixed the adjoint tests, in the eventuallity this gets fixed
reverendbedford Aug 7, 2024
1914d79
Updated adjoint tolerances
reverendbedford Aug 7, 2024
6b3358c
Fix inference mode bug
hugary1995 Aug 7, 2024
bb67eba
Basic working version
reverendbedford Aug 8, 2024
2fd29cf
Code review
reverendbedford Aug 9, 2024
b7c9f25
Deterministic demo model seems to work
reverendbedford Aug 13, 2024
ccaa4da
Tensor valued parameter update doesn't take
reverendbedford Aug 14, 2024
532b165
Nevermind
reverendbedford Aug 14, 2024
3840667
Start at a test
reverendbedford Aug 14, 2024
e127115
A regularized version of linear interpolation also does not work
hugary1995 Aug 14, 2024
ac57a00
See what happens in the unit test ScalarLinearInterpolation1.i
hugary1995 Aug 14, 2024
2dcea73
nvmd
hugary1995 Aug 14, 2024
8df94f4
Fixed test so that it runs
reverendbedford Aug 14, 2024
fe71204
Gary is right, other vector parameters work
reverendbedford Aug 14, 2024
1785cf8
Fix interpolation AD
hugary1995 Aug 14, 2024
5beb186
Simple test to demonstrate problem
reverendbedford Aug 14, 2024
660bfe5
Fixed batch size thing
reverendbedford Aug 15, 2024
427f4ce
Deterministic example completed
reverendbedford Aug 15, 2024
7e4a180
Everything trains
reverendbedford Aug 19, 2024
3d2fdb3
Everything seems to work, maybe give a bit more work to the examples …
reverendbedford Aug 20, 2024
d3177c3
Critical fix for static recovery models
reverendbedford Aug 20, 2024
3063759
Slight tweaks to the stochastic example
reverendbedford Sep 3, 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
11 changes: 0 additions & 11 deletions include/neml2/models/LinearInterpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ class LinearInterpolation : public Interpolation<T>
*/
template <typename T2>
T2 mask(const T2 & in, const torch::Tensor & m) const;

/// Batch shape of the interpolant, excluding the last dimension which is the interpolation axis
const TensorShape _interp_batch_sizes;
/// Starting abscissa of each interval
const Scalar & _X0;
/// Ending abscissa of each interval
const Scalar & _X1;
/// Starting ordinate of each interval
const T & _Y0;
/// Slope of each interval
const T & _slope;
};

template <typename T>
Expand Down
67 changes: 67 additions & 0 deletions include/neml2/models/SmoothLinearInterpolation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024, UChicago Argonne, LLC
// All Rights Reserved
// Software Name: NEML2 -- the New Engineering material Model Library, version 2
// By: Argonne National Laboratory
// OPEN SOURCE LICENSE (MIT)
//
// 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.

#pragma once

#include "neml2/models/Interpolation.h"

namespace neml2
{
/**
* @brief Regularized version of neml2::LinearInterpolation rendered fully differentiable
*/
template <typename T>
class SmoothLinearInterpolation : public Interpolation<T>
{
public:
static OptionSet expected_options();

SmoothLinearInterpolation(const OptionSet & options);

protected:
void set_value(bool out, bool dout_din, bool d2out_din2) override;

private:
/// @returns the smooth interpolation factor given the interval offset between 0 and 1
Scalar smooth_interp_factor(const Scalar & x) const;

/// @returns the first derivative of the smooth interpolation function
Scalar d_smooth_interp_factor(const Scalar & x) const;

/// Sharpness of the smooth interpolation
const Real _k;
/// Starting abscissa of each interval
const Scalar & _X0;
/// Ending abscissa of each interval
const Scalar & _X1;
/// Starting ordinate of each interval
const T & _Y0;
/// Ending ordinate of each interval
const T & _Y1;
};

typedef SmoothLinearInterpolation<Scalar> ScalarSmoothLinearInterpolation;
typedef SmoothLinearInterpolation<Vec> VecSmoothLinearInterpolation;
typedef SmoothLinearInterpolation<SR2> SR2SmoothLinearInterpolation;
} // namespace neml2
53 changes: 53 additions & 0 deletions include/neml2/models/solid_mechanics/KocksMeckingIntercept.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2024, UChicago Argonne, LLC
// All Rights Reserved
// Software Name: NEML2 -- the New Engineering material Model Library, version 2
// By: Argonne National Laboratory
// OPEN SOURCE LICENSE (MIT)
//
// 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.

#pragma once

#include "neml2/models/NonlinearParameter.h"

namespace neml2
{
/**
* @brief A scalar-valued parameter defined by (C-B) / A
*/
class KocksMeckingIntercept : public NonlinearParameter<Scalar>
{
public:
static OptionSet expected_options();

KocksMeckingIntercept(const OptionSet & options);

protected:
void set_value(bool out, bool dout_din, bool d2out_din2) override;

/// KM A
const Scalar & _A;

/// KM B
const Scalar & _B;

/// KM C
const Scalar & _C;
};
}
4 changes: 0 additions & 4 deletions include/neml2/tensors/LabeledMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class LabeledMatrix : public LabeledTensor<LabeledMatrix, 2>
const LabeledAxis & axis,
const torch::TensorOptions & options = default_tensor_options());

/// Fill another matrix into this matrix.
/// The item set of the other matrix must be a subset of this matrix's item set.
void fill(const LabeledMatrix & other, bool recursive = true);

/// Chain rule product of two derivatives
LabeledMatrix chain(const LabeledMatrix & other) const;
};
Expand Down
9 changes: 9 additions & 0 deletions include/neml2/tensors/LabeledTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ class LabeledTensor
/// Get a specific labeled axis
const LabeledAxis & axis(Size i = 0) const { return *_axes[i]; }

/**
* @brief Fill with another LabeledTensor that matches this one on all but one axis
*
* @param Derived The LabeledTensor to fill from
* @param Size The common axis, default 0
* @param bool If true, fill recursively down subaxes
*/
void fill(const Derived & other, Size odim = 0, bool recursive = true);

protected:
/// The tensor
Tensor _tensor;
Expand Down
4 changes: 0 additions & 4 deletions include/neml2/tensors/LabeledVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class LabeledVector : public LabeledTensor<LabeledVector, 1>

/// Slice the logically 1D tensor by a single sub-axis
LabeledVector slice(const std::string & name) const;

/// Fill (override) another vector into this vector.
/// The item set of the other vector must be a subset of this vector's item set.
void fill(const LabeledVector & other, bool recursive = true);
};

namespace utils
Expand Down
4 changes: 4 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ add_custom_target(python-stub ALL
# Artifacts
configure_file(neml2/__init__.py ${NEML2_BINARY_DIR}/python/neml2/__init__.py COPYONLY)
configure_file(neml2/visualization.py ${NEML2_BINARY_DIR}/python/neml2/visualization.py COPYONLY)
configure_file(neml2/pyzag/__init__.py ${NEML2_BINARY_DIR}/python/neml2/pyzag/__init__.py COPYONLY)
configure_file(neml2/pyzag/interface.py ${NEML2_BINARY_DIR}/python/neml2/pyzag/interface.py COPYONLY)
install(FILES
neml2/__init__.py
neml2/visualization.py
neml2/pyzag/__init__.py
neml2/pyzag/interface.py
${NEML2_BINARY_DIR}/python/neml2/__init__.pyi
${NEML2_BINARY_DIR}/python/neml2/base.pyi
${NEML2_BINARY_DIR}/python/neml2/math.pyi
Expand Down
Loading
Loading