Skip to content

Commit

Permalink
Document and cleanup kernel options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Peeters committed Nov 10, 2024
1 parent 3fdb0f9 commit af5955b
Show file tree
Hide file tree
Showing 11 changed files with 918 additions and 29 deletions.
23 changes: 2 additions & 21 deletions core/pythoncdb/py_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ namespace cadabra {
.def(pybind11::init<bool>())
.def_readonly_static("version", &Kernel::version)
.def_readonly_static("build", &Kernel::build)
.def_readonly("scalar_backend", &Kernel::scalar_backend)
.def_readwrite("display_fractions", &Kernel::display_fractions)
.def_readwrite("call_embedded_python_functions", &Kernel::call_embedded_python_functions)
.def_readwrite("scalar_backend", &Kernel::scalar_backend)
.def("warn", &Kernel::warn, pybind11::arg("msg"), pybind11::arg("level") = 0)
.def("configure_warnings", kernel_configure_warnings);

Expand All @@ -135,26 +136,6 @@ namespace cadabra {
Kernel* kernel = create_scope();
m.attr("__cdbkernel__") = pybind11::cast(kernel);

m.def("kernel", [](pybind11::kwargs dict) {
Kernel *k = get_kernel_from_scope();
for (auto& item : dict) {
std::string key = item.first.cast<std::string>();
if (key == "scalar_backend") {
std::string val = item.second.cast<std::string>();
if (val == "sympy") k->scalar_backend = Kernel::scalar_backend_t::sympy;
else if (val == "mathematica") k->scalar_backend = Kernel::scalar_backend_t::mathematica;
else throw ArgumentException("scalar_backend must be 'sympy' or 'mathematica'.");
}
else if(key == "call_embedded_python_functions") {
bool val = item.second.cast<bool>();
k->call_embedded_python_functions=val;
}
else {
throw ArgumentException("unknown argument '" + key + "'.");
}
}
});

m.def("create_scope", &create_scope,
pybind11::return_value_policy::take_ownership);
m.def("create_scope_from_global", &create_scope_from_global,
Expand Down
1 change: 1 addition & 0 deletions doc/the_cadabra_book.tex
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ \chapter{Manipulating expressions}
%==================================================================
\chapter{Writing your own packages}
\input{ref_programming}
\input{ref_kernel}
\input{ref_c++_library}

%==================================================================
Expand Down
8 changes: 4 additions & 4 deletions examples/input_format.cnb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
"cell_id": 14839438110559465856,
"cell_origin": "client",
"cell_type": "input",
"source": "kernel(call_embedded_python_functions=True)"
"source": "__cdbkernel__.call_embedded_python_functions=True"
},
{
"cell_id": 13320774661377944897,
Expand All @@ -271,12 +271,12 @@
"cell_type": "input",
"cells": [
{
"cell_id": 14670749530413958279,
"cell_id": 17277331614704024525,
"cell_origin": "server",
"cell_type": "latex_view",
"cells": [
{
"cell_id": 16922367421830269796,
"cell_id": 1818314009831986771,
"cell_origin": "server",
"cell_type": "input_form",
"source": "A + B + D"
Expand Down Expand Up @@ -306,7 +306,7 @@
"cell_id": 16834549477742454181,
"cell_origin": "client",
"cell_type": "input",
"source": "kernel(call_embedded_python_functions=False)"
"source": "__cdbkernel__.call_embedded_python_functions=False"
},
{
"cell_id": 13066277311614345372,
Expand Down
152 changes: 152 additions & 0 deletions examples/ref_accents.cnb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"cell_id": 15346339992211116796,
"cells": [
{
"cell_id": 16459148063967060997,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 6792806555766337768,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "\\section*{Accents}\n\nIt often occurs that you want to put a hat or tilde or some other\naccent on top of a symbol, as a means to indicate a slightly different\nobject. In most of these cases, the properties of the normal symbol\nand the accented symbol are identical. Such accents are declared using\nthe \\prop{Accent} property, as in"
}
],
"hidden": true,
"source": "\\section*{Accents}\n\nIt often occurs that you want to put a hat or tilde or some other\naccent on top of a symbol, as a means to indicate a slightly different\nobject. In most of these cases, the properties of the normal symbol\nand the accented symbol are identical. Such accents are declared using\nthe \\prop{Accent} property, as in"
},
{
"cell_id": 16057021908384386123,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 11553527963445813639,
"cell_origin": "server",
"cell_type": "latex_view",
"source": "\\begin{dmath*}{}\\text{Property Accent attached to~}\\backslash\\texttt{hat}\\{\\#\\}.\\end{dmath*}"
}
],
"source": "\\hat{#}::Accent;"
},
{
"cell_id": 16972251731688036769,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 12965346805565846436,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "This automatically makes all symbols with hats inherit the properties\nof the unhatted symbols,"
}
],
"hidden": true,
"source": "This automatically makes all symbols with hats inherit the properties\nof the unhatted symbols,"
},
{
"cell_id": 17676320454094676305,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 15299440598427965471,
"cell_origin": "server",
"cell_type": "latex_view",
"cells": [
{
"cell_id": 4840539522801871562,
"cell_origin": "server",
"cell_type": "input_form",
"source": "\\hat{\\chi} \\psi"
}
],
"source": "\\begin{dmath*}{}\\widehat{\\chi} \\psi\\end{dmath*}"
},
{
"cell_id": 11746078301643897089,
"cell_origin": "server",
"cell_type": "latex_view",
"cells": [
{
"cell_id": 14275938498403721147,
"cell_origin": "server",
"cell_type": "input_form",
"source": "-\\psi \\hat{\\chi}"
}
],
"source": "\\begin{dmath*}{}-\\psi \\widehat{\\chi}\\end{dmath*}"
}
],
"source": "\\hat{#}::Accent.\n{\\psi, \\chi}::AntiCommuting.\n{\\psi, \\chi}::SortOrder.\nex:= \\hat{\\chi} \\psi;\nsort_product(_);"
},
{
"cell_id": 16254242404429757988,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 2296267821247394715,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "If you want to put an accent on an object with indices, wrap the\naccent around the entire object, do not leave the indices outside."
}
],
"hidden": true,
"source": "If you want to put an accent on an object with indices, wrap the\naccent around the entire object, do not leave the indices outside."
},
{
"cell_id": 4078046895693549704,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 14719176952547821212,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "Note that it is also possible to mark objects by attaching sub- or\nsuperscripted symbols to them, as in e.g.~$A^\\dagger$. This can be\ndone by declaring these symbols explicitly using the \\prop{Symbol}\nproperty,"
}
],
"hidden": true,
"source": "Note that it is also possible to mark objects by attaching sub- or\nsuperscripted symbols to them, as in e.g.~$A^\\dagger$. This can be\ndone by declaring these symbols explicitly using the \\prop{Symbol}\nproperty,"
},
{
"cell_id": 7750888541147789542,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 7392594223693586359,
"cell_origin": "server",
"cell_type": "latex_view",
"source": "\\begin{dmath*}{}\\text{Property Symbol attached to~}\\dagger.\\end{dmath*}"
}
],
"source": "\\dagger::Symbol;"
},
{
"cell_id": 865666516606114027,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 8568844144367393656,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "If you do not do this, the dagger symbol will be seen as an index\nand an error will be reported if it appears more than twice."
}
],
"hidden": true,
"source": "If you do not do this, the dagger symbol will be seen as an index\nand an error will be reported if it appears more than twice."
},
{
"cell_id": 17791353427878308235,
"cell_origin": "client",
"cell_type": "input",
"source": ""
}
],
"description": "Cadabra JSON notebook format",
"version": 1.0
}
Loading

0 comments on commit af5955b

Please sign in to comment.