|
| 1 | +/* |
| 2 | + * This file is part of pyqpp. |
| 3 | + * |
| 4 | + * Copyright (c) 2017 - 2025 softwareQ Inc. All rights reserved. |
| 5 | + * |
| 6 | + * MIT License |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | + * SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#ifndef PYQPP_ENTROPIES_BIND_HPP_ |
| 28 | +#define PYQPP_ENTROPIES_BIND_HPP_ |
| 29 | + |
| 30 | +#include "pyqpp/pyqpp_common.hpp" |
| 31 | + |
| 32 | +/* Bindings for entropies.hpp */ |
| 33 | +inline void init_entropies(py::module_& m) { |
| 34 | + using namespace qpp; |
| 35 | + |
| 36 | + // --- Entropy Bindings --- |
| 37 | + |
| 38 | + // von-Neumann entropy (Templated for MatrixBase) |
| 39 | + m.def( |
| 40 | + "entropy", [](const cmat& A) { return qpp::entropy(A); }, |
| 41 | + "Computes the von-Neumann entropy of a density matrix (base 2).", |
| 42 | + py::arg("A")); |
| 43 | + |
| 44 | + // Shannon entropy (Non-templated, but kept as lambda for consistency) |
| 45 | + m.def( |
| 46 | + "entropy", |
| 47 | + [](const std::vector<realT>& prob) { return qpp::entropy(prob); }, |
| 48 | + "Computes the Shannon entropy of a probability distribution (base 2).", |
| 49 | + py::arg("prob")); |
| 50 | + |
| 51 | + // Renyi entropy (Templated for MatrixBase) |
| 52 | + m.def( |
| 53 | + "renyi", |
| 54 | + [](const cmat& A, realT alpha) { return qpp::renyi(A, alpha); }, |
| 55 | + "Computes the Renyi-alpha entropy of a density matrix.", py::arg("A"), |
| 56 | + py::arg("alpha")); |
| 57 | + |
| 58 | + // Renyi entropy (Vector version) |
| 59 | + m.def( |
| 60 | + "renyi", |
| 61 | + [](const std::vector<realT>& prob, realT alpha) { |
| 62 | + return qpp::renyi(prob, alpha); |
| 63 | + }, |
| 64 | + "Computes the Renyi-alpha entropy of a probability distribution.", |
| 65 | + py::arg("prob"), py::arg("alpha")); |
| 66 | + |
| 67 | + // Tsallis entropy (Templated for MatrixBase) |
| 68 | + m.def( |
| 69 | + "tsallis", [](const cmat& A, realT q) { return qpp::tsallis(A, q); }, |
| 70 | + "Computes the Tsallis-q entropy of a density matrix.", py::arg("A"), |
| 71 | + py::arg("q")); |
| 72 | + |
| 73 | + // Tsallis entropy (Vector version) |
| 74 | + m.def( |
| 75 | + "tsallis", |
| 76 | + [](const std::vector<realT>& prob, realT q) { |
| 77 | + return qpp::tsallis(prob, q); |
| 78 | + }, |
| 79 | + "Computes the Tsallis-q entropy of a probability distribution.", |
| 80 | + py::arg("prob"), py::arg("q")); |
| 81 | + |
| 82 | + // --- Mutual Information Bindings --- |
| 83 | + |
| 84 | + // Quantum Mutual Information (Templated, varied dimensions) |
| 85 | + m.def( |
| 86 | + "qmutualinfo", |
| 87 | + [](const cmat& A, const std::vector<idx>& subsysA, |
| 88 | + const std::vector<idx>& subsysB, const std::vector<idx>& dims) { |
| 89 | + return qpp::qmutualinfo(A, subsysA, subsysB, dims); |
| 90 | + }, |
| 91 | + "Computes the quantum mutual information between two subsystems A and " |
| 92 | + "B with given dimensions.", |
| 93 | + py::arg("A"), py::arg("subsysA"), py::arg("subsysB"), py::arg("dims")); |
| 94 | + |
| 95 | + // Quantum Mutual Information (Templated, uniform dimensions) |
| 96 | + m.def( |
| 97 | + "qmutualinfo", |
| 98 | + [](const cmat& A, const std::vector<idx>& subsysA, |
| 99 | + const std::vector<idx>& subsysB, |
| 100 | + idx d) { return qpp::qmutualinfo(A, subsysA, subsysB, d); }, |
| 101 | + "Computes the quantum mutual information between two subsystems A and " |
| 102 | + "B assuming uniform dimensions d.", |
| 103 | + py::arg("A"), py::arg("subsysA"), py::arg("subsysB"), py::arg("d") = 2); |
| 104 | +} |
| 105 | + |
| 106 | +#endif /* PYQPP_ENTROPIES_BIND_HPP_ */ |
0 commit comments