def probabilities(self, angles):
"""
Computes the probability of each state given a particular set of angles.
:param angles: [list] A concatenated list of angles [betas]+[gammas]
:return: [list] The probabilities of each outcome given those angles.
"""
if isinstance(angles, list):
angles = np.array(angles)
assert angles.shape[0] == 2 * self.steps, "angles must be 2 * steps"
param_prog = self.get_parameterized_program()
prog = param_prog(angles)
wf = self.qvm.wavefunction(prog)
wf = wf.amplitudes.reshape((-1, 1))
probs = np.zeros_like(wf)
for xx in range(2 ** self.n_qubits):
probs[xx] = np.conj(wf[xx]) * wf[xx]
return probs
评论列表
文章目录