diff --git a/.gitmodules b/.gitmodules index 73ec8d2..f5ad008 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "deps/libcanon"] path = deps/libcanon url = https://github.com/tschijnmo/libcanon.git +[submodule "deps/DummyRDD"] + path = deps/DummyRDD + url = https://github.com/DrudgeCAS/DummyRDD diff --git a/README.rst b/README.rst index 13d0de4..a15859d 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ -.. image:: https://circleci.com/gh/tschijnmo/drudge.svg?style=shield - :target: https://circleci.com/gh/tschijnmo/drudge +.. image:: https://circleci.com/gh/DrudgeCAS/drudge.svg?style=shield + :target: https://circleci.com/gh/DrudgeCAS/drudge -.. image:: https://travis-ci.org/tschijnmo/drudge.svg?branch=master - :target: https://travis-ci.org/tschijnmo/drudge +.. image:: https://travis-ci.org/DrudgeCAS/drudge.svg?branch=master + :target: https://travis-ci.org/DrudgeCAS/drudge .. image:: https://coveralls.io/repos/github/tschijnmo/drudge/badge.svg?branch=master :target: https://coveralls.io/github/tschijnmo/drudge?branch=master @@ -58,6 +58,14 @@ with heavy dependence on tensor contraction and sums of tensor contractions, substantial optimization could be given. +Documentation/Installation +------ +Documentation Pages are located at the github pages `documentation`_ site. +Installation instructions can be seen at `installation`_. + + + + Drudge is developed by Jinmo Zhao and Prof Gustavo E Scuseria at Rice University, and was supported as part of the Center for the Computational Design of Functional Layered Materials, an Energy Frontier Research Center funded by @@ -71,3 +79,5 @@ Award DE-SC0012575. .. _Clifford algebras: https://en.wikipedia.org/wiki/Clifford_algebra .. _su(2) algebra: https://en.m.wikipedia.org/wiki/Special_unitary_group#Lie_Algebra .. _gristmill: https://github.com/tschijnmo/gristmill +.. _documentation: https://drudgecas.github.io/drudge/ +.. _installation: https://drudgecas.github.io/drudge/install.html diff --git a/deps/DummyRDD b/deps/DummyRDD new file mode 160000 index 0000000..0089341 --- /dev/null +++ b/deps/DummyRDD @@ -0,0 +1 @@ +Subproject commit 00893412e5c52bde2dfa5457500db0d8f8616202 diff --git a/drudge/drs.py b/drudge/drs.py index d9c465b..eb976f3 100644 --- a/drudge/drs.py +++ b/drudge/drs.py @@ -347,13 +347,13 @@ def __missing__(self, key: str): if key.startswith('__') and key.endswith('__'): raise KeyError(key) - for entry, excl in self._path: - if hasattr(entry, key) and key not in excl: - resolv = getattr(entry, key) + for entry, excl in self._path: #For every module/variable in the environment + if hasattr(entry, key) and key not in excl: # check if our key is defined in it + resolv = getattr(entry, key) # if found, pull it from the environment break else: continue - else: + else: # if we didn't find earlier and break, default to defining it instead resolv = DrsSymbol(self._drudge, key) return resolv diff --git a/drudge/drudge.py b/drudge/drudge.py index 8f9f6a0..f28bd7a 100644 --- a/drudge/drudge.py +++ b/drudge/drudge.py @@ -3490,7 +3490,7 @@ def _union(orig, new): def _inters(orig, new): - """Make the interaction of two sets. + """Make the intersection of two sets. If the original is a None value, a new set will be created with elements from the new set. When both operands are None, the result is None. diff --git a/drudge/utils.py b/drudge/utils.py index ac489e3..d97e349 100644 --- a/drudge/utils.py +++ b/drudge/utils.py @@ -89,7 +89,7 @@ def __call__(self, *args, **kwargs): return self._func(*args, **kwargs) -class _EnumSymbsMeta(ManagedProperties): +class _EnumSymbsMeta(type): """The meta class for enumeration symbols. The primary purpose of this metaclass is to set the concrete singleton @@ -140,7 +140,7 @@ class EnumSymbs(AtomicExpr, metaclass=_EnumSymbsMeta): Subclasses can set `_symbs_` inside the class body to be a sequence of string pairs. Then attributes named after the first field of the pairs will - be created, with the LaTeX form controlled by the second pair. + be created, with the LaTeX form controlled by the second field of the pair. The resulted values are valid SymPy expressions. They are ordered according to their order in the given enumeration sequence. @@ -222,6 +222,15 @@ def __rsub__(self, other): """ return self.__sub__(other) + def __getstate__(self): + """Retrieve state of object for pickling/serialization""" + return {slot: getattr(self, slot) for slot in self.__slots__} + + def __setstate__(self, state): + """Create state of object for deserialization""" + for key, value in state.items(): + setattr(self, key, value) + def sort_key(self, order=None): return ( self.class_key(), diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..bfba7e3 --- /dev/null +++ b/install.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# +# INSTRUCTIONS: +# 0) Check the ENV_NAME doesn't collide with previously defined environments +# - List current environments with `conda env list` +# 1) Run this With `source install_in.sh` +# + +ENV_NAME=drudge + +# Ensure latest conda installed +conda update -n base -c defaults conda -y + +# Conda env creation +echo "Creating Conda Environment" +conda create --name $ENV_NAME python=3.9 -y +conda activate $ENV_NAME + +# Choose the correct conda package list +if [[ "$(uname -m)" == "x86_64" ]]; then + # conda install --name $ENV_NAME --file install/env_x86.txt -y + conda install conda-forge::gcc==14.2.0 -y + conda install conda-forge::gxx_linux-64==14.2.0 -y +else + # echo "CONDA ENVIRONMENT FOR arm64 NOT YET VERIFIED" + # conda install --name $ENV_NAME --file install/env_arm.txt -y + echo "" +fi + +conda install IPython==8.15.0 -y +conda install sympy==1.13.2 -y +conda install pyspark==3.4.1 -y +conda install jinja2 -y +conda install pytest -y +conda install coveralls -y + +# Force Conda into Base, then into created environment +echo "Initializing Conda" +conda init +conda activate $ENV_NAME + + +# Clone repository +echo "Cloning Submodules" +git submodule update --init --recursive + + +# Setup Vars +echo "Setting env vars" +export PYTHONPATH=$(pwd) +export DUMMY_SPARK=1 + +# Build cpp files +echo "Building cpp files" +python3 setup.py build +python3 setup.py install + +# Copy the cpp files where needed +# echo "Moving cpp files" +# cp build/lib.linux-x86_64-cpython-39/drudge/wickcore.cpython-39-x86_64-linux-gnu.so drudge/ +# cp build/lib.linux-x86_64-cpython-39/drudge/canonpy.cpython-39-x86_64-linux-gnu.so drudge/ + +# Add Dummy Spark +echo "Getting Dummy Spark" +git clone https://github.com/DrudgeCAS/DummyRDD ../dummyRDD/ + +echo "Moving Dummy Spark" +cp -r ../dummyRDD/dummy_spark . + +# Remove unneeded folder +rm -rf ../dummyRDD/ + +echo "Installation Complete!" +echo "Assuming you ran this with '\''source'\'' you'\''re now inside the drudge folder. To get started using drudge you'll want to do 3 things after opening your chosen IDE to your code location:" +echo " 1) Ensure your Python Interpreter is set to the Conda Environment Python we just created" +echo " 2) Ensure this conda environment is activated with '\''conda activate drudge '\'' in the terminal which runs your program" +echo " 3) Set your pythonpath to the build directory of this repository like '\''export PYTHONPATH=\$PYTHONPATH:/path/to/drudge/build'\''" +echo " " +echo "Have Fun!" diff --git a/install/env_arm.txt b/install/env_arm.txt new file mode 100644 index 0000000..06e50a5 --- /dev/null +++ b/install/env_arm.txt @@ -0,0 +1,6 @@ +IPython==8.15.0 +sympy==1.13.2 +pyspark==3.4.1 +jinja2 +pytest +coveralls diff --git a/install/env_x86.txt b/install/env_x86.txt new file mode 100644 index 0000000..3d1e055 --- /dev/null +++ b/install/env_x86.txt @@ -0,0 +1,8 @@ +conda-forge::gcc==14.2.0 +conda-forge::gxx_linux-64==14.2.0 +IPython==8.15.0 +sympy==1.13.2 +pyspark==3.4.1 +jinja2 +pytest +coveralls diff --git a/tests/free_algebra_test.py b/tests/free_algebra_test.py index a45075e..45448b0 100644 --- a/tests/free_algebra_test.py +++ b/tests/free_algebra_test.py @@ -19,7 +19,7 @@ from conftest import skip_in_spark -@pytest.fixture(scope='module') +@pytest.fixture def free_alg(spark_ctx): """Initialize the environment for a free algebra.""" diff --git a/tests/nuclear_test.py b/tests/nuclear_test.py index 45093fc..6e5ccc2 100644 --- a/tests/nuclear_test.py +++ b/tests/nuclear_test.py @@ -113,6 +113,7 @@ def test_varsh_872_5(nuclear: NuclearBogoliubovDrudge): TODO: Investigate its failure in Apache Spark environment. """ + dr = nuclear a, alpha, b, beta, b_prm, beta_prm = symbols( 'a alpha b beta bprm betaprm', integer=True @@ -132,7 +133,7 @@ def test_varsh_872_5(nuclear: NuclearBogoliubovDrudge): ) for sums_i in [sums, reversed(sums)]: tensor = dr.sum(*sums_i, amp) - res = tensor.deep_simplify().merge() + res = tensor.simplify_am().merge() #previously used deep_simplify assert res.n_terms == 1 term = res.local_terms[0] assert len(term.sums) == 0 @@ -208,7 +209,7 @@ def test_wigner3j_sum_to_wigner6j(nuclear: NuclearBogoliubovDrudge): ((-1) ** (j3 - m3) / (2 * j3 + 1)) * KroneckerDelta(j3, jprm3) * KroneckerDelta(m3, mprm3) * Wigner6j(j1, j2, j3, j4, j5, j6) - ).expand().simplify() + ).expand().simplify(doit=False) # For performance reason, just test a random arrangement of the summations. random.shuffle(sums)