Skip to content

Commit

Permalink
Merge pull request #3176 from PrincetonUniversity/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
kmantel authored Jan 30, 2025
2 parents 1ea4407 + 97b9de9 commit 5c8168f
Show file tree
Hide file tree
Showing 65 changed files with 2,957 additions and 1,004 deletions.
8 changes: 7 additions & 1 deletion .github/actions/install-pnl/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ runs:
sed -i /modeci_mdf/d requirements.txt
# pywinpty is a transitive dependency and v1.0+ removed support for x86 wheels
echo "pywinpty<1" >> env_constraints.txt
# jupyter_sever pulls jupyter_server_terminals which depends on in pywinpty >= 2.0.3
# jupyter_server >= 2 pulls jupyter_server_terminals which depends on in pywinpty >= 2.0.3
echo "jupyter_server<2" >> env_constraints.txt
# scipy >=1.9.2 doesn't provide win32 wheel and GA doesn't have working fortran on windows
echo "scipy<1.9.2" >> env_constraints.txt
Expand All @@ -67,6 +67,12 @@ runs:
echo "contourpy<1.1.0" >> env_constraints.txt
# pillow >= 10.0.0 doesn't provide win32 wheel
echo "pillow < 10.0.0" >> env_constraints.txt
# pandas >= 2.1.0 doesn't provide win32 wheel
echo "pandas < 2.1.0" >> env_constraints.txt
# llvmlite >= 0.42.0 doesn't provide win32 wheel
echo "llvmlite < 0.42.0" >> env_constraints.txt
# matplotlib >=3.8.0 doesn't provide win32 wheel
echo "matplotlib < 3.8.0" >> env_constraints.txt
fi
- name: Install updated package
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/pnl-ci-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest, windows-latest]
pnl-version: ${{ (github.event_name == 'push') && fromJSON('["head"]') || fromJSON('["head", "base"]') }}
exclude:
- os: macos-latest
pnl-version: 'base'
- os: windows-latest
pnl-version: 'base'
- python-version: '3.7'
pnl-version: 'base'
- python-version: '3.8'
pnl-version: 'base'
- python-version: '3.9'
Expand All @@ -40,14 +38,6 @@ jobs:
- python-version: '3.12'
pnl-version: 'base'

# Python 3.7 x64 on macos-14 (arm64) images is broken [0]
# and arm64 version is not available [1].
# Restrict python 3.7 macos runs to macos-13
# [0] https://github.com/actions/setup-python/issues/855
# [1] https://github.com/actions/setup-python/issues/856
- python-version: '3.7'
os: macos-latest

outputs:
on_master: ${{ steps.on_master.outputs.on-branch }}

Expand Down Expand Up @@ -80,9 +70,7 @@ jobs:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
# Block python3.7.17 on macos. see:
# https://github.com/actions/setup-python/issues/682
python-version: ${{ (matrix.os == 'macos-latest' && matrix.python-version == '3.7') && '3.7.16' || matrix.python-version }}
python-version: ${{ matrix.python-version }}

- name: Get pip cache location
shell: bash
Expand Down
27 changes: 12 additions & 15 deletions .github/workflows/pnl-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.11', '3.12']
python-version: ['3.8', '3.11', '3.12']
python-architecture: ['x64']
extra-args: ['']
os: [ubuntu, macos, windows]
Expand All @@ -51,7 +51,7 @@ jobs:
extra-args: '--forked -m "not llvm"'

# add 32-bit build on windows
- python-version: '3.8'
- python-version: '3.9'
python-architecture: 'x86'
os: windows

Expand All @@ -70,22 +70,18 @@ jobs:
# https://github.com/ionelmc/pytest-benchmark/issues/243
extra-args: '-m benchmark --benchmark-enable --benchmark-only --benchmark-min-rounds=2 --benchmark-max-time=0.001 --benchmark-warmup=off -n0 --dist=no'

# add python 3.7 with deps restricted to min supported version
- python-version: '3.7'
python-architecture: 'x64'
os: ubuntu
version-restrict: 'min'

# add python 3.8 build on macos since 3.7 is broken
# https://github.com/actions/virtual-environments/issues/4230
# use default python-architecture
# add python 3.8 with deps restricted to min supported version
# use default python architecture
# https://github.com/actions/setup-python/issues/960
- python-version: '3.8'
os: macos
version-restrict: 'min'

exclude:
# 3.7 is broken on macos-11,
# https://github.com/actions/virtual-environments/issues/4230
- python-version: '3.7'
# 3.8/x64 python is broken on aarch64 macos runners
# https://github.com/actions/setup-python/issues/960
- python-version: '3.8'
python-architecture: 'x64'
os: macos

steps:
Expand All @@ -112,7 +108,8 @@ jobs:
if: ${{ matrix.version-restrict == 'min' }}
shell: bash
run: |
sed -i '/^[^#]/s/>=/==/' *requirements.txt
# macos/bsd sed requires backup suffix argument to -i
sed -i=.bak -e '/^[^#]/s/>=/==/' *requirements.txt
git config user.name "github actions"
git config user.email "none"
git commit -a -m "Restrict version of direct dependencies to min"
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest, windows-latest]
dist: [wheel, sdist]
exclude:
# 3.7 is broken on macos-11,
# https://github.com/actions/virtual-environments/issues/4230
- python-version: '3.7'
os: macos-latest

runs-on: ${{ matrix.os }}
needs: [create-python-dist]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def calc_prob(em_preds, test_ys):
normalize_field_weights = True, # whether to normalize the field weights during memory retrieval
normalize_memories = False, # whether to normalize the memory during memory retrieval
# normalize_memories = True, # whether to normalize the memory during memory retrieval
normalize_memories = False, # whether to normalize the memory vectors
# softmax_temperature = None, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
softmax_temperature = .1, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
# softmax_temperature = ADAPTIVE, # temperature of the softmax used during memory retrieval (smaller means more argmax-like
Expand Down
2 changes: 1 addition & 1 deletion doc_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
psyneulink-sphinx-theme<1.2.4.1
psyneulink-sphinx-theme<1.2.6.0
sphinx<4.2.1
sphinx_autodoc_typehints<1.16.0
1 change: 1 addition & 0 deletions docs/source/AutodiffComposition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AutodiffComposition
*Related*

* `Composition_Learning`
* `Composition_Bias_Nodes`

.. automodule:: psyneulink.library.compositions.autodiffcomposition
:members:
Expand Down
2 changes: 2 additions & 0 deletions docs/source/Core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Core

- `TransferFunctions`

- `TimerFunctions`

- `TransformFunctions`

- `StatefulFunctions`
Expand Down
1 change: 1 addition & 0 deletions docs/source/IntegratorMechanisms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ IntegratorMechanisms

DDM
EpisodicMemoryMechanism
TimerMechanism
1 change: 1 addition & 0 deletions docs/source/NonStatefulFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Functions that do *not* depend on a previous value.
OptimizationFunctions
SelectionFunctions
TransferFunctions
TimerFunctions
TransformFunctions
10 changes: 10 additions & 0 deletions docs/source/TimerFunctions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TimerFunctions
==============

.. toctree::
:maxdepth: 3

.. automodule:: psyneulink.core.components.functions.nonstateful.timerfunctions
:members: TimerFunction, LinearTimer, AcceleratingTimer, DeceleratingTimer, AsymptoticTimer
:private-members:
:exclude-members: Parameters
7 changes: 7 additions & 0 deletions docs/source/TimerMechanism.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TimerMechanism
==============

.. automodule:: psyneulink.library.components.mechanisms.processing.integrator.timermechanism
:members:
:private-members:
:exclude-members: random, Parameters
5 changes: 3 additions & 2 deletions docs/source/TransferFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ TransferFunctions
.. toctree::
:maxdepth: 3

.. automodule:: psyneulink.core.components.functions.transferfunctions
:members: TransferFunction, Identity, Linear, Exponential, Logistic, Tanh, ReLU, Angle, Gaussian, GaussianDistort, BinomialDistort, Dropout, SoftMax, LinearMatrix, TransferWithCosts, CostFunctions
.. automodule:: psyneulink.core.components.functions.nonstateful.transferfunctions
:members: TransferFunction, Identity, Linear, Exponential, Logistic, Tanh,ReLU, Angle, Gaussian, GaussianDistort, BinomialDistort, Dropout, SoftMax, LinearMatrix, TransferWithCosts,
CostFunctions
:private-members:
:exclude-members: Parameters
20 changes: 6 additions & 14 deletions psyneulink/core/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,19 +1413,15 @@ def _is_compilation_state(p):
def _get_state_ids(self):
return [sp.name for sp in self._get_compilation_state()]

@property
@functools.cached_property
def llvm_state_ids(self):
ids = getattr(self, "_state_ids", None)
if ids is None:
ids = self._get_state_ids()
setattr(self, "_state_ids", ids)
return ids
return self._get_state_ids()

def _get_state_initializer(self, context):
def _convert(p):
x = p.get(context)
if p.name == 'matrix': # Flatten matrix
val = tuple(np.asfarray(x).flatten())
val = tuple(np.asarray(x, dtype=float).ravel())
elif isinstance(x, np.random.RandomState):
state = x.get_state(legacy=False)

Expand Down Expand Up @@ -1569,13 +1565,9 @@ def _is_compilation_param(p):
def _get_param_ids(self):
return [p.name for p in self._get_compilation_params()]

@property
@functools.cached_property
def llvm_param_ids(self):
ids = getattr(self, "_param_ids", None)
if ids is None:
ids = self._get_param_ids()
setattr(self, "_param_ids", ids)
return ids
return self._get_param_ids()

def _is_param_modulated(self, p):
try:
Expand Down Expand Up @@ -1626,7 +1618,7 @@ def _get_values(p):
elif p.name == 'num_trials_per_estimate': # Should always be int
return 0 if param is None else int(param)
elif p.name == 'matrix': # Flatten matrix
return tuple(np.asfarray(param).flatten())
return tuple(np.asarray(param, dtype=float).ravel())
return _convert(param)

return tuple(map(_get_values, self._get_compilation_params()))
Expand Down
8 changes: 5 additions & 3 deletions psyneulink/core/components/functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from . import function
from .nonstateful import selectionfunctions, objectivefunctions, optimizationfunctions, transformfunctions, \
learningfunctions, transferfunctions, distributionfunctions, fitfunctions
learningfunctions, timerfunctions, transferfunctions, distributionfunctions, fitfunctions
from . import stateful
from .stateful import integratorfunctions, memoryfunctions
from . import userdefinedfunction

from .function import *
from psyneulink.core.components.functions.nonstateful.transformfunctions import *
from psyneulink.core.components.functions.nonstateful.transferfunctions import *
from psyneulink.core.components.functions.nonstateful.timerfunctions import *
from psyneulink.core.components.functions.nonstateful.transformfunctions import *
from psyneulink.core.components.functions.nonstateful.selectionfunctions import *
from psyneulink.core.components.functions.nonstateful.distributionfunctions import *
from psyneulink.core.components.functions.nonstateful.objectivefunctions import *
Expand All @@ -21,8 +22,9 @@

__all__ = list(function.__all__)
__all__.extend(userdefinedfunction.__all__)
__all__.extend(transformfunctions.__all__)
__all__.extend(transferfunctions.__all__)
__all__.extend(timerfunctions.__all__)
__all__.extend(transformfunctions.__all__)
__all__.extend(selectionfunctions.__all__)
__all__.extend(stateful.__all__)
__all__.extend(distributionfunctions.__all__)
Expand Down
9 changes: 6 additions & 3 deletions psyneulink/core/components/functions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,16 @@ class Function_Base(Function):
Attributes
----------
variable: value
variable: number
format and default value can be specified by the :keyword:`variable` argument of the constructor; otherwise,
they are specified by the Function's :keyword:`class_defaults.variable`.
function : function
called by the Function's `owner <Function_Base.owner>` when it is executed.
value : number
the result returned by calling the Function.
COMMENT:
enable_output_type_conversion : Bool : False
specifies whether `function output type conversion <Function_Output_Type_Conversion>` is enabled.
Expand All @@ -554,7 +557,7 @@ class Function_Base(Function):
specifies whether the return value of the function is different than the shape of either is outermost dimension
(axis 0) of its its `variable <Function_Base.variable>`, or any of the items in the next dimension (axis 1).
Used to determine whether the shape of the inputs to the `Component` to which the function is assigned
should be based on the `variable <Function_Base.variable>` of the function or its `value <Function.value>`.
should be based on the `variable <Function_Base.variable>` of the function or its `value <Function_Base.value>`.
COMMENT
owner : Component
Expand Down Expand Up @@ -832,7 +835,7 @@ def convert_output_type(self, value, output_type=None):
# Note: if 2D or 1D array has more than two items, generate exception
elif output_type is FunctionOutputType.NP_0D_ARRAY:
if object_has_single_value(value):
value = np.asfarray(value)
value = np.asarray(value, dtype=float)
else:
raise FunctionError(f"Can't convert value ({value}) with more than a single number to a raw number.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def _gen_llvm_function_body(self, ctx, builder, params, _, arg_in, arg_out, *, t
v2 = builder.gep(arg_in, [ctx.int32_ty(0), ctx.int32_ty(1), ctx.int32_ty(0)])

acc_ptr = builder.alloca(ctx.float_ty)
builder.store(ctx.float_ty(-0.0), acc_ptr)
builder.store(acc_ptr.type.pointee(-0.0), acc_ptr)

kwargs = {"ctx": ctx, "v1": v1, "v2": v2, "acc": acc_ptr}
if self.metric == DIFFERENCE or self.metric == NORMED_L0_SIMILARITY:
Expand All @@ -1010,15 +1010,16 @@ def _gen_llvm_function_body(self, ctx, builder, params, _, arg_in, arg_out, *, t
denom1_acc = builder.alloca(ctx.float_ty)
denom2_acc = builder.alloca(ctx.float_ty)
for loc in numer_acc, denom1_acc, denom2_acc:
builder.store(ctx.float_ty(-0.0), loc)
builder.store(loc.type.pointee(-0.0), loc)

kwargs['numer_acc'] = numer_acc
kwargs['denom1_acc'] = denom1_acc
kwargs['denom2_acc'] = denom2_acc
inner = functools.partial(self.__gen_llvm_cosine, **kwargs)
elif self.metric == MAX_ABS_DIFF:
del kwargs['acc']
max_diff_ptr = builder.alloca(ctx.float_ty)
builder.store(ctx.float_ty(float("NaN")), max_diff_ptr)
builder.store(max_diff_ptr.type.pointee(float("NaN")), max_diff_ptr)
kwargs['max_diff_ptr'] = max_diff_ptr
inner = functools.partial(self.__gen_llvm_max_diff, **kwargs)
elif self.metric == CORRELATION:
Expand All @@ -1028,7 +1029,7 @@ def _gen_llvm_function_body(self, ctx, builder, params, _, arg_in, arg_out, *, t
acc_x2_ptr = builder.alloca(ctx.float_ty)
acc_y2_ptr = builder.alloca(ctx.float_ty)
for loc in [acc_x_ptr, acc_y_ptr, acc_xy_ptr, acc_x2_ptr, acc_y2_ptr]:
builder.store(ctx.float_ty(-0.0), loc)
builder.store(loc.type.pointee(-0.0), loc)
del kwargs['acc']
kwargs['acc_x'] = acc_x_ptr
kwargs['acc_y'] = acc_y_ptr
Expand Down Expand Up @@ -1078,7 +1079,7 @@ def _gen_llvm_function_body(self, ctx, builder, params, _, arg_in, arg_out, *, t
acc_x2 = builder.load(acc_x2_ptr)
acc_y2 = builder.load(acc_y2_ptr)

# We'll need meanx,y below
# We'll need mean_x,y below
mean_x = builder.fdiv(acc_x, n)
mean_y = builder.fdiv(acc_y, n)

Expand Down Expand Up @@ -1122,7 +1123,7 @@ def _gen_llvm_function_body(self, ctx, builder, params, _, arg_in, arg_out, *, t

# ret = 1 - abs(corr)
ret = builder.call(fabs, [corr])
ret = builder.fsub(ctx.float_ty(1), ret)
ret = builder.fsub(ret.type(1), ret)

if arg_out.type.pointee != ret.type:
# Some instances use 2d output values
Expand All @@ -1139,7 +1140,7 @@ def _gen_llvm_function_body(self, ctx, builder, params, _, arg_in, arg_out, *, t
with builder.if_else(normalize_b) as (then, otherwise):
with then:
norm_factor = input_length ** 2 if self.metric == ENERGY else input_length
normalized = builder.fdiv(ret, ctx.float_ty(norm_factor), name="normalized")
normalized = builder.fdiv(ret, ret.type(norm_factor), name="normalized")
builder.store(normalized, arg_out)
with otherwise:
builder.store(ret, arg_out)
Expand Down
Loading

0 comments on commit 5c8168f

Please sign in to comment.