Skip to content

Commit 824b932

Browse files
authored
Merge pull request #8 from kpeeters/master
Sync with upstream
2 parents 087a992 + ba747e0 commit 824b932

27 files changed

+1347
-656
lines changed

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ project(Cadabra)
1010
# Preamble
1111
#---------------------------------------------------------------------------
1212

13+
# Aliases for directories
14+
set(CADABRA_ROOT_DIR ${CMAKE_SOURCE_DIR})
15+
set(CADABRA_CLIENT_SERVER_DIR ${CADABRA_ROOT_DIR}/client_server)
16+
set(CADABRA_CORE_DIR ${CADABRA_ROOT_DIR}/core)
17+
set(CADABRA_FRONTEND_DIR ${CADABRA_ROOT_DIR}/frontend)
18+
set(CADABRA_IMAGES_DIR ${CADABRA_ROOT_DIR}/images)
19+
set(CADABRA_LIBS_DIR ${CADABRA_ROOT_DIR}/libs)
20+
1321
include(cmake/functions.cmake)
1422

1523
# Include Visual Studio specific build commands
@@ -59,19 +67,19 @@ install(
5967
endif()
6068
"
6169
)
70+
71+
# Are we trying to build cadabra as a c++ library?
72+
option(BUILD_AS_CPP_LIBRARY "Build cadabra as a C++ library" OFF)
73+
if (BUILD_AS_CPP_LIBRARY)
74+
enable_testing()
75+
add_subdirectory(c++lib)
76+
return()
77+
endif()
6278

6379

6480
# Include packaging logic.
6581
include(cmake/packaging.cmake)
6682

67-
# Aliases for directories
68-
set(CADABRA_ROOT_DIR ${CMAKE_SOURCE_DIR})
69-
set(CADABRA_CLIENT_SERVER_DIR ${CADABRA_ROOT_DIR}/client_server)
70-
set(CADABRA_CORE_DIR ${CADABRA_ROOT_DIR}/core)
71-
set(CADABRA_FRONTEND_DIR ${CADABRA_ROOT_DIR}/frontend)
72-
set(CADABRA_IMAGES_DIR ${CADABRA_ROOT_DIR}/images)
73-
set(CADABRA_LIBS_DIR ${CADABRA_ROOT_DIR}/libs)
74-
7583

7684
#---------------------------------------------------------------------------
7785
# User options and other notifications

JUPYTER.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,16 @@ Build the Cadabra Jupyter kernel with::
147147
The 'new' button in the Jupyterhub file browser should now offer you
148148
the option of creating a new Cadabra notebook.
149149

150+
151+
Creating a Conda package of the Cadabra Jupyter kernel
152+
------------------------------------------------------
153+
154+
To build a Conda package of the Cadabra Jupyter kernel from scratch,
155+
first install miniconda as above, and activate::
156+
157+
source ~/miniconda3/bin/activate
158+
159+
Install the prerequisites for building conda packages::
160+
161+
conda install conda-build
162+

c++lib/CMakeLists.txt

Lines changed: 285 additions & 173 deletions
Large diffs are not rendered by default.

c++lib/cadabra2++

Lines changed: 0 additions & 1 deletion
This file was deleted.

conda/build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Conda build script to build a Cadabra Jupyter kernel.
2+
3+
mkdir build
4+
cd build
5+
cmake -G $CMAKE_GENERATOR \
6+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
7+
-DCMAKE_BUILD_TYPE=Release $SRC_DIR \
8+
-DENABLE_JUPYTER=ON \
9+
-DENABLE_FRONTEND=OFF \
10+
-DCMAKE_INCLUDE_PATH=${HOME}/miniconda3/include \
11+
-DCMAKE_LIBRARY_PATH=${HOME}/miniconda3/lib \
12+
-DCMAKE_INSTALL_PREFIX=${HOME}/miniconda3
13+
14+
cmake --build .
15+
cmake --build . --target install

conda/meta.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package:
2+
name: "cadabra2-jupyter-kernel"
3+
version: "2.2.7"
4+
5+
source:
6+
path: ../
7+
8+
requirements:
9+
build:
10+
- python
11+
- setuptools
12+
- cmake
13+
- pkg-config
14+
- glibmm
15+
- zeromq
16+
- cppzmq
17+
- xtl
18+
- cryptopp
19+
- sqlite
20+
- util-linux
21+
- xeus
22+
- nlohmann_json
23+
- sympy
24+
- jupyter
25+
26+
run:
27+
- python
28+
29+
about:
30+
home: https://cadabra.science
31+
license: GPL
32+
license_family: GPL
33+
summary: Jupyter kernel for the Cadabra2 computer algebra system.

core/Algorithm.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3434
#include "properties/Indices.hh"
3535
#include "properties/Coordinate.hh"
3636
#include "properties/Symbol.hh"
37+
#include "properties/Trace.hh"
3738
#include "properties/DependsBase.hh"
3839

3940
#include <sstream>
@@ -319,7 +320,8 @@ void Algorithm::propagate_zeroes(post_order_iterator& it, const iterator& topnod
319320
return;
320321

321322
const Derivative *der=kernel.properties.get<Derivative>(walk);
322-
if(*walk->name=="\\prod" || der) {
323+
const Trace *trace=kernel.properties.get<Trace>(walk);
324+
if(*walk->name=="\\prod" || der || trace) {
323325
if(der && it->is_index()) return;
324326
walk->multiplier=rat_set.insert(0).first;
325327
it=walk;

core/Compare.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,23 @@ namespace cadabra {
11581158
return sign;
11591159
}
11601160

1161+
int Ex_comparator::can_swap_components(Ex::iterator one, Ex::iterator two, match_t subtree_comparison)
1162+
{
1163+
int tmp;
1164+
auto impi=properties.get_with_pattern<ImplicitIndex>(one, tmp);
1165+
if(impi.first) {
1166+
if(impi.first->explicit_form.size()>0) {
1167+
one=impi.first->explicit_form.begin();
1168+
}
1169+
}
1170+
impi=properties.get_with_pattern<ImplicitIndex>(two, tmp);
1171+
if(impi.first) {
1172+
if(impi.first->explicit_form.size()>0) {
1173+
two=impi.first->explicit_form.begin();
1174+
}
1175+
}
1176+
return can_swap(one, two, subtree_comparison, true);
1177+
}
11611178

11621179
// Determine the sign required to move the last factor in 'factors' to
11631180
// the right of the first. If moving left, do not count signs from

core/Compare.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ namespace cadabra {
313313
int can_swap(Ex::iterator one, Ex::iterator two, match_t subtree_comparison,
314314
bool ignore_implicit_indices=false);
315315

316+
/// Wrapper for can_swap which is meant for objects that have implicit
317+
/// indices. This checks whether a single component of A commutes or
318+
/// anticommutes with a single component of B, saying nothing about
319+
/// whether A and B commute under matrix multiplication.
320+
321+
int can_swap_components(Ex::iterator one, Ex::iterator two,
322+
match_t subtree_comparison);
323+
316324
/// Determine whether object 'one' and 'two' can be moved next
317325
/// to each other by moving either one or the other: if fix_one==true
318326
/// the first node is kept fixed, otherwise the second node is kept fixed.

core/algorithms/canonicalise.cc

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Functional.hh"
55
#include "algorithms/canonicalise.hh"
66
#include "modules/xperm_new.h"
7+
#include "properties/Trace.hh"
78
#include "properties/Traceless.hh"
89
#include "properties/Diagonal.hh"
910
#include "properties/Derivative.hh"
@@ -50,18 +51,53 @@ bool canonicalise::remove_traceless_traces(iterator& it)
5051
while(facit!=tr.end(it)) {
5152
const Traceless *trl=kernel.properties.get_composite<Traceless>(facit);
5253
if(trl) {
54+
unsigned int ihits=0;
5355
tree_exact_less_mod_prel_obj comp(&kernel.properties);
5456
std::set<Ex, tree_exact_less_mod_prel_obj> countmap(comp);
5557
index_iterator indit=begin_index(facit);
5658
while(indit!=end_index(facit)) {
59+
bool incremented_now=false;
60+
auto ind=kernel.properties.get<Indices>(indit, true);
61+
if(ind) {
62+
// The indexs need to be in the set for which the object is
63+
// traceless (if specified, otherwise accept all).
64+
if(ind->set_name==trl->index_set_name || trl->index_set_name=="") {
65+
incremented_now=true;
66+
++ihits;
67+
}
68+
}
69+
else incremented_now=true;
70+
// Having no name is treated as having the right name
5771
if(countmap.find(Ex(indit))==countmap.end()) {
5872
countmap.insert(Ex(indit));
59-
++indit;
6073
}
61-
else {
74+
else if(incremented_now) {
6275
zero(it->multiplier);
6376
return true;
6477
}
78+
++indit;
79+
}
80+
iterator parent=it;
81+
if (tr.number_of_children(it)==1 && !tr.is_head(it)) parent=tr.parent(it);
82+
const Trace *trace=kernel.properties.get<Trace>(parent);
83+
if(trace) {
84+
int tmp;
85+
auto impi=kernel.properties.get_with_pattern<ImplicitIndex>(facit, tmp);
86+
if(impi.first->explicit_form.size()>0) {
87+
// Does the explicit form have two more indices of the right type?
88+
Ex::iterator eform=impi.first->explicit_form.begin();
89+
unsigned int ehits=0;
90+
indit=begin_index(eform);
91+
while(indit!=end_index(eform)) {
92+
auto ind=kernel.properties.get<Indices>(indit, true);
93+
if(ind->set_name==trl->index_set_name && ind->set_name==trace->index_set_name) ++ehits;
94+
if(ehits - ihits > 1) {
95+
zero(it->multiplier);
96+
return true;
97+
}
98+
++indit;
99+
}
100+
}
65101
}
66102
}
67103
++facit;

0 commit comments

Comments
 (0)