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

Type of initial state is too strict #789

Open
HaroldErbin opened this issue Jan 10, 2025 · 0 comments
Open

Type of initial state is too strict #789

HaroldErbin opened this issue Jan 10, 2025 · 0 comments

Comments

@HaroldErbin
Copy link
Contributor

It seems that the data type of initial_state in pulser.EmulatorConfig is too strict. Indeed, I am defining the state as a numpy array, and it is not recognized as a valid Sequence[Complex].

Here is my code:

if initial_state == "plus":
    initial_state = np.ones(2**L, dtype=np.complex128)
elif initial_state == "down":
    initial_state = "all-ground"
else:
    raise ValueError(f"Initial state '{initial_state}' is not valid.")

config = pulser.EmulatorConfig(
        sampling_rate=sampling_rate,
        evaluation_times="Full",
        initial_state=initial_state,
    )

PyLance in VSCode complains:

Argument of type "NDArray[float64] | Literal['all-ground']" cannot be assigned to parameter "initial_state" of type "Sequence[complex] | Literal['all-ground']" in function "__init__"
  Type "NDArray[float64] | Literal['all-ground']" is not assignable to type "Sequence[complex] | Literal['all-ground']"
    Type "NDArray[float64]" is not assignable to type "Sequence[complex] | Literal['all-ground']"
      "ndarray[Any, dtype[float64]]" is not assignable to "Sequence[complex]"
      "ndarray[Any, dtype[float64]]" is not assignable to "Literal['all-ground']"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
(parameter) initial_state: NDArray[float64] | Literal['all-ground']

Specifying that dtype=complex gives NDArray[Any] and dtype=np.complex128 gives NDArray[complexfloating[_64Bit, _64Bit]], none of them recognized as Sequence[complex].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant