diff --git a/VERSION.txt b/VERSION.txt index 867e52437..cb174d58a 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -1.2.0 \ No newline at end of file +1.2.1 \ No newline at end of file diff --git a/pulser-core/pulser/backend/config.py b/pulser-core/pulser/backend/config.py index 2da0e6f99..482fd29ff 100644 --- a/pulser-core/pulser/backend/config.py +++ b/pulser-core/pulser/backend/config.py @@ -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) diff --git a/pulser-simulation/pulser_simulation/simulation.py b/pulser-simulation/pulser_simulation/simulation.py index 653ef20d0..c180c7f8b 100644 --- a/pulser-simulation/pulser_simulation/simulation.py +++ b/pulser-simulation/pulser_simulation/simulation.py @@ -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: diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 58866bc67..7a9e5fbf5 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -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, + ) + )