Skip to content

Commit

Permalink
Update dependency pulser-core to v1.2.0 (#636)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
renovate[bot] authored Jan 6, 2025
1 parent 1636785 commit c426f17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ allow-ambiguous-features = true

[project.optional-dependencies]
pulser = [
"pulser-core==1.1.1",
"pulser-simulation==1.1.1",
"pulser-core==1.2.0",
"pulser-simulation==1.2.0",
"pasqal-cloud==0.12.6",
]
visualization = [
Expand Down
2 changes: 1 addition & 1 deletion qadence/backends/pulser/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def run_noisy_sim(noise_prob: float) -> Tensor:
for i, param_values_el in enumerate(vals):
sequence = self.assign_parameters(circuit, param_values_el)
sim_result: CoherentResults = simulate_sequence(sequence, self.config, state)
final_state = sim_result.get_final_state().data.toarray()
final_state = sim_result.get_final_state().data.to_array()
batched_dm[i] = np.flip(final_state)
return torch.from_numpy(batched_dm)

Expand Down
4 changes: 3 additions & 1 deletion qadence/engines/torch/differentiable_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def forward(
if isinstance(expectation_values[0], list):
exp_vals: list = []
for expectation_value in expectation_values:
res = list(map(lambda x: x.get_final_state().data.toarray(), expectation_value))
res = list(
map(lambda x: x.get_final_state().data.to_array(), expectation_value)
)
exp_vals.append(torch.tensor(res))
expectation_values = exp_vals
return torch.stack(expectation_values)
Expand Down
16 changes: 16 additions & 0 deletions tests/backends/pulser_basic/test_quantum_pulser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_noisy_simulations(noiseless_pulser_sim: Tensor, noisy_pulser_sim: Tenso
assert torch.allclose(noiseless_expectation, noiseless_pulser_sim, atol=1.0e-3)
assert torch.allclose(noisy_expectation, noisy_pulser_sim, atol=1.0e-3)

# test backend itself
backend = backend_factory(backend=BackendName.PULSER, diff_mode=DiffMode.GPSR)
(pulser_circ, pulser_obs, embed, params) = backend.convert(circuit, observable)
native_noisy_expectation = backend.expectation(
pulser_circ, pulser_obs, embed(params, {}), noise=noise
)
assert torch.allclose(native_noisy_expectation, noisy_expectation, atol=1.0e-3)


def test_batched_noisy_simulations(
noiseless_pulser_sim: Tensor, batched_noisy_pulser_sim: Tensor
Expand All @@ -95,3 +103,11 @@ def test_batched_noisy_simulations(
batched_noisy_expectation = model_noisy.expectation()
assert torch.allclose(noiseless_expectation, noiseless_pulser_sim, atol=1.0e-3)
assert torch.allclose(batched_noisy_expectation, batched_noisy_pulser_sim, atol=1.0e-3)

# test backend itself
backend = backend_factory(backend=BackendName.PULSER, diff_mode=DiffMode.GPSR)
(pulser_circ, pulser_obs, embed, params) = backend.convert(circuit, observable)
batched_native_expectation = backend.expectation(
pulser_circ, pulser_obs, embed(params, {}), noise=noise
)
assert torch.allclose(batched_native_expectation, batched_noisy_pulser_sim, atol=1.0e-3)

0 comments on commit c426f17

Please sign in to comment.