-
Notifications
You must be signed in to change notification settings - Fork 4
Tal/review #8
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: master
Are you sure you want to change the base?
Tal/review #8
Changes from all commits
4d2d0ca
dc8d5a5
e989473
c51f241
b4fe228
0df1eaf
e59e618
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 |
|---|---|---|
|
|
@@ -26,12 +26,12 @@ class PolarizationOperationType(Enum): | |
|
|
||
| Constructs an operator, which acts on a single Polarization Space | ||
|
|
||
| Identity (I) | ||
| Identity (Id) | ||
| ------------ | ||
| Constructs Identity (:math:`\hat{I}`) operator | ||
| Constructs Identity (:math:`\hat{Id}`) operator | ||
| .. math:: | ||
|
|
||
| \hat{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} | ||
| \hat{Id} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} | ||
|
|
||
| Pauli X (X) | ||
| ----------- | ||
|
|
@@ -48,8 +48,8 @@ class PolarizationOperationType(Enum): | |
| .. math:: | ||
|
|
||
| \hat{\sigma_y} = \begin{bmatrix} | ||
| 0 & -i \\ | ||
| i & 0 | ||
| 0 & -Id \\ | ||
| Id & 0 | ||
| \end{bmatrix} | ||
|
|
||
| Pauli Z (Z) | ||
|
|
@@ -72,20 +72,20 @@ class PolarizationOperationType(Enum): | |
| Constructs Phase (:math:`\hat S`) operator | ||
| .. math:: | ||
|
|
||
| \hat{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} | ||
| \hat{S} = \begin{bmatrix} 1 & 0 \\ 0 & Id \end{bmatrix} | ||
|
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 this case i also represents imaginary number. |
||
|
|
||
| T Opeator (T) | ||
| ------------- | ||
| Constructs T (:math:`\hat T`) operator | ||
| .. math:: | ||
| \hat{T} = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \pi/4} \end{bmatrix} | ||
| \hat{T} = \begin{bmatrix} 1 & 0 \\ 0 & e^{Id \pi/4} \end{bmatrix} | ||
|
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. Again, i represents imaginary number. |
||
|
|
||
| Sqrt(X) Operator (SX) | ||
| --------------------- | ||
| Constructs SX (:math:`\hat{SX}`) operator | ||
| .. math:: | ||
|
|
||
| \hat{SX} = \frac{1}{2} \begin{bmatrix} 1+i & 1-i \\ 1-i & 1+i \end{bmatrix} | ||
| \hat{SX} = \frac{1}{2} \begin{bmatrix} 1+Id & 1-Id \\ 1-Id & 1+Id \end{bmatrix} | ||
|
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. Again, i represents imaginary number. |
||
|
|
||
| RX Operator (RX) | ||
| ---------------- | ||
|
|
@@ -95,8 +95,8 @@ class PolarizationOperationType(Enum): | |
| .. math:: | ||
|
|
||
| \hat{RX} = \begin{bmatrix} | ||
| \cos\left(\frac{\theta}{2}\right) & -i\sin\left(\frac{\theta}{2}\right) \\ | ||
| -i\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) | ||
| \cos\left(\frac{\theta}{2}\right) & -Id\sin\left(\frac{\theta}{2}\right) \\ | ||
| -Id\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) | ||
|
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. Again, i represents imaginary number. |
||
| \end{bmatrix} | ||
|
|
||
| Usage Example | ||
|
|
@@ -126,8 +126,8 @@ class PolarizationOperationType(Enum): | |
| .. math:: | ||
|
|
||
| \hat{RZ} = \begin{bmatrix} | ||
| e^{-i\frac{\theta}{2}} & 0 \\ | ||
| 0 & e^{i\frac{\theta}{2}} | ||
| e^{-Id\frac{\theta}{2}} & 0 \\ | ||
| 0 & e^{Id\frac{\theta}{2}} | ||
|
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. Again, i represents imaginary number. |
||
| \end{bmatrix} | ||
|
|
||
| Usage Example | ||
|
|
@@ -150,7 +150,7 @@ class PolarizationOperationType(Enum): | |
| >>> op = Operation(PolarizationOperationType.Custom, operator=operator) | ||
| """ | ||
|
|
||
| I: Tuple[bool, List[str], ExpansionLevel, int] = ( | ||
| Id: Tuple[bool, List[str], ExpansionLevel, int] = ( | ||
| True, | ||
| [], | ||
| ExpansionLevel.Vector, | ||
|
|
@@ -263,7 +263,7 @@ def compute_operator(self, dimensions: List[int], **kwargs: Any) -> jnp.ndarray: | |
| Returns operator matrix | ||
| """ | ||
| match self: | ||
| case PolarizationOperationType.I: | ||
| case PolarizationOperationType.Id: | ||
| return identity_operator() | ||
| case PolarizationOperationType.X: | ||
| return x_operator() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,7 @@ def reorder(self, *ordered_states: "BaseState") -> None: | |
|
|
||
| # Update the new order | ||
| self.state_objs = list(ordered_states) | ||
|
|
||
| elif self.expansion_level == ExpansionLevel.Matrix: | ||
| # Get the state and reshape it | ||
| shape = [os.dimensions for os in self.state_objs] * 2 | ||
|
|
@@ -129,8 +130,8 @@ def reorder(self, *ordered_states: "BaseState") -> None: | |
| def measure( | ||
| self, | ||
| *states: "BaseState", | ||
| separate_measurement: bool = False, | ||
| destructive: bool = True, | ||
| separate_measurement: bool = False, | ||
| ) -> Dict["BaseState", int]: | ||
| """ | ||
| Measures this subspace. If the state is measured partially, then the state | ||
|
|
@@ -163,13 +164,13 @@ def measure( | |
| C = Config() | ||
|
|
||
| remaining_states = [s for s in self.state_objs] | ||
|
|
||
| # TODO: Replace this with a match statement to make it more readable | ||
| if self.expansion_level == ExpansionLevel.Vector: | ||
| # Get the state and reshape it into tensor | ||
| shape = [so.dimensions for so in self.state_objs] | ||
| shape.append(1) | ||
| ps = self.state.reshape(shape) | ||
| for idx, state in enumerate(states): | ||
| for state in states: | ||
| # Constructing the einsum str | ||
| einsum = ESC.measure_vector(remaining_states, [state]) | ||
|
|
||
|
|
@@ -213,17 +214,20 @@ def measure( | |
| state.index = None | ||
| state.expansion_level = ExpansionLevel.Label | ||
| self.state_objs.remove(state) | ||
|
|
||
| if len(self.state_objs) > 0: | ||
| # Handle reshaping and storing the post measurement product state | ||
| self.state = ps.reshape(-1, 1) | ||
| self.state /= jnp.linalg.norm(self.state) | ||
|
|
||
| else: | ||
| # Product state will be deleted | ||
| self.state = jnp.array([[1]]) | ||
|
|
||
| elif self.expansion_level == ExpansionLevel.Matrix: | ||
| shape = [so.dimensions for so in self.state_objs] * 2 | ||
| ps = self.state.reshape(shape) | ||
| for idx, state in enumerate(states): | ||
| for state in states: | ||
| # Generate einsum string | ||
| einsum = ESC.measure_matrix(remaining_states, [state]) | ||
|
|
||
|
|
@@ -269,7 +273,7 @@ def measure( | |
| state.index = None | ||
| state.expansion_level = ExpansionLevel.Label | ||
|
|
||
| # Remove the mesaured state from the product state | ||
| # Remove the measured state from the product state | ||
| self.state_objs.remove(state) | ||
|
|
||
| # Reconstruct the post measurement product state | ||
|
|
@@ -643,7 +647,8 @@ def apply_operation(self, operation: Operation, *states: "BaseState") -> None: | |
| for i, s in enumerate(states): | ||
| op_type = operation._operation_type | ||
| assert isinstance( | ||
| s, op_type.expected_base_state_types[i] # type: ignore | ||
| s, | ||
| op_type.expected_base_state_types[i], # type: ignore | ||
| ) | ||
| operation.compute_dimensions( | ||
| [s._num_quanta if isinstance(s, Fock) else 0 for s in states], | ||
|
|
@@ -755,6 +760,7 @@ def update_all_indices(self) -> None: | |
| ][0] | ||
|
|
||
|
|
||
| # FIXME: Inherit from Envelope to limit code duplication ? | ||
|
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.
|
||
| class CompositeEnvelope: | ||
| """ | ||
| Composite Envelope is a pointer to a container, which includes the state | ||
|
|
||
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.
In this case i represents imaginary number, not identity matrix.