Coverage for picos/constraints/con_quantkeydist.py: 89.47%

57 statements  

« 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# ------------------------------------------------------------------------------ 

18 

19"""Implementation of :class:`QuantKeyDistributionConstraint`.""" 

20 

21from collections import namedtuple 

22 

23from .. import glyphs 

24from ..apidoc import api_end, api_start 

25from ..caching import cached_property 

26from .constraint import Constraint 

27 

28_API_START = api_start(globals()) 

29# ------------------------------- 

30 

31 

32class QuantKeyDistributionConstraint(Constraint): 

33 """Upper bound on a quantum key distribution function. 

34 

35 This is the upper bound on a quantum key distribution function, represented 

36 by :class:`~picos.expressions.QuantumKeyDistribution`. 

37 """ 

38 

39 def __init__(self, function, upperBound): 

40 """Construct a :class:`QuantKeyDistributionConstraint`. 

41 

42 :param ~picos.expressions.QuantumKeyDistribution function: 

43 Constrained expression. 

44 :param ~picos.expressions.AffineExpression upperBound: 

45 Upper bound on the expression. 

46 """ 

47 from ..expressions import AffineExpression, QuantumKeyDistribution 

48 

49 assert isinstance(function, QuantumKeyDistribution) 

50 assert isinstance(upperBound, AffineExpression) 

51 assert len(upperBound) == 1 

52 

53 self.function = function 

54 self.upperBound = upperBound 

55 

56 required_type = self._required_type() 

57 

58 assert isinstance(function.X, required_type) 

59 

60 super(QuantKeyDistributionConstraint, self).__init__(function._typeStr) 

61 

62 def _required_type(self): 

63 from ..expressions import AffineExpression 

64 

65 return AffineExpression 

66 

67 @property 

68 def X(self): 

69 """The :math:`X` of the function.""" 

70 return self.function.X 

71 

72 @cached_property 

73 def subsystems(self): 

74 """The subsystems being block-diagonalized of :math:`X`.""" 

75 return self.function.subsystems 

76 

77 @cached_property 

78 def dimensions(self): 

79 """The dimensions of the subsystems of :math:`X`.""" 

80 return self.function.dimensions 

81 

82 @cached_property 

83 def K_list(self): 

84 r"""The Kraus operators :math:`K_i` of :math:`\mathcal{G}`.""" 

85 return self.function.K_list 

86 

87 @cached_property 

88 def Z_list(self): 

89 r"""The Kraus operators :math:`Z_i` of :math:`\mathcal{Z}`.""" 

90 return self.function.Z_list 

91 

92 Subtype = namedtuple("Subtype", ("argdim",)) 

93 

94 def _subtype(self): 

95 return self.Subtype(self.X.shape[0] ** 2) 

96 

97 @classmethod 

98 def _cost(cls, subtype): 

99 n = subtype.argdim 

100 return n * (n + 1) // 2 + 1 

101 

102 def _expression_names(self): 

103 yield "function" 

104 yield "upperBound" 

105 

106 def _str(self): 

107 return glyphs.le(self.function.string, self.upperBound.string) 

108 

109 def _get_size(self): 

110 n = self.X.shape[0] 

111 return (n * n + 1, 1) 

112 

113 def _get_slack(self): 

114 return self.upperBound.safe_value - self.function.safe_value 

115 

116 

117class ComplexQuantKeyDistributionConstraint(QuantKeyDistributionConstraint): 

118 """Upper bound on a complex quantum key distribution function.""" 

119 

120 # TODO: Implement real conversion of quantum conditional entropy cone 

121 

122 def _required_type(self): 

123 from ..expressions import ComplexAffineExpression 

124 

125 return ComplexAffineExpression 

126 

127 

128# -------------------------------------- 

129__all__ = api_end(_API_START, globals())