original_docstring: Fix Bob's measurements and optimize over Alice's measurements.
docstring: Fix Bob's measurements and optimize over Alice's measurements.
docstring_tokens: Fix Bob ' s measurements and optimize over Alice ' s measurements .
code: def __optimize_alice(self, bob_povms) -> Tuple[Dict, float]:
          """Fix Bob's measurements and optimize over Alice's measurements."""
          # Get number of inputs and outputs.
          (
              dim,
              _,
              num_outputs_alice,
              num_outputs_bob,
              num_inputs_alice,
              num_inputs_bob,
          ) = self.pred_mat.shape
  
          # The cvxpy package does not support optimizing over 4-dimensional objects.
          # To overcome this, we use a dictionary to index between the questions and
          # answers, while the cvxpy variables held at this positions are
          # `dim`-by-`dim` cvxpy variables.
          rho = defaultdict(cvxpy.Variable)
          for x_ques in range(num_inputs_alice):
              for a_ans in range(num_outputs_alice):
                  rho[x_ques, a_ans] = cvxpy.Variable(
                      (dim * num_outputs_bob, dim * num_outputs_bob), hermitian=True
                  )
  
          tau = cvxpy.Variable((dim * num_outputs_bob, dim * num_outputs_bob), hermitian=True)
          win = 0
          for x_ques in range(num_inputs_alice):
              for y_ques in range(num_inputs_bob):
                  for a_ans in range(num_outputs_alice):
                      for b_ans in range(num_outputs_bob):
                          if isinstance(bob_povms[y_ques, b_ans], np.ndarray):
                              win += self.prob_mat[x_ques, y_ques] * cvxpy.trace(
                                  (
                                      np.kron(
                                          self.pred_mat[:, :, a_ans, b_ans, x_ques, y_ques],
                                          bob_povms[y_ques, b_ans],
                                      )
                                  )
                                  .conj()
                                  .T
                                  @ rho[x_ques, a_ans]
                              )
                          if isinstance(
                              bob_povms[y_ques, b_ans],
                              cvxpy.expressions.variable.Variable,
                          ):
                              win += self.prob_mat[x_ques, y_ques] * cvxpy.trace(
                                  (
                                      np.kron(
                                          self.pred_mat[:, :, a_ans, b_ans, x_ques, y_ques],
                                          bob_povms[y_ques, b_ans].value,
                                      )
                                  )
                                  .conj()
                                  .T
                                  @ rho[x_ques, a_ans]
                              )
          objective = cvxpy.Maximize(cvxpy.real(win))
          constraints = []
  
          # Sum over "a" for all "x" for Alice's measurements.
          for x_ques in range(num_inputs_alice):
              rho_sum_a = 0
              for a_ans in range(num_outputs_alice):
                  rho_sum_a += rho[x_ques, a_ans]
                  constraints.append(rho[x_ques, a_ans] >> 0)
              constraints.append(rho_sum_a == tau)
  
          constraints.append(cvxpy.trace(tau) == 1)
          constraints.append(tau >> 0)
  
          problem = cvxpy.Problem(objective, constraints)
  
          lower_bound = problem.solve()
          return rho, lower_bound
code_tokens: def __optimize_alice ( self , bob_povms ) -> Tuple [ Dict , float ] : ( dim , _ , num_outputs_alice , num_outputs_bob , num_inputs_alice , num_inputs_bob , ) = self . pred_mat . shape rho = defaultdict ( cvxpy . Variable ) for x_ques in range ( num_inputs_alice ) : for a_ans in range ( num_outputs_alice ) : rho [ x_ques , a_ans ] = cvxpy . Variable ( ( dim * num_outputs_bob , dim * num_outputs_bob ) , hermitian = True ) tau = cvxpy . Variable ( ( dim * num_outputs_bob , dim * num_outputs_bob ) , hermitian = True ) win = 0 for x_ques in range ( num_inputs_alice ) : for y_ques in range ( num_inputs_bob ) : for a_ans in range ( num_outputs_alice ) : for b_ans in range ( num_outputs_bob ) : if isinstance ( bob_povms [ y_ques , b_ans ] , np . ndarray ) : win += self . prob_mat [ x_ques , y_ques ] * cvxpy . trace ( ( np . kron ( self . pred_mat [ : , : , a_ans , b_ans , x_ques , y_ques ] , bob_povms [ y_ques , b_ans ] , ) ) . conj ( ) . T @ rho [ x_ques , a_ans ] ) if isinstance ( bob_povms [ y_ques , b_ans ] , cvxpy . expressions . variable . Variable , ) : win += self . prob_mat [ x_ques , y_ques ] * cvxpy . trace ( ( np . kron ( self . pred_mat [ : , : , a_ans , b_ans , x_ques , y_ques ] , bob_povms [ y_ques , b_ans ] . value , ) ) . conj ( ) . T @ rho [ x_ques , a_ans ] ) objective = cvxpy . Maximize ( cvxpy . real ( win ) ) constraints = [ ] for x_ques in range ( num_inputs_alice ) : rho_sum_a = 0 for a_ans in range ( num_outputs_alice ) : rho_sum_a += rho [ x_ques , a_ans ] constraints . append ( rho [ x_ques , a_ans ] >> 0 ) constraints . append ( rho_sum_a == tau ) constraints . append ( cvxpy . trace ( tau ) == 1 ) constraints . append ( tau >> 0 ) problem = cvxpy . Problem ( objective , constraints ) lower_bound = problem . solve ( ) return rho , lower_bound
short_docstring: Fix Bob's measurements and optimize over Alice's measurements.
short_docstring_tokens: Fix Bob ' s measurements and optimize over Alice ' s measurements .
comment: """Fix Bob's measurements and optimize over Alice's measurements."""$SEP$# Get number of inputs and outputs.$SEP$# The cvxpy package does not support optimizing over 4-dimensional objects.$SEP$# To overcome this, we use a dictionary to index between the questions and$SEP$# answers, while the cvxpy variables held at this positions are$SEP$# `dim`-by-`dim` cvxpy variables.$SEP$# Sum over "a" for all "x" for Alice's measurements.