Skip to content

Commit

Permalink
Fix to enable conda binary relocation. Attempt to fix property docstr…
Browse files Browse the repository at this point in the history
…ings (incomplete).
  • Loading branch information
kpeeters committed Jan 22, 2021
1 parent 35eb5bd commit 9451c9b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(CADABRA_VERSION_MAJOR 2)
set(CADABRA_VERSION_MINOR 3)
set(CADABRA_VERSION_PATCH 6)
set(CADABRA_VERSION_TWEAK 3)
set(COPYRIGHT_YEARS "2001-2020")
set(CADABRA_VERSION_TWEAK 4)
set(COPYRIGHT_YEARS "2001-2021")
math(EXPR SYSTEM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
find_program(GIT git PATHS ${GIT_DIR})
if(GIT)
Expand Down
6 changes: 6 additions & 0 deletions core/InstallPrefix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ std::string cadabra::install_prefix()
#endif
}

const char *cadabra::cmake_install_prefix()
{
static const char prefix[]=CMAKE_INSTALL_PREFIX;

return prefix;
}
7 changes: 6 additions & 1 deletion core/InstallPrefix.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace cadabra {

/// Return an absolute path to the installation path. This is
/// determined at runtime, to allow for binary distributions to be
/// installed at any location.
/// installed at any location. Note that this cannot be used
/// if the binary running the code was a python interpreter.

std::string install_prefix();

/// Just get a constant char array with the install prefix.

const char *cmake_install_prefix();

}
7 changes: 5 additions & 2 deletions core/pythoncdb/py_helpers.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "../Config.hh"
#include "../InstallPrefix.hh"
#include <fstream>
#include "py_helpers.hh"
#include "nlohmann/json.hpp"
#include <iostream>

namespace cadabra {

Expand All @@ -27,13 +29,14 @@ namespace cadabra {

std::string read_manual(const char* category, const char* name)
{
std::ifstream ifs(std::string(CMAKE_INSTALL_PREFIX) + "/share/cadabra2/manual/" + category + "/" + name + ".cnb");
std::string manual_page = std::string(cadabra::cmake_install_prefix()) + "/share/cadabra2/manual/" + category + "/" + name + ".cnb";
std::ifstream ifs(manual_page);
try {
nlohmann::json root=nlohmann::json::parse(ifs);
return (*root["cells"].begin())["source"].get<std::string>();
}
catch(nlohmann::json::exception& ex) {
return "Failed to collect help information";
return "Failed to collect help information; no info at "+manual_page+".";
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/pythoncdb/py_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace cadabra {

PYBIND11_MODULE(cadabra2, m)
{
py::options options;
options.disable_function_signatures();

m.def("init_ipython", &init_ipython);

// These must be initialized in the order of which
Expand Down
17 changes: 10 additions & 7 deletions core/pythoncdb/py_properties.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "py_properties.hh"
#include "py_kernel.hh"
#include "py_helpers.hh"

#include "properties/Accent.hh"
#include "properties/AntiCommuting.hh"
Expand Down Expand Up @@ -223,7 +224,7 @@ namespace cadabra {
// using cpp_type = typename base_type::cpp_type;
using py_type = typename base_type::py_type;

return py_type(m, name.c_str(), py::multiple_inheritance())
return py_type(m, name.c_str(), py::multiple_inheritance(), read_manual("properties", name.c_str()).c_str())
.def_static("get", [](Ex_ptr ex, const std::string& label, bool ipr) { return base_type::get_from_kernel(ex->begin(), label, ipr); }, py::arg("ex"), py::arg("label") = "", py::arg("ignore_parent_rel") = false)
.def_static("get", [](ExNode node, const std::string& label, bool ipr) { return base_type::get_from_kernel(node.it, label, ipr); }, py::arg("exnode"), py::arg("label") = "", py::arg("ignore_parent_rel") = false)
.def("attach", &BoundPropT::attach)
Expand All @@ -239,14 +240,16 @@ namespace cadabra {
using cpp_type = typename base_type::cpp_type;
using py_type = typename base_type::py_type;

return py_type(m, std::make_shared<cpp_type>()->name().c_str(), py::multiple_inheritance())
return py_type(m, std::make_shared<cpp_type>()->name().c_str(), py::multiple_inheritance(), read_manual("properties", std::make_shared<cpp_type>()->name().c_str()).c_str())
.def(py::init<Ex_ptr, Ex_ptr>(), py::arg("ex"), py::arg("param")=Ex{})

.def_static("get", [](Ex_ptr ex, const std::string& label, bool ipr) { return base_type::get_from_kernel(ex->begin(), label, ipr); }, py::arg("ex"), py::arg("label") = "", py::arg("ignore_parent_rel") = false)
.def_static("get", [](ExNode node, const std::string& label, bool ipr) { return base_type::get_from_kernel(node.it, label, ipr); }, py::arg("exnode"), py::arg("label") = "", py::arg("ignore_parent_rel") = false)
.def("attach", &BoundPropT::attach)
.def("__str__", &BoundPropT::str_)
.def("__repr__", &BoundPropT::repr_)
.def("_latex_", &BoundPropT::latex_);
.def("_latex_", &BoundPropT::latex_)
;
}


Expand Down Expand Up @@ -395,10 +398,10 @@ namespace cadabra {
def_prop<Py_Vielbein>(m);
def_prop<Py_InverseVielbein>(m);

py::enum_<Indices::position_t>(py_indices, "position_t")
.value("free", Indices::free)
.value("fixed", Indices::fixed)
.value("independent", Indices::independent)
py::enum_<Indices::position_t>(py_indices, "position_t", "How to interpret the sub/super-script position of the indices.")
.value("free", Indices::free, "Index positions are arbitrary.")
.value("fixed", Indices::fixed, "Index positions are fixed, but can be changed by canonicalisation.")
.value("independent", Indices::independent, "Index positions are independent and should never change.")
.export_values();


Expand Down
37 changes: 25 additions & 12 deletions tests/meld.cdb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test11():

test11()

def test12():
def test12a():
__cdbkernel__ = create_scope()
{m,n,p,q,r,s,t,u,v,w,a,b,c,d,e,f}::Indices(vector).
W_{m n p q}::WeylTensor.
Expand All @@ -120,9 +120,22 @@ def test12():
+ (1/4) W_{m n a b} W_{p s b a} W_{m p c d} W_{n s d c}:
meld(ex)
assert(ex==0)
print("Test 12 passed")

test12()
print("Test 12a (using meld) passed in", timeit.timeit(test12a,number=1))

def test12b():
__cdbkernel__ = create_scope()
{m,n,p,q,r,s,t,u,v,w,a,b,c,d,e,f}::Indices(vector).
W_{m n p q}::WeylTensor.
ex:= W_{p q r s} W_{p t r u} W_{t v q w} W_{u v s w}
- W_{p q r s} W_{p q t u} W_{r v t w} W_{s v u w}
- W_{m n a b} W_{n p b c} W_{m s c d} W_{s p d a}
+ (1/4) W_{m n a b} W_{p s b a} W_{m p c d} W_{n s d c}:
young_project_product(_)
rename_dummies(_)
assert(ex==0)

print("Test 12b (using young_*) passed in", timeit.timeit(test12b,number=1))

def test13():
__cdbkernel__ = create_scope()
Expand Down Expand Up @@ -228,8 +241,8 @@ def test21():
meld(_)
assert(ex==0)

test21(); print("Test 21 passed")
#print("Test 21 (using meld) passed in", timeit.timeit(test21,number=1000))
#test21(); print("Test 21 passed")
print("Test 21 (using meld) passed in", timeit.timeit(test21,number=1000))

def test22():
__cdbkernel__ = create_scope()
Expand All @@ -243,8 +256,8 @@ def test22():
canonicalise(_)
assert(ex==0)

test22(); print("Test 22 passed")
#print("Test 22 (using canonicalise) passed in", timeit.timeit(test22,number=1000))
#test22(); print("Test 22 passed")
print("Test 22 (using canonicalise) passed in", timeit.timeit(test22,number=1000))

# import numpy as np
# {n#}::Indices;
Expand Down Expand Up @@ -272,13 +285,13 @@ def test23():
F_{\mu\sigma}::ImplicitIndex(F^{b c}_{\mu\sigma})
A_{\mu}::ImplicitIndex(A^{a b}_{\mu})
Tr{#}::Trace(indices=group)
ex1:= a F_{\mu\sigma} A_{\nu} A_{\rho} \epsilon^{\mu\sigma\nu\rho}:
ex2:= b A_{\mu} F_{\nu\sigma} A_{\rho} \epsilon^{\mu\nu\sigma\rho}:
ex:= Tr {@(ex1) + @(ex2)};
print(ex)
ex1:= F_{\mu\sigma} A_{\nu} A_{\rho} \epsilon^{\mu\sigma\nu\rho}:
ex2:= A_{\mu} F_{\nu\sigma} A_{\rho} \epsilon^{\mu\nu\sigma\rho}:
ex:= Tr {@(ex1) + @(ex2)};
# This crashes here:
explicit_indices(_)
sort_product(_)
meld(_);
meld(_)
assert(ex == $0$)

#test23()
Expand Down

0 comments on commit 9451c9b

Please sign in to comment.