Skip to content

Commit 9451c9b

Browse files
committed
Fix to enable conda binary relocation. Attempt to fix property docstrings (incomplete).
1 parent 35eb5bd commit 9451c9b

File tree

7 files changed

+57
-24
lines changed

7 files changed

+57
-24
lines changed

cmake/version.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set(CADABRA_VERSION_MAJOR 2)
22
set(CADABRA_VERSION_MINOR 3)
33
set(CADABRA_VERSION_PATCH 6)
4-
set(CADABRA_VERSION_TWEAK 3)
5-
set(COPYRIGHT_YEARS "2001-2020")
4+
set(CADABRA_VERSION_TWEAK 4)
5+
set(COPYRIGHT_YEARS "2001-2021")
66
math(EXPR SYSTEM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
77
find_program(GIT git PATHS ${GIT_DIR})
88
if(GIT)

core/InstallPrefix.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ std::string cadabra::install_prefix()
3030
#endif
3131
}
3232

33+
const char *cadabra::cmake_install_prefix()
34+
{
35+
static const char prefix[]=CMAKE_INSTALL_PREFIX;
36+
37+
return prefix;
38+
}

core/InstallPrefix.hh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ namespace cadabra {
77

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

1213
std::string install_prefix();
1314

15+
/// Just get a constant char array with the install prefix.
16+
17+
const char *cmake_install_prefix();
18+
1419
}

core/pythoncdb/py_helpers.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "../Config.hh"
2+
#include "../InstallPrefix.hh"
23
#include <fstream>
34
#include "py_helpers.hh"
45
#include "nlohmann/json.hpp"
6+
#include <iostream>
57

68
namespace cadabra {
79

@@ -27,13 +29,14 @@ namespace cadabra {
2729

2830
std::string read_manual(const char* category, const char* name)
2931
{
30-
std::ifstream ifs(std::string(CMAKE_INSTALL_PREFIX) + "/share/cadabra2/manual/" + category + "/" + name + ".cnb");
32+
std::string manual_page = std::string(cadabra::cmake_install_prefix()) + "/share/cadabra2/manual/" + category + "/" + name + ".cnb";
33+
std::ifstream ifs(manual_page);
3134
try {
3235
nlohmann::json root=nlohmann::json::parse(ifs);
3336
return (*root["cells"].begin())["source"].get<std::string>();
3437
}
3538
catch(nlohmann::json::exception& ex) {
36-
return "Failed to collect help information";
39+
return "Failed to collect help information; no info at "+manual_page+".";
3740
}
3841
}
3942

core/pythoncdb/py_module.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace cadabra {
2323

2424
PYBIND11_MODULE(cadabra2, m)
2525
{
26+
py::options options;
27+
options.disable_function_signatures();
28+
2629
m.def("init_ipython", &init_ipython);
2730

2831
// These must be initialized in the order of which

core/pythoncdb/py_properties.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "py_properties.hh"
22
#include "py_kernel.hh"
3+
#include "py_helpers.hh"
34

45
#include "properties/Accent.hh"
56
#include "properties/AntiCommuting.hh"
@@ -223,7 +224,7 @@ namespace cadabra {
223224
// using cpp_type = typename base_type::cpp_type;
224225
using py_type = typename base_type::py_type;
225226

226-
return py_type(m, name.c_str(), py::multiple_inheritance())
227+
return py_type(m, name.c_str(), py::multiple_inheritance(), read_manual("properties", name.c_str()).c_str())
227228
.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)
228229
.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)
229230
.def("attach", &BoundPropT::attach)
@@ -239,14 +240,16 @@ namespace cadabra {
239240
using cpp_type = typename base_type::cpp_type;
240241
using py_type = typename base_type::py_type;
241242

242-
return py_type(m, std::make_shared<cpp_type>()->name().c_str(), py::multiple_inheritance())
243+
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())
243244
.def(py::init<Ex_ptr, Ex_ptr>(), py::arg("ex"), py::arg("param")=Ex{})
245+
244246
.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)
245247
.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)
246248
.def("attach", &BoundPropT::attach)
247249
.def("__str__", &BoundPropT::str_)
248250
.def("__repr__", &BoundPropT::repr_)
249-
.def("_latex_", &BoundPropT::latex_);
251+
.def("_latex_", &BoundPropT::latex_)
252+
;
250253
}
251254

252255

@@ -395,10 +398,10 @@ namespace cadabra {
395398
def_prop<Py_Vielbein>(m);
396399
def_prop<Py_InverseVielbein>(m);
397400

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

404407

tests/meld.cdb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test11():
110110

111111
test11()
112112

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

125-
test12()
124+
print("Test 12a (using meld) passed in", timeit.timeit(test12a,number=1))
125+
126+
def test12b():
127+
__cdbkernel__ = create_scope()
128+
{m,n,p,q,r,s,t,u,v,w,a,b,c,d,e,f}::Indices(vector).
129+
W_{m n p q}::WeylTensor.
130+
ex:= W_{p q r s} W_{p t r u} W_{t v q w} W_{u v s w}
131+
- W_{p q r s} W_{p q t u} W_{r v t w} W_{s v u w}
132+
- W_{m n a b} W_{n p b c} W_{m s c d} W_{s p d a}
133+
+ (1/4) W_{m n a b} W_{p s b a} W_{m p c d} W_{n s d c}:
134+
young_project_product(_)
135+
rename_dummies(_)
136+
assert(ex==0)
137+
138+
print("Test 12b (using young_*) passed in", timeit.timeit(test12b,number=1))
126139

127140
def test13():
128141
__cdbkernel__ = create_scope()
@@ -228,8 +241,8 @@ def test21():
228241
meld(_)
229242
assert(ex==0)
230243

231-
test21(); print("Test 21 passed")
232-
#print("Test 21 (using meld) passed in", timeit.timeit(test21,number=1000))
244+
#test21(); print("Test 21 passed")
245+
print("Test 21 (using meld) passed in", timeit.timeit(test21,number=1000))
233246

234247
def test22():
235248
__cdbkernel__ = create_scope()
@@ -243,8 +256,8 @@ def test22():
243256
canonicalise(_)
244257
assert(ex==0)
245258

246-
test22(); print("Test 22 passed")
247-
#print("Test 22 (using canonicalise) passed in", timeit.timeit(test22,number=1000))
259+
#test22(); print("Test 22 passed")
260+
print("Test 22 (using canonicalise) passed in", timeit.timeit(test22,number=1000))
248261

249262
# import numpy as np
250263
# {n#}::Indices;
@@ -272,13 +285,13 @@ def test23():
272285
F_{\mu\sigma}::ImplicitIndex(F^{b c}_{\mu\sigma})
273286
A_{\mu}::ImplicitIndex(A^{a b}_{\mu})
274287
Tr{#}::Trace(indices=group)
275-
ex1:= a F_{\mu\sigma} A_{\nu} A_{\rho} \epsilon^{\mu\sigma\nu\rho}:
276-
ex2:= b A_{\mu} F_{\nu\sigma} A_{\rho} \epsilon^{\mu\nu\sigma\rho}:
277-
ex:= Tr {@(ex1) + @(ex2)};
278-
print(ex)
288+
ex1:= F_{\mu\sigma} A_{\nu} A_{\rho} \epsilon^{\mu\sigma\nu\rho}:
289+
ex2:= A_{\mu} F_{\nu\sigma} A_{\rho} \epsilon^{\mu\nu\sigma\rho}:
290+
ex:= Tr {@(ex1) + @(ex2)};
291+
# This crashes here:
279292
explicit_indices(_)
280293
sort_product(_)
281-
meld(_);
294+
meld(_)
282295
assert(ex == $0$)
283296

284297
#test23()

0 commit comments

Comments
 (0)