From 76aa6120e9fb352d0a55c60c2eda23364baa1965 Mon Sep 17 00:00:00 2001 From: Michel Ferrero Date: Wed, 21 May 2014 16:35:33 +0200 Subject: [PATCH] Add new python operators For now they are called operators2. --- pytriqs/operators/CMakeLists.txt | 1 + pytriqs/operators/operators2_desc.py | 55 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 pytriqs/operators/operators2_desc.py diff --git a/pytriqs/operators/CMakeLists.txt b/pytriqs/operators/CMakeLists.txt index 8a4ccb96..3b82103a 100644 --- a/pytriqs/operators/CMakeLists.txt +++ b/pytriqs/operators/CMakeLists.txt @@ -6,4 +6,5 @@ SET(PYTHON_SOURCES install (FILES ${PYTHON_SOURCES} DESTINATION ${TRIQS_PYTHON_LIB_DEST}/operators) +triqs_python_extension(operators2 operators) diff --git a/pytriqs/operators/operators2_desc.py b/pytriqs/operators/operators2_desc.py new file mode 100644 index 00000000..d251ffac --- /dev/null +++ b/pytriqs/operators/operators2_desc.py @@ -0,0 +1,55 @@ +from wrap_generator import * + +# The operator class +op = class_( + py_type = "Operator", + c_type = "many_body_operator", + is_printable= True, + arithmetic = ("algebra","double") + ) + +op.add_constructor(signature="()", doc="create zero operator") + +# Complete the number_protocol +mbo = 'many_body_operator' +scal = 'double' + +# Allow + and - between scalar and operator +add = op.number_protocol['add'] +add.add_overload (calling_pattern = "+", args = [(mbo,'x'), (scal,'y')], rtype = mbo) +add.add_overload (calling_pattern = "+", args = [(scal,'x'), (mbo,'y')], rtype = mbo) +sub = op.number_protocol['subtract'] +sub.add_overload (calling_pattern = "-", args = [(mbo,'x'), (scal,'y')], rtype = mbo) +sub.add_overload (calling_pattern = "-", args = [(scal,'x'), (mbo,'y')], rtype = mbo) + +# Allow unary - on an operator +neg = pyfunction(py_name = "__neg__") +neg.arity = 1 +neg.add_overload (calling_pattern = "-", args = [(mbo,'x')], rtype = mbo) +op.number_protocol['negative'] = neg + +# The many_body_operators module +module = module_(full_name = "operators2", doc = "Doc of my_module") +module.add_include("") +module.add_include("") +module.add_using("namespace triqs::utility") +module.add_class(op) + +# Annihilation operators +module.add_function(name = "c", signature="many_body_operator(std::string ind1)", doc="annihilation operator") +module.add_function(name = "c", signature="many_body_operator(std::string ind1, std::string ind2)", doc="annihilation operator") +module.add_function(name = "c", signature="many_body_operator(std::string ind1, int i)", doc="annihilation operator") +module.add_function(name = "c", signature="many_body_operator(int i, std::string ind1)", doc="annihilation operator") +module.add_function(name = "c", signature="many_body_operator(int i, int j)", doc="annihilation operator") + +# Construction operators +module.add_function(name = "c_dag", signature="many_body_operator(std::string ind1)", doc="annihilation operator") +module.add_function(name = "c_dag", signature="many_body_operator(std::string ind1, std::string ind2)", doc="annihilation operator") +module.add_function(name = "c_dag", signature="many_body_operator(std::string ind1, int i)", doc="annihilation operator") +module.add_function(name = "c_dag", signature="many_body_operator(int i, std::string ind1)", doc="annihilation operator") +module.add_function(name = "c_dag", signature="many_body_operator(int i, int j)", doc="annihilation operator") + +# to generate the module code +if __name__ == '__main__' : + module.generate_code(mako_template = sys.argv[1], wrap_file = sys.argv[2]) +