Commit e5396e14 authored by kerry-he's avatar kerry-he
Browse files

Formatted tests, constraints, expressions

parent c69bfe75
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@ style:
    - pip install ruff
  script:
    - >
      ruff
      ruff check
      --select D,E
      --ignore D105,D203,D213,D401,E221,E226,E271,E272,E501,E702,E741
      picos tests
+3 −3
Original line number Diff line number Diff line
@@ -57,11 +57,11 @@ from .con_mtxgeomean import (MatrixGeoMeanEpiConstraint, ComplexMatrixGeoMean
                                TrMatrixGeoMeanHypoConstraint, ComplexTrMatrixGeoMeanHypoConstraint)
from .con_oprelentr     import (OpRelEntropyConstraint, ComplexOpRelEntropyConstraint,  # noqa
                                TrOpRelEntropyConstraint, ComplexTrOpRelEntropyConstraint)
from .con_qkd           import (QuantKeyDistributionConstraint, # noqa
from .con_quantkeydist           import (QuantKeyDistributionConstraint, # noqa
                                ComplexQuantKeyDistributionConstraint)
from .con_qce           import (QuantCondEntropyConstraint, # noqa
from .con_quantcondentr           import (QuantCondEntropyConstraint, # noqa
                                ComplexQuantCondEntropyConstraint)
from .con_qre           import (QuantRelEntropyConstraint, # noqa
from .con_quantrelentr           import (QuantRelEntropyConstraint, # noqa
                                ComplexQuantRelEntropyConstraint)
from .con_prodcone      import ProductConeConstraint  # noqa
from .con_quadratic     import (NonconvexQuadraticConstraint, # noqa
+35 −28
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
# this program.  If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------

"""Implementation of :class:`MatrixGeoMeanEpiConstraint`."""
"""Matrix geometric mean constraints"""

from collections import namedtuple

@@ -30,16 +30,16 @@ _API_START = api_start(globals())


class MatrixGeoMeanEpiConstraint(Constraint):
    """Epigraph of an operator relative entropy.
    """Epigraph of a convex matrix geometric mean.

    This is the upper bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the upper bound, in the Loewner order, of a convex matrix geometric
    mean, represented by :class:`~picos.expressions.MatrixGeometricMean`.
    """

    def __init__(self, divergence, upperBound):
        """Construct a :class:`MatrixGeoMeanEpiConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy divergence:
        :param ~picos.expressions.MatrixGeometricMean divergence:
            Constrained expression.
        :param ~picos.expressions.AffineExpression upperBound:
            Upper bound on the expression.
@@ -51,7 +51,8 @@ class MatrixGeoMeanEpiConstraint(Constraint):
        assert isinstance(divergence, MatrixGeometricMean)
        assert isinstance(upperBound, required_type)
        assert divergence.shape == upperBound.shape
        assert (-1 <= divergence.power and divergence.power <= 0) or (1 <= divergence.power and divergence.power <= 2)
        assert (-1 <= divergence.power and divergence.power <= 0) or \
               ( 1 <= divergence.power and divergence.power <= 2)

        self.divergence = divergence
        self.upperBound = upperBound
@@ -105,27 +106,29 @@ class MatrixGeoMeanEpiConstraint(Constraint):
    def _get_slack(self):
        return self.upperBound.safe_value - self.divergence.safe_value


class ComplexMatrixGeoMeanEpiConstraint(MatrixGeoMeanEpiConstraint):
    """Upper bound on a complex quantum relative entropy."""
    """Epigraph of a complex convex matrix geometric mean."""

    # TODO: Implement real conversion of quantum relative entropy cone
    # TODO: Implement real conversion of matrix geometric mean epigraph

    def _required_type(self):
        from ..expressions import ComplexAffineExpression

        return ComplexAffineExpression


class TrMatrixGeoMeanEpiConstraint(Constraint):
    """Epigraph of an operator relative entropy.
    """Upper bound of trace of a convex operator relative entropy.

    This is the upper bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the upper bound on the trace of a convex matrix geometric mean,
    represented by :class:`~picos.expressions.TrMatrixGeometricMean`.
    """

    def __init__(self, divergence, upperBound):
        """Construct a :class:`MatrixGeoMeanEpiConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy divergence:
        :param ~picos.expressions.TrMatrixGeometricMean divergence:
            Constrained expression.
        :param ~picos.expressions.AffineExpression upperBound:
            Upper bound on the expression.
@@ -135,7 +138,8 @@ class TrMatrixGeoMeanEpiConstraint(Constraint):
        assert isinstance(divergence, TrMatrixGeometricMean)
        assert isinstance(upperBound, AffineExpression)
        assert len(upperBound) == 1
        assert (-1 <= divergence.power and divergence.power <= 0) or (1 <= divergence.power and divergence.power <= 2)
        assert (-1 <= divergence.power and divergence.power <= 0) or \
               ( 1 <= divergence.power and divergence.power <= 2)

        self.divergence = divergence
        self.upperBound = upperBound
@@ -193,9 +197,9 @@ class TrMatrixGeoMeanEpiConstraint(Constraint):


class ComplexTrMatrixGeoMeanEpiConstraint(TrMatrixGeoMeanEpiConstraint):
    """Upper bound on a complex quantum relative entropy."""
    """Upper bound of trace of a complex convex operator relative entropy."""

    # TODO: Implement real conversion of quantum relative entropy cone
    # TODO: Implement real conversion of matrix geometric mean cone

    def _required_type(self):
        from ..expressions import ComplexAffineExpression
@@ -204,16 +208,16 @@ class ComplexTrMatrixGeoMeanEpiConstraint(TrMatrixGeoMeanEpiConstraint):


class MatrixGeoMeanHypoConstraint(Constraint):
    """Epigraph of an operator relative entropy.
    """Hypograph of a concave matrix geometric mean.

    This is the upper bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the lower bound, in the Loewner order, of a concave matrix geometric
    mean, represented by :class:`~picos.expressions.MatrixGeometricMean`.
    """

    def __init__(self, divergence, lowerBound):
        """Construct a :class:`MatrixGeoMeanEpiConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy divergence:
        :param ~picos.expressions.MatrixGeometricMean divergence:
            Constrained expression.
        :param ~picos.expressions.AffineExpression lowerBound:
            Upper bound on the expression.
@@ -279,30 +283,32 @@ class MatrixGeoMeanHypoConstraint(Constraint):
    def _get_slack(self):
        return self.lowerBound.safe_value - self.divergence.safe_value


class ComplexMatrixGeoMeanHypoConstraint(MatrixGeoMeanHypoConstraint):
    """Upper bound on a complex quantum relative entropy."""
    """Hypograph of a complex concave matrix geometric mean."""

    # TODO: Implement real conversion of quantum relative entropy cone
    # TODO: Implement real conversion of matrix geometric mean hypograph

    def _required_type(self):
        from ..expressions import ComplexAffineExpression

        return ComplexAffineExpression


class TrMatrixGeoMeanHypoConstraint(Constraint):
    """Epigraph of an operator relative entropy.
    """Lower bound of trace of a concave operator relative entropy.

    This is the upper bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the lower bound on the trace of a concave matrix geometric mean,
    represented by :class:`~picos.expressions.TrMatrixGeometricMean`.
    """

    def __init__(self, divergence, lowerBound):
        """Construct a :class:`MatrixGeoMeanEpiConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy divergence:
        :param ~picos.expressions.TrMatrixGeometricMean divergence:
            Constrained expression.
        :param ~picos.expressions.AffineExpression lowerBound:
            Upper bound on the expression.
            Lower bound on the expression.
        """
        from ..expressions import AffineExpression, TrMatrixGeometricMean

@@ -367,14 +373,15 @@ class TrMatrixGeoMeanHypoConstraint(Constraint):


class ComplexTrMatrixGeoMeanHypoConstraint(TrMatrixGeoMeanHypoConstraint):
    """Upper bound on a complex quantum relative entropy."""
    """Lower bound of trace of a complex concave operator relative entropy."""

    # TODO: Implement real conversion of quantum relative entropy cone
    # TODO: Implement real conversion of matrix geometric mean cone

    def _required_type(self):
        from ..expressions import ComplexAffineExpression

        return ComplexAffineExpression


# --------------------------------------
__all__ = api_end(_API_START, globals())
+16 −13
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
# this program.  If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------

"""Implementation of :class:`OpRelEntropyConstraint`."""
"""Operator relative entropy constraints."""

from collections import namedtuple

@@ -32,14 +32,14 @@ _API_START = api_start(globals())
class OpRelEntropyConstraint(Constraint):
    """Epigraph of an operator relative entropy.

    This is the upper bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the upper bound, in the Loewner order, of an operator relative
    entropy, represented by :class:`~picos.expressions.OperatorRelativeEntropy`.
    """

    def __init__(self, divergence, upperBound):
        """Construct a :class:`OpRelEntropyConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy divergence:
        :param ~picos.expressions.OperatorRelativeEntropy divergence:
            Constrained expression.
        :param ~picos.expressions.AffineExpression upperBound:
            Upper bound on the expression.
@@ -99,27 +99,29 @@ class OpRelEntropyConstraint(Constraint):
    def _get_slack(self):
        return self.upperBound.safe_value - self.divergence.safe_value


class ComplexOpRelEntropyConstraint(OpRelEntropyConstraint):
    """Upper bound on a complex quantum relative entropy."""
    """Epigraph of a complex operator relative entropy."""

    # TODO: Implement real conversion of quantum relative entropy cone
    # TODO: Implement real conversion of operator relative entropy epigraph

    def _required_type(self):
        from ..expressions import ComplexAffineExpression

        return ComplexAffineExpression


class TrOpRelEntropyConstraint(Constraint):
    """Epigraph of an operator relative entropy.
    """Upper bound of trace of operator relative entropy.

    This is the upper bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the upper bound on the trace of an operator relative entropy,
    represented by :class:`~picos.expressions.TrOperatorRelativeEntropy`.
    """

    def __init__(self, divergence, upperBound):
        """Construct a :class:`OpRelEntropyConstraint`.
        """Construct a :class:`TrOpRelEntropyConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy divergence:
        :param ~picos.expressions.TrOperatorRelativeEntropy divergence:
            Constrained expression.
        :param ~picos.expressions.AffineExpression upperBound:
            Upper bound on the expression.
@@ -181,14 +183,15 @@ class TrOpRelEntropyConstraint(Constraint):


class ComplexTrOpRelEntropyConstraint(TrOpRelEntropyConstraint):
    """Upper bound on a complex quantum relative entropy."""
    """Upper bound of trace of complex operator relative entropy."""

    # TODO: Implement real conversion of quantum relative entropy cone
    # TODO: Implement real conversion of operator relative entropy cone

    def _required_type(self):
        from ..expressions import ComplexAffineExpression

        return ComplexAffineExpression


# --------------------------------------
__all__ = api_end(_API_START, globals())
+5 −3
Original line number Diff line number Diff line
@@ -32,14 +32,14 @@ _API_START = api_start(globals())
class QuantCondEntropyConstraint(Constraint):
    """Lower bound on a quantum conditional entropy.

    This is the lower bound on a negative or relative quantum entropy, both
    represented by :class:`~picos.expressions.NegativeQuantumEntropy`.
    This is the lower bound on a quantum conditional entropy, represented by 
    :class:`~picos.expressions.QuantumConditionalEntropy`.
    """

    def __init__(self, function, lowerBound):
        """Construct a :class:`QuantCondEntropyConstraint`.

        :param ~picos.expressions.NegativeQuantumEntropy function:
        :param ~picos.expressions.QuantumConditionalEntropy function:
            Constrained expression.
        :param ~picos.expressions.AffineExpression lowerBound:
            Lower bound on the expression.
@@ -103,6 +103,7 @@ class QuantCondEntropyConstraint(Constraint):
    def _get_slack(self):
        return self.function.safe_value - self.lowerBound.safe_value


class ComplexQuantCondEntropyConstraint(QuantCondEntropyConstraint):
    """Lower bound on a complex quantum conditional entropy."""

@@ -113,5 +114,6 @@ class ComplexQuantCondEntropyConstraint(QuantCondEntropyConstraint):

        return ComplexAffineExpression


# --------------------------------------
__all__ = api_end(_API_START, globals())
Loading