Skip to content

Commit

Permalink
[Bugfix] Fix noisy simulation pulser and test (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
chMoussa authored Nov 15, 2024
1 parent ca7cf6a commit 4655065
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
27 changes: 7 additions & 20 deletions qadence/backends/pulser/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,27 +351,14 @@ def expectation(
noise=noise,
)
support = sorted(list(circuit.abstract.register.support))
# TODO: There should be a better check for batched density matrices.
if dms.size()[0] > 1:
res_list = [
[
obs.native(
dm.squeeze(), param_values, qubit_support=support, noise=noise
)
for dm in dms
]
for obs in observable
]
res = torch.stack(
[torch.transpose(torch.stack(res), 0, -1) for res in res_list]
)

else:
res_list = [
obs.native(dms, param_values, qubit_support=support) for obs in observable
res_list = [
[
obs.native(dm.squeeze(), param_values, qubit_support=support, noise=noise)
for dm in dms
]
res = torch.transpose(torch.stack(res_list), 0, 1)
res = res if len(res.shape) > 0 else res.reshape(1)
for obs in observable
]
res = torch.stack([torch.transpose(torch.stack(res), 0, -1) for res in res_list])
return res.real
elif mitigation is not None:
logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def batched_noisy_pulser_sim() -> Tensor:

@fixture
def noisy_pulser_sim() -> Tensor:
return tensor([[[0.3043, 0.0000, 0.0000, -0.0038]]])
return tensor([[0.3597]])


@fixture
Expand Down

0 comments on commit 4655065

Please sign in to comment.