diff --git a/CHANGES b/CHANGES index 55ed1666d..1c3749152 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +Pre-release + - Significant speedup in pyqpp's compilation time + Version 4.3.4 - 14 August 2023 - Docker update, see the ["docker/"] directory - Fix in ["types.hpp"] for defaulting types when not using CMake diff --git a/pyqpp/src/classes/circuits/circuits_bind.cpp b/pyqpp/include/classes/circuits/circuits_bind.hpp similarity index 99% rename from pyqpp/src/classes/circuits/circuits_bind.cpp rename to pyqpp/include/classes/circuits/circuits_bind.hpp index 85c744626..94b43f055 100644 --- a/pyqpp/src/classes/circuits/circuits_bind.cpp +++ b/pyqpp/include/classes/circuits/circuits_bind.hpp @@ -24,10 +24,11 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_CLASSES_CIRCUITS_CIRCUITS_BIND_HPP_ +#define PYQPP_CLASSES_CIRCUITS_CIRCUITS_BIND_HPP_ /* qpp::QCircuit and related free functions */ -void init_classes_circuits_circuits(py::module_& m) { +inline void init_classes_circuits_circuits(py::module_& m) { using namespace qpp; auto pyQCircuit = @@ -488,3 +489,5 @@ void init_classes_circuits_circuits(py::module_& m) { "Replicates a quantum circuit description", py::arg("qc"), py::arg("n")); } + +#endif /* PYQPP_CLASSES_CIRCUITS_CIRCUITS_BIND_HPP_ */ diff --git a/pyqpp/src/classes/circuits/engines_bind.cpp b/pyqpp/include/classes/circuits/engines_bind.hpp similarity index 96% rename from pyqpp/src/classes/circuits/engines_bind.cpp rename to pyqpp/include/classes/circuits/engines_bind.hpp index 6460231ea..2354a663b 100644 --- a/pyqpp/src/classes/circuits/engines_bind.cpp +++ b/pyqpp/include/classes/circuits/engines_bind.hpp @@ -24,7 +24,8 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_CLASSES_CIRCUITS_ENGINES_BIND_HPP_ +#define PYQPP_CLASSES_CIRCUITS_ENGINES_BIND_HPP_ /* qpp::QNoisyEngine instantiator */ template @@ -73,7 +74,7 @@ void declare_noisy_engine(py::module& m, const std::string& type) { } /* qpp::QEngine */ -void init_classes_circuits_engines(py::module_& m) { +inline void init_classes_circuits_engines(py::module_& m) { using namespace qpp; py::class_(m, "QEngine") @@ -146,3 +147,5 @@ void init_classes_circuits_engines(py::module_& m) { declare_noisy_engine( m, "QuditDepolarizingNoise"); } + +#endif /* PYQPP_CLASSES_CIRCUITS_ENGINES_BIND_HPP_ */ diff --git a/pyqpp/src/classes/gates_bind.cpp b/pyqpp/include/classes/gates_bind.hpp similarity index 95% rename from pyqpp/src/classes/gates_bind.cpp rename to pyqpp/include/classes/gates_bind.hpp index 7d950400d..613e36213 100644 --- a/pyqpp/src/classes/gates_bind.cpp +++ b/pyqpp/include/classes/gates_bind.hpp @@ -24,10 +24,11 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_CLASSES_GATES_BIND_HPP_ +#define PYQPP_CLASSES_GATES_BIND_HPP_ /* qpp::Gates */ -void init_classes_gates(py::module_& m) { +inline void init_classes_gates(py::module_& m) { using namespace qpp; auto gates = m.def_submodule("gates"); @@ -87,3 +88,5 @@ void init_classes_gates(py::module_& m) { "Zd", [](idx D) { return qpp::gt.Zd(D); }, "Generalized Z gate for qudits", py::arg("D") = 2); } + +#endif /* PYQPP_CLASSES_GATES_BIND_HPP_ */ diff --git a/pyqpp/src/classes/reversible_bind.cpp b/pyqpp/include/classes/reversible_bind.hpp similarity index 97% rename from pyqpp/src/classes/reversible_bind.cpp rename to pyqpp/include/classes/reversible_bind.hpp index 649751767..0010de75b 100644 --- a/pyqpp/src/classes/reversible_bind.cpp +++ b/pyqpp/include/classes/reversible_bind.hpp @@ -24,10 +24,11 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_CLASSES_REVERSIBLE_BIND_HPP_ +#define PYQPP_CLASSES_REVERSIBLE_BIND_HPP_ /* qpp::Dynamic_bitset and qpp::Bit_circuit */ -void init_classes_reversible(py::module_& m) { +inline void init_classes_reversible(py::module_& m) { using namespace qpp; /* qpp::Dynamic_bitset */ @@ -136,3 +137,5 @@ void init_classes_reversible(py::module_& m) { return oss.str(); }); } + +#endif /* PYQPP_CLASSES_REVERSIBLE_BIND_HPP_ */ diff --git a/pyqpp/src/classes/states_bind.cpp b/pyqpp/include/classes/states_bind.hpp similarity index 94% rename from pyqpp/src/classes/states_bind.cpp rename to pyqpp/include/classes/states_bind.hpp index 7774450be..3ed9b2b1d 100644 --- a/pyqpp/src/classes/states_bind.cpp +++ b/pyqpp/include/classes/states_bind.hpp @@ -24,10 +24,11 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_CLASSES_STATES_BIND_HPP_ +#define PYQPP_CLASSES_STATES_BIND_HPP_ /* qpp::States */ -void init_classes_states(py::module_& m) { +inline void init_classes_states(py::module_& m) { using namespace qpp; auto states = m.def_submodule("states"); @@ -78,3 +79,5 @@ void init_classes_states(py::module_& m) { "zero", [](idx n, idx d) { return qpp::st.zero(n, d); }, "Zero state of n qudits", py::arg("n") = 1, py::arg("d") = 2); } + +#endif /* PYQPP_CLASSES_STATES_BIND_HPP_ */ diff --git a/pyqpp/src/constants_bind.cpp b/pyqpp/include/constants_bind.hpp similarity index 90% rename from pyqpp/src/constants_bind.cpp rename to pyqpp/include/constants_bind.hpp index f15581c45..04207738e 100644 --- a/pyqpp/src/constants_bind.cpp +++ b/pyqpp/include/constants_bind.hpp @@ -24,13 +24,16 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_CONSTANTS_BIND_HPP_ +#define PYQPP_CONSTANTS_BIND_HPP_ /* Constants from constants.hpp */ -void init_constants(py::module_& m) { +inline void init_constants(py::module_& m) { using namespace qpp; m.attr("ee") = qpp::ee; m.def("omega", &qpp::omega, "D-th root of unity", py::arg("D")); m.attr("pi") = qpp::pi; } + +#endif /* PYQPP_CONSTANTS_BIND_HPP_ */ diff --git a/pyqpp/src/functions_bind.cpp b/pyqpp/include/functions_bind.hpp similarity index 95% rename from pyqpp/src/functions_bind.cpp rename to pyqpp/include/functions_bind.hpp index c5e30b987..941b4c3f7 100644 --- a/pyqpp/src/functions_bind.cpp +++ b/pyqpp/include/functions_bind.hpp @@ -24,10 +24,11 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_FUNCTIONS_BIND_HPP_ +#define PYQPP_FUNCTIONS_BIND_HPP_ /* Some free functions (non-exhaustive list) from functions.hpp */ -void init_functions(py::module_& m) { +inline void init_functions(py::module_& m) { using namespace qpp; /* Template methods must be explicitly instantiated, some examples below */ @@ -73,3 +74,5 @@ void init_functions(py::module_& m) { "transpose", [](const cmat& A) { return qpp::transpose(A); }, "Transpose", py::arg("A")); } + +#endif /* PYQPP_FUNCTIONS_BIND_HPP_ */ diff --git a/pyqpp/src/instruments_bind.cpp b/pyqpp/include/instruments_bind.hpp similarity index 95% rename from pyqpp/src/instruments_bind.cpp rename to pyqpp/include/instruments_bind.hpp index 70b155498..f66122a3f 100644 --- a/pyqpp/src/instruments_bind.cpp +++ b/pyqpp/include/instruments_bind.hpp @@ -24,10 +24,11 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_INSTRUMENTS_BIND_HPP_ +#define PYQPP_INSTRUMENTS_BIND_HPP_ /* Some free functions (non-exhaustive list) from instruments.hpp */ -void init_instruments(py::module_& m) { +inline void init_instruments(py::module_& m) { using namespace qpp; m.def( @@ -80,3 +81,5 @@ void init_instruments(py::module_& m) { py::arg("num_samples"), py::arg("A"), py::arg("target"), py::arg("d") = 2); } + +#endif /* PYQPP_INSTRUMENTS_BIND_HPP_ */ diff --git a/pyqpp/src/pyqpp_specific_bind.cpp b/pyqpp/include/pyqpp_specific_bind.hpp similarity index 87% rename from pyqpp/src/pyqpp_specific_bind.cpp rename to pyqpp/include/pyqpp_specific_bind.hpp index 8a1325794..15d9e9903 100644 --- a/pyqpp/src/pyqpp_specific_bind.cpp +++ b/pyqpp/include/pyqpp_specific_bind.hpp @@ -24,11 +24,12 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_PYQPP_SPECIFIC_BIND_HPP_ +#define PYQPP_PYQPP_SPECIFIC_BIND_HPP_ -// Python-specific functions only (not necessarily with an equivalent version in -// qpp) -void init_pyqpp_specific(py::module_& m) { +/* Python-specific functions only (not necessarily with an equivalent version in + * qpp) */ +inline void init_pyqpp_specific(py::module_& m) { using namespace qpp; m.def( @@ -45,3 +46,5 @@ void init_pyqpp_specific(py::module_& m) { }, "Sets the prng seed to a random value"); } + +#endif /* PYQPP_PYQPP_SPECIFIC_BIND_HPP_ */ diff --git a/pyqpp/src/qasm/qasm_bind.cpp b/pyqpp/include/qasm/qasm_bind.hpp similarity index 90% rename from pyqpp/src/qasm/qasm_bind.cpp rename to pyqpp/include/qasm/qasm_bind.hpp index 8c1f16554..d0c8dc7bf 100644 --- a/pyqpp/src/qasm/qasm_bind.cpp +++ b/pyqpp/include/qasm/qasm_bind.hpp @@ -24,13 +24,16 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_QASM_QASM_BIND_HPP_ +#define PYQPP_QASM_QASM_BIND_HPP_ /* OpenQASM interfacing */ -void init_qasm_qasm(py::module_& m) { +inline void init_qasm_qasm(py::module_& m) { using namespace qpp; auto py_qasm = m.def_submodule("qasm"); py_qasm.def("read_from_file", &qpp::qasm::read_from_file, "Get QCircuit representation of OpenQASM circuit"); } + +#endif /* PYQPP_QASM_QASM_BIND_HPP_ */ diff --git a/pyqpp/src/random_bind.cpp b/pyqpp/include/random_bind.hpp similarity index 90% rename from pyqpp/src/random_bind.cpp rename to pyqpp/include/random_bind.hpp index 755da00e8..ec273fe60 100644 --- a/pyqpp/src/random_bind.cpp +++ b/pyqpp/include/random_bind.hpp @@ -24,12 +24,15 @@ * SOFTWARE. */ -#include "pyqpp_common.h" +#ifndef PYQPP_RANDOM_BIND_HPP_ +#define PYQPP_RANDOM_BIND_HPP_ /* Some free functions (non-exhaustive list) from random.hpp */ -void init_random(py::module_& m) { +inline void init_random(py::module_& m) { using namespace qpp; m.def("randU", &qpp::randU, "Generates a random unitary matrix", py::arg("D") = 2); } + +#endif /* PYQPP_RANDOM_BIND_HPP_ */ diff --git a/pyqpp/qpp_wrapper.cpp b/pyqpp/qpp_wrapper.cpp index 21edfaa10..940b8d1b1 100644 --- a/pyqpp/qpp_wrapper.cpp +++ b/pyqpp/qpp_wrapper.cpp @@ -26,21 +26,20 @@ #include "pyqpp_common.h" -void init_constants(py::module_&); -void init_functions(py::module_&); -void init_instruments(py::module_&); -void init_random(py::module_&); +#include "classes/circuits/circuits_bind.hpp" +#include "classes/circuits/engines_bind.hpp" -void init_classes_gates(py::module_&); -void init_classes_reversible(py::module_&); -void init_classes_states(py::module_&); +#include "classes/gates_bind.hpp" +#include "classes/reversible_bind.hpp" +#include "classes/states_bind.hpp" -void init_classes_circuits_circuits(py::module_&); -void init_classes_circuits_engines(py::module_&); +#include "qasm/qasm_bind.hpp" -void init_qasm_qasm(py::module_&); - -void init_pyqpp_specific(py::module_&); +#include "constants_bind.hpp" +#include "functions_bind.hpp" +#include "instruments_bind.hpp" +#include "pyqpp_specific_bind.hpp" +#include "random_bind.hpp" PYBIND11_MODULE(pyqpp, m) { m.doc() = diff --git a/setup.py b/setup.py index 64741ceb8..ec267367a 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,8 @@ if eigen_path is None: raise Exception('Eigen3 not found!') -source_files = [f for f in sorted(glob("pyqpp/**/*.cpp", recursive=True))] +#source_files = [f for f in sorted(glob("pyqpp/**/*.cpp", recursive=True))] +source_files = ["pyqpp/qpp_wrapper.cpp"] ext_modules = [ Pybind11Extension( "pyqpp",