Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing of initial state in EmulatorConfig, fix normalization with qutip 5 #792

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
]
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
),
1e-2,
)
)
Loading