Coverage for picos/constraints/con_quantcondentr.py: 92.16%
51 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-12 07:53 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-12 07:53 +0000
1# ------------------------------------------------------------------------------
2# Copyright (C) 2024 Kerry He
3#
4# This file is part of PICOS.
5#
6# PICOS is free software: you can redistribute it and/or modify it under the
7# terms of the GNU General Public License as published by the Free Software
8# Foundation, either version 3 of the License, or (at your option) any later
9# version.
10#
11# PICOS is distributed in the hope that it will be useful, but WITHOUT ANY
12# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program. If not, see <http://www.gnu.org/licenses/>.
17# ------------------------------------------------------------------------------
19"""Implementation of :class:`QuantCondEntropyConstraint`."""
21from collections import namedtuple
23from .. import glyphs
24from ..apidoc import api_end, api_start
25from ..caching import cached_property
26from .constraint import Constraint
28_API_START = api_start(globals())
29# -------------------------------
32class QuantCondEntropyConstraint(Constraint):
33 """Lower bound on a quantum conditional entropy.
35 This is the lower bound on a quantum conditional entropy, represented by
36 :class:`~picos.expressions.QuantumConditionalEntropy`.
37 """
39 def __init__(self, function, lowerBound):
40 """Construct a :class:`QuantCondEntropyConstraint`.
42 :param ~picos.expressions.QuantumConditionalEntropy function:
43 Constrained expression.
44 :param ~picos.expressions.AffineExpression lowerBound:
45 Lower bound on the expression.
46 """
47 from ..expressions import AffineExpression, QuantumConditionalEntropy
49 assert isinstance(function, QuantumConditionalEntropy)
50 assert isinstance(lowerBound, AffineExpression)
51 assert len(lowerBound) == 1
53 self.function = function
54 self.lowerBound = lowerBound
56 required_type = self._required_type()
58 assert isinstance(function.X, required_type)
60 super(QuantCondEntropyConstraint, self).__init__(function._typeStr)
62 def _required_type(self):
63 from ..expressions import AffineExpression
65 return AffineExpression
67 @property
68 def X(self):
69 """The :math:`X` of the function."""
70 return self.function.X
72 @cached_property
73 def subsystems(self):
74 """The subsystems being traced out of :math:`X`."""
75 return self.function.subsystems
77 @cached_property
78 def dimensions(self):
79 """The dimensions of the subsystems of :math:`X`."""
80 return self.function.dimensions
82 Subtype = namedtuple("Subtype", ("argdim",))
84 def _subtype(self):
85 return self.Subtype(self.X.shape[0] ** 2)
87 @classmethod
88 def _cost(cls, subtype):
89 n = subtype.argdim
90 return n * (n + 1) // 2 + 1
92 def _expression_names(self):
93 yield "function"
94 yield "lowerBound"
96 def _str(self):
97 return glyphs.ge(self.function.string, self.lowerBound.string)
99 def _get_size(self):
100 n = self.X.shape[0]
101 return (n * n + 1, 1)
103 def _get_slack(self):
104 return self.function.safe_value - self.lowerBound.safe_value
107class ComplexQuantCondEntropyConstraint(QuantCondEntropyConstraint):
108 """Lower bound on a complex quantum conditional entropy."""
110 # TODO: Implement real conversion of quantum conditional entropy cone
112 def _required_type(self):
113 from ..expressions import ComplexAffineExpression
115 return ComplexAffineExpression
118# --------------------------------------
119__all__ = api_end(_API_START, globals())