Skip to content

Commit

Permalink
Fix MeasureMulti*PauliSum
Browse files Browse the repository at this point in the history
self.measure_multiple_times returns a [len(obs_list), num_wires] tensor, you have to take the product over the wires first to get the measurement of the Pauli string and then sum over the obs_list (multiplied by coefficients in the case of MeasureMultiQubitPaulisum.
  • Loading branch information
yannick-couzinie authored Nov 12, 2024
1 parent 611cc2a commit a69808e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions torchquantum/measurement/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def __init__(self, obs_list, v_c_reg_mapping=None):
)

def forward(self, qdev: tq.QuantumDevice):
res_all = self.measure_multiple_times(qdev)
res_all = self.measure_multiple_times(qdev).prod(-1)

return res_all.sum(-1)

Expand Down Expand Up @@ -452,8 +452,9 @@ def __init__(self, obs_list, v_c_reg_mapping=None):
)

def forward(self, qdev: tq.QuantumDevice):
res_all = self.measure_multiple_times(qdev)
return (res_all * self.obs_list[0]["coefficient"]).sum(-1)
res_all = self.measure_multiple_times(qdev).prod(-1)

return (res_all * torch.tensor(self.obs_list[0]["coefficient"])).sum(-1)


if __name__ == '__main__':
Expand Down

0 comments on commit a69808e

Please sign in to comment.