Skip to content

Commit

Permalink
Fix typing of initial state in EmulatorConfig, fix normalization with…
Browse files Browse the repository at this point in the history
… qutip 5 (#792)

* Delete no-normalization output

* Normalize initial state

* Bump to v1.2.1
  • Loading branch information
a-corni authored Jan 23, 2025
1 parent c986ec1 commit 7f91905
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.2.1
4 changes: 3 additions & 1 deletion pulser-core/pulser/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class EmulatorConfig(BackendConfig):

sampling_rate: float = 1.0
evaluation_times: float | Sequence[float] | EVAL_TIMES_LITERAL = "Full"
initial_state: Literal["all-ground"] | Sequence[complex] = "all-ground"
initial_state: Literal["all-ground"] | Sequence[complex] | np.ndarray = (
"all-ground"
)
with_modulation: bool = False
prefer_device_noise_model: bool = False
noise_model: NoiseModel = field(default_factory=NoiseModel)
Expand Down
4 changes: 3 additions & 1 deletion pulser-simulation/pulser_simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ def set_initial_state(
"Incompatible shape of initial state."
+ f"Expected {legal_shape}, got {shape}."
)
self._initial_state = qutip.Qobj(state, dims=legal_dims).to("CSR")
self._initial_state = (
qutip.Qobj(state, dims=legal_dims).unit().to("CSR")
)

@property
def evaluation_times(self) -> np.ndarray:
Expand Down
33 changes: 33 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,3 +1639,36 @@ def pos_factor(qid):
)
# Drawing with modulation
sim.draw()


def test_initial_state_sim():
seq = Sequence(
Register({"q0": (-6, 0), "q1": (0, 0), "q2": (6, 0)}), AnalogDevice
)
seq.declare_channel("ising", "rydberg_global")
seq.add(Pulse.ConstantPulse(4000, 9.28, 18.7, 0), "ising")
L = len(seq.register.qubits)
initial_state = np.ones(2**L)
emulator = QutipEmulator.from_sequence(seq)
emulator.set_initial_state(initial_state)
np.random.seed(123)
res = emulator.run()
final_state = res.get_final_state()
assert np.all(
np.isclose(
final_state.full(),
np.array(
[
[0.28985369 + 0.13530479j],
[0.40220557 + 0.0j],
[0.27445983 + 0.15541026j],
[0.29608403 + 0.06155379j],
[0.40220557 + 0.0j],
[0.36173532 - 0.01617572j],
[0.29608403 + 0.06155379j],
[0.36931122 - 0.15570528j],
]
),
1e-2,
)
)

0 comments on commit 7f91905

Please sign in to comment.