Exemple #1
0
    def aux_operators(
        self, aux_operators: Optional[
            Union[OperatorBase, LegacyBaseOperator,
                  List[Optional[Union[OperatorBase, LegacyBaseOperator]]]]]
    ) -> None:
        """ Set aux operators """
        if aux_operators is None:
            aux_operators = []
        elif not isinstance(aux_operators, list):
            aux_operators = [aux_operators]

        # We need to handle the array entries being Optional i.e. having value None
        self._aux_op_nones = [op is None for op in aux_operators]
        if aux_operators:
            zero_op = I.tensorpower(self.operator.num_qubits) * 0.0
            converted = []
            for op in aux_operators:
                if op is None:
                    converted.append(zero_op)
                elif isinstance(op, LegacyBaseOperator):
                    converted.append(op.to_opflow())
                else:
                    converted.append(op)

            # For some reason Chemistry passes aux_ops with 0 qubits and paulis sometimes.
            aux_operators = [zero_op if op == 0 else op for op in converted]

        self._aux_operators = aux_operators  # type: List
Exemple #2
0
 def aux_operators(self,
                   aux_operators: Optional[List[Optional[Union[OperatorBase,
                                                               LegacyBaseOperator]]]]) -> None:
     """ Set aux operators """
     # We need to handle the array entries being Optional i.e. having value None
     self._aux_op_nones = None
     if isinstance(aux_operators, list):
         self._aux_op_nones = [op is None for op in aux_operators]
         zero_op = I.tensorpower(self.operator.num_qubits) * 0.0
         converted = [op.to_opflow() if op else zero_op for op in aux_operators]
         # For some reason Chemistry passes aux_ops with 0 qubits and paulis sometimes.
         converted = [zero_op if op == 0 else op for op in converted]
         aux_operators = ListOp(converted)
     elif isinstance(aux_operators, LegacyBaseOperator):
         aux_operators = [aux_operators.to_opflow()]
     self._aux_operators = aux_operators
Exemple #3
0
 def aux_operators(self,
                   aux_operators: Optional[List[Optional[Union[OperatorBase,
                                                               LegacyBaseOperator]]]]) -> None:
     """ Set aux operators """
     # This is all terrible code to deal with weight 0-qubit None aux_ops.
     self._aux_op_nones = None
     if isinstance(aux_operators, list):
         self._aux_op_nones = [op is None for op in aux_operators]
         zero_op = I.tensorpower(self.operator.num_qubits) * 0.0
         converted = [op.to_opflow() if op else zero_op for op in aux_operators]
         # For some reason Chemistry passes aux_ops with 0 qubits and paulis sometimes.
         converted = [zero_op if op == 0 else op for op in converted]
         aux_operators = ListOp(converted)
     elif isinstance(aux_operators, LegacyBaseOperator):
         aux_operators = [aux_operators.to_opflow()]
     self._aux_operators = aux_operators
 def aux_operators(
     self,
     aux_operators: Optional[List[Optional[Union[OperatorBase,
                                                 LegacyBaseOperator]]]]
 ) -> None:
     """ set aux operators """
     if aux_operators is None:
         self._aux_operators = []
     else:
         aux_operators = \
             [aux_operators] if not isinstance(aux_operators, list) else aux_operators
         converted = [
             op.to_opflow() if op is not None else None
             for op in aux_operators
         ]
         # Chemistry passes aux_ops with 0 qubits and paulis sometimes
         zero_op = I.tensorpower(self.operator.num_qubits) * 0.0
         converted = [zero_op if op == 0 else op for op in converted]
         self._aux_operators = converted
    def aux_operators(self,
                      aux_operators: Optional[
                          Union[OperatorBase,
                                LegacyBaseOperator,
                                List[Optional[Union[OperatorBase,
                                                    LegacyBaseOperator]]]]]) -> None:
        if aux_operators is None:
            aux_operators = []
        elif not isinstance(aux_operators, list):
            aux_operators = [aux_operators]

        if aux_operators:
            zero_op = I.tensorpower(self.operator.num_qubits) * 0.0
            converted = [op.to_opflow() if isinstance(op, LegacyBaseOperator)
                         else op for op in aux_operators]

            # For some reason Chemistry passes aux_ops with 0 qubits and paulis sometimes.
            aux_operators = [zero_op if op == 0 else op for op in converted]

        self._aux_operators = aux_operators