Skip to content

Commit

Permalink
[Fix] Simulation with state preparation errors fixed (#354)
Browse files Browse the repository at this point in the history
* Fixing bug related to simulation with state preparation errors

* Updating the noisy simulations notebook
  • Loading branch information
HGSilveri authored Apr 6, 2022
1 parent c34dffb commit e954b9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
11 changes: 5 additions & 6 deletions pulser/simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,19 +642,18 @@ def _build_basis_and_op_matrices(self) -> None:
self.basis[proj[0]] * self.basis[proj[1]].dag()
)

def _construct_hamiltonian(self, update_and_extract: bool = True) -> None:
def _construct_hamiltonian(self, update: bool = True) -> None:
"""Constructs the hamiltonian from the Sequence.
Also builds qutip.Qobjs related to the Sequence if not built already,
and refreshes potential noise parameters by drawing new at random.
Args:
update_and_extract(bool=True): Whether to update the noise
parameters and extract the samples from the sequence.
update(bool=True): Whether to update the noise parameters.
"""
if update_and_extract:
if update:
self._update_noise()
self._extract_samples()
self._extract_samples()
if not hasattr(self, "basis_name"):
self._build_basis_and_op_matrices()

Expand Down Expand Up @@ -976,7 +975,7 @@ def _run_solver() -> CoherentResults:
else:
reps = 1
# At each run, new random noise: new Hamiltonian
self._construct_hamiltonian(update_and_extract=update_ham)
self._construct_hamiltonian(update=update_ham)
# Get CoherentResults instance from sequence with added noise:
cleanres_noisyseq = _run_solver()
# Extract statistics at eval time:
Expand Down
Loading

0 comments on commit e954b9f

Please sign in to comment.