original_docstring: Fix Alice's measurements and optimize over Bob's measurements.
docstring: Fix Alice's measurements and optimize over Bob's measurements.
docstring_tokens: Fix Alice ' s measurements and optimize over Bob ' s measurements .
code: def __optimize_bob(self, rho) -> Tuple[Dict, float]:
          """Fix Alice's measurements and optimize over Bob'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.
          bob_povms = defaultdict(cvxpy.Variable)
          for y_ques in range(num_inputs_bob):
              for b_ans in range(num_outputs_bob):
                  bob_povms[y_ques, b_ans] = cvxpy.Variable((dim, dim), 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):
                          win += self.prob_mat[x_ques, y_ques] * cvxpy.trace(
                              (
                                  cvxpy.kron(
                                      self.pred_mat[:, :, a_ans, b_ans, x_ques, y_ques],
                                      bob_povms[y_ques, b_ans],
                                  )
                              )
                              @ rho[x_ques, a_ans].value
                          )
          objective = cvxpy.Maximize(cvxpy.real(win))
  
          constraints = []
  
          # Sum over "b" for all "y" for Bob's measurements.
          for y_ques in range(num_inputs_bob):
              bob_sum_b = 0
              for b_ans in range(num_outputs_bob):
                  bob_sum_b += bob_povms[y_ques, b_ans]
                  constraints.append(bob_povms[y_ques, b_ans] >> 0)
              constraints.append(bob_sum_b == np.identity(num_outputs_bob))
  
          problem = cvxpy.Problem(objective, constraints)
  
          lower_bound = problem.solve()
          return bob_povms, lower_bound
code_tokens: def __optimize_bob ( self , rho ) -> Tuple [ Dict , float ] : ( dim , _ , num_outputs_alice , num_outputs_bob , num_inputs_alice , num_inputs_bob , ) = self . pred_mat . shape bob_povms = defaultdict ( cvxpy . Variable ) for y_ques in range ( num_inputs_bob ) : for b_ans in range ( num_outputs_bob ) : bob_povms [ y_ques , b_ans ] = cvxpy . Variable ( ( dim , dim ) , 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 ) : win += self . prob_mat [ x_ques , y_ques ] * cvxpy . trace ( ( cvxpy . kron ( self . pred_mat [ : , : , a_ans , b_ans , x_ques , y_ques ] , bob_povms [ y_ques , b_ans ] , ) ) @ rho [ x_ques , a_ans ] . value ) objective = cvxpy . Maximize ( cvxpy . real ( win ) ) constraints = [ ] for y_ques in range ( num_inputs_bob ) : bob_sum_b = 0 for b_ans in range ( num_outputs_bob ) : bob_sum_b += bob_povms [ y_ques , b_ans ] constraints . append ( bob_povms [ y_ques , b_ans ] >> 0 ) constraints . append ( bob_sum_b == np . identity ( num_outputs_bob ) ) problem = cvxpy . Problem ( objective , constraints ) lower_bound = problem . solve ( ) return bob_povms , lower_bound
short_docstring: Fix Alice's measurements and optimize over Bob's measurements.
short_docstring_tokens: Fix Alice ' s measurements and optimize over Bob ' s measurements .
comment: """Fix Alice's measurements and optimize over Bob'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 "b" for all "y" for Bob's measurements.