From 1ec63bca9c7e465727a77620b3702608ee78f485 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Sun, 5 May 2024 19:37:54 -0400 Subject: [PATCH] Removes theano --- .github/workflows/Tests.yml | 5 +- devtools/conda-envs/full-environment.yaml | 1 - devtools/conda-envs/min-ver-environment.yaml | 2 +- opt_einsum/contract.py | 128 +++++++++---------- setup.py | 4 +- 5 files changed, 66 insertions(+), 74 deletions(-) diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 2ae5535..882d2ab 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -16,10 +16,7 @@ jobs: environment: ["min-deps", "full", "min-ver"] exclude: - python-version: 3.12 - environment: "full" - include: - - python-version: 3.9 - environment: "min-deps" + environment: "min-ver" runs-on: ubuntu-latest diff --git a/devtools/conda-envs/full-environment.yaml b/devtools/conda-envs/full-environment.yaml index 26d176f..6c7084e 100644 --- a/devtools/conda-envs/full-environment.yaml +++ b/devtools/conda-envs/full-environment.yaml @@ -11,7 +11,6 @@ dependencies: - tensorflow-base - dask - sparse - - theano - pytorch-cpu - autograd - jax diff --git a/devtools/conda-envs/min-ver-environment.yaml b/devtools/conda-envs/min-ver-environment.yaml index e30ba8c..6fa8b39 100644 --- a/devtools/conda-envs/min-ver-environment.yaml +++ b/devtools/conda-envs/min-ver-environment.yaml @@ -8,7 +8,7 @@ dependencies: - nomkl # Backends - - tensorflow ==2.5.* + - tensorflow ==2.15.* - dask ==2021.* # Testing diff --git a/opt_einsum/contract.py b/opt_einsum/contract.py index 2769c2c..600f537 100644 --- a/opt_einsum/contract.py +++ b/opt_einsum/contract.py @@ -436,72 +436,68 @@ def contract(*operands_: Any, **kwargs: Any) -> ArrayType: replacement for NumPy's einsum function that optimizes the order of contraction to reduce overall scaling at the cost of several intermediate arrays. - **Parameters:** - - - **subscripts** - *(str)* Specifies the subscripts for summation. - - **\\*operands** - *(list of array_like)* hese are the arrays for the operation. - - **out** - *(array_like)* A output array in which set the sresulting output. - - **dtype** - *(str)* The dtype of the given contraction, see np.einsum. - - **order** - *(str)* The order of the resulting contraction, see np.einsum. - - **casting** - *(str)* The casting procedure for operations of different dtype, see np.einsum. - - **use_blas** - *(bool)* Do you use BLAS for valid operations, may use extra memory for more intermediates. - - **optimize** - *(str, list or bool, optional (default: ``auto``))* Choose the type of path. - - - if a list is given uses this as the path. - - `'optimal'` An algorithm that explores all possible ways of - contracting the listed tensors. Scales factorially with the number of - terms in the contraction. - - `'dp'` A faster (but essentially optimal) algorithm that uses - dynamic programming to exhaustively search all contraction paths - without outer-products. - - `'greedy'` An cheap algorithm that heuristically chooses the best - pairwise contraction at each step. Scales linearly in the number of - terms in the contraction. - - `'random-greedy'` Run a randomized version of the greedy algorithm - 32 times and pick the best path. - - `'random-greedy-128'` Run a randomized version of the greedy - algorithm 128 times and pick the best path. - - `'branch-all'` An algorithm like optimal but that restricts itself - to searching 'likely' paths. Still scales factorially. - - `'branch-2'` An even more restricted version of 'branch-all' that - only searches the best two options at each step. Scales exponentially - with the number of terms in the contraction. - - `'auto'` Choose the best of the above algorithms whilst aiming to - keep the path finding time below 1ms. - - `'auto-hq'` Aim for a high quality contraction, choosing the best - of the above algorithms whilst aiming to keep the path finding time - below 1sec. - - - **memory_limit** - *({None, int, 'max_input'} (default: `None`))* - Give the upper bound of the largest intermediate tensor contract will build. - - None or -1 means there is no limit - - `max_input` means the limit is set as largest input tensor - - a positive integer is taken as an explicit limit on the number of elements - - The default is None. Note that imposing a limit can make contractions - exponentially slower to perform. - - - **backend** - *(str, optional (default: ``auto``))* Which library to use to perform the required ``tensordot``, ``transpose`` - and ``einsum`` calls. Should match the types of arrays supplied, See - :func:`contract_expression` for generating expressions which convert - numpy arrays to and from the backend library automatically. - - **Returns:** - - - **out** - *(array_like)* The result of the einsum expression. - - **Notes:** - - This function should produce a result identical to that of NumPy's einsum - function. The primary difference is ``contract`` will attempt to form - intermediates which reduce the overall scaling of the given einsum contraction. - By default the worst intermediate formed will be equal to that of the largest - input array. For large einsum expressions with many input arrays this can - provide arbitrarily large (1000 fold+) speed improvements. - - For contractions with just two tensors this function will attempt to use - NumPy's built-in BLAS functionality to ensure that the given operation is - performed optimally. When NumPy is linked to a threaded BLAS, potential - speedups are on the order of 20-100 for a six core machine. + Parameters: + subscripts: *(str)* Specifies the subscripts for summation. + \\*operands: *(list of array_like)* hese are the arrays for the operation. + out: *(array_like)* A output array in which set the sresulting output. + dtype - *(str)* The dtype of the given contraction, see np.einsum. + order - *(str)* The order of the resulting contraction, see np.einsum. + casting - *(str)* The casting procedure for operations of different dtype, see np.einsum. + use_blas - *(bool)* Do you use BLAS for valid operations, may use extra memory for more intermediates. + optimize - *(str, list or bool, optional (default: ``auto``))* Choose the type of path. + - if a list is given uses this as the path. + - `'optimal'` An algorithm that explores all possible ways of + contracting the listed tensors. Scales factorially with the number of + terms in the contraction. + - `'dp'` A faster (but essentially optimal) algorithm that uses + dynamic programming to exhaustively search all contraction paths + without outer-products. + - `'greedy'` An cheap algorithm that heuristically chooses the best + pairwise contraction at each step. Scales linearly in the number of + terms in the contraction. + - `'random-greedy'` Run a randomized version of the greedy algorithm + 32 times and pick the best path. + - `'random-greedy-128'` Run a randomized version of the greedy + algorithm 128 times and pick the best path. + - `'branch-all'` An algorithm like optimal but that restricts itself + to searching 'likely' paths. Still scales factorially. + - `'branch-2'` An even more restricted version of 'branch-all' that + only searches the best two options at each step. Scales exponentially + with the number of terms in the contraction. + - `'auto'` Choose the best of the above algorithms whilst aiming to + keep the path finding time below 1ms. + - `'auto-hq'` Aim for a high quality contraction, choosing the best + of the above algorithms whilst aiming to keep the path finding time + below 1sec. + + memory_limit - *({None, int, 'max_input'} (default: `None`))* - Give the upper bound of the largest intermediate tensor contract will build. + - None or -1 means there is no limit + - `max_input` means the limit is set as largest input tensor + - a positive integer is taken as an explicit limit on the number of elements + + The default is None. Note that imposing a limit can make contractions + exponentially slower to perform. + + - backend - *(str, optional (default: ``auto``))* Which library to use to perform the required ``tensordot``, ``transpose`` + and ``einsum`` calls. Should match the types of arrays supplied, See + :func:`contract_expression` for generating expressions which convert + numpy arrays to and from the backend library automatically. + + Returns: + The result of the einsum expression. + + Notes: + This function should produce a result identical to that of NumPy's einsum + function. The primary difference is ``contract`` will attempt to form + intermediates which reduce the overall scaling of the given einsum contraction. + By default the worst intermediate formed will be equal to that of the largest + input array. For large einsum expressions with many input arrays this can + provide arbitrarily large (1000 fold+) speed improvements. + + For contractions with just two tensors this function will attempt to use + NumPy's built-in BLAS functionality to ensure that the given operation is + performed optimally. When NumPy is linked to a threaded BLAS, potential + speedups are on the order of 20-100 for a six core machine. """ optimize_arg = kwargs.pop("optimize", True) if optimize_arg is True: diff --git a/setup.py b/setup.py index 913a9f1..fb2281e 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,9 @@ url="https://github.com/dgasmith/opt_einsum", license='MIT', packages=setuptools.find_packages(), - python_requires='>=3.6', + python_requires='>=3.9', install_requires=[ - 'numpy>=1.7', + 'numpy>=1.23', ], extras_require={ 'tests': [