-
Notifications
You must be signed in to change notification settings - Fork 32
redefining OperatorEvolution class and fixing typehints
#1528
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| from typing import Protocol | ||
|
|
||
| import numpy as np | ||
| from numpy.typing import NDArray | ||
| from numpy.typing import ArrayLike, NDArray | ||
|
|
||
| from qibolab._core.serialize import Model | ||
|
|
||
|
|
@@ -43,9 +43,27 @@ class Operator(Protocol): | |
| def dag(self) -> "Operator": | ||
| """Return the adjoint of the operator.""" | ||
|
|
||
| def full(self) -> "Operator": | ||
| """Return the matrix form of the operator.""" | ||
|
|
||
| def __add__(self, other: "Operator") -> "Operator": | ||
| """Add two operators.""" | ||
|
|
||
| def __sub__(self, other: "Operator") -> "Operator": | ||
| """Subtract two operators.""" | ||
|
|
||
| def __mul__(self, other: float | int | complex) -> "Operator": | ||
| """Scalar multiplication.""" | ||
|
|
||
| def __rmul__(self, other: float | int | complex) -> "Operator": | ||
| """Right-hand scalar multiplication.""" | ||
|
|
||
| def __truediv__(self, other: float | int | complex) -> "Operator": | ||
| """Scalar division.""" | ||
|
|
||
| def __matmul__(self, other: "Operator") -> "Operator": | ||
| """Multiply two operators.""" | ||
|
|
||
|
|
||
| TimeDependentOperator = tuple[Operator, NDArray] | ||
| """Abstract time dependent operator type.""" | ||
|
|
@@ -62,7 +80,9 @@ class EvolutionResult(Protocol): | |
| class OperatorEvolution: | ||
| """Abstract operator evolution interface.""" | ||
|
|
||
| operators: list[Operator | TimeDependentOperator] = field(default_factory=list) | ||
| static: Operator | ||
| """static term in the system evolution""" | ||
| operators: list[TimeDependentOperator] = field(default_factory=list) | ||
| """List of static or time-dependent operators for evolution.""" | ||
| times: NDArray = field(default_factory=lambda: np.array([], dtype=float)) | ||
| """Evolution times with time step equal to the waveforms resolution.""" | ||
|
|
@@ -79,10 +99,10 @@ def engine(self): | |
| @abstractmethod | ||
| def evolve( | ||
| self, | ||
| hamiltonian: Operator, | ||
| hamiltonian: OperatorEvolution, | ||
| initial_state: Operator, | ||
| time: list[float], | ||
| collapse_operators: list[Operator] = None, | ||
| time: ArrayLike, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in |
||
| collapse_operators: list[Operator] | None = None, | ||
| **kwargs, | ||
| ) -> tuple[EvolutionResult, dict]: | ||
| """Evolve the system.""" | ||
|
|
@@ -110,5 +130,5 @@ def expand( | |
| """Expand operator in larger Hilbert space.""" | ||
|
|
||
| @abstractmethod | ||
| def basis(self, n: int, state: int) -> Operator: | ||
| def basis(self, dim: int | list[int], state: int | list[int]) -> Operator: | ||
| """Basis operator for n levels system.""" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qibolab/benchmarks/engine_sweep.py
Line 81 in dd6f942
This
hamiltoniancan be 0 or something else, but eventually is also passed toevolve.