qit.lmap.Lmap¶
- class qit.lmap.Lmap(s: Union[array_like, Lmap], dim: Optional[Sequence[int]] = None)¶
Bounded finite-dimensional linear maps between tensor products of Hilbert spaces.
Contains both the order-2 tensor representing the map, and the dimension vectors of the domain and codomain vector spaces. All the usual scalar-map and map-map arithmetic operators are provided, including the exponentiation of maps by integers.
Base class of
State
.- Parameters
s (Union['array_like', Lmap]) – Linear map. If an Lmap instance is given, a copy is made.
dim (Optional[Sequence[int]]) – 2-tuple containing the output and input subsystem dimensions stored in tuples:
dim == (out, in)
. Ifdim
,out
orin
isNone
, the corresponding dimensions are inferred froms
.
calling syntax resulting dim ============== ============= Lmap(rand(a)) ((a,), (1,)) 1D array default: ket vector Lmap(rand(a), ((1,), None)) ((1,), (a,)) bra vector given as a 1D array Lmap(rand(a, b)) ((a,), (b,)) 2D array, all dims inferred Lmap(rand(4, b), ((2, 2), None)) ((2, 2), (b,)) 2D array, output: two qubits Lmap(rand(a, 6), (None, (3, 2))) ((a,), (3, 2)) 2D array, input: qutrit+qubit Lmap(rand(6, 6), ((3, 2), (2, 3))) ((3, 2), (2, 3)) 2D array, all dims given Lmap(A) (A is an Lmap) copy constructor Lmap(A, dim) (A is an Lmap) copy constructor, redefine the dimensions
Attributes
linear map data
2-tuple of output and input dimension tuples, big-endian
Methods
conj
()Complex conjugate.
Hermitian conjugate.
imag
()Imaginary part.
True iff the Lmaps have equal dimensions and can thus be added.
is_ket
()True if the Lmap is a ket.
True if the Lmap is internally represented as a sparse array.
norm
()Frobenius matrix norm of the Lmap.
real
()Real part.
Eliminate unnecessary singleton dimensions.
reorder
(perm[, inplace])Change the relative order of the input and/or output subsystems.
reorder_legs
(perm[, inplace])Arbitrary reordering of Lmap input/output subsystems (tensor legs).
tensorpow
(n)Tensor power of the Lmap.
trace
()Trace of the Lmap.
Transpose.
- data¶
linear map data
- Type
array
- dim¶
2-tuple of output and input dimension tuples, big-endian
- Type
tuple[tuple, tuple]
- _inplacer(inplace)¶
Utility for implementing inplace operations.
- Parameters
inplace (bool) – iff True perform the operation in place
- Returns
iff inplace is True the object itself, otherwise a deep copy
- Return type
Functions using this should begin with
s = self._inplacer(inplace)
and end withreturn s
- remove_singletons()¶
Eliminate unnecessary singleton dimensions.
NOTE: changes the object itself!
- is_compatible(t)¶
True iff the Lmaps have equal dimensions and can thus be added.
- is_ket()¶
True if the Lmap is a ket.
- is_sparse()¶
True if the Lmap is internally represented as a sparse array.
- real()¶
Real part.
- imag()¶
Imaginary part.
- conj()¶
Complex conjugate.
- transpose()¶
Transpose.
- ctranspose()¶
Hermitian conjugate.
- trace()¶
Trace of the Lmap.
The trace is only properly defined if self.dim[0] == self.dim[1].
- norm()¶
Frobenius matrix norm of the Lmap.
- tensorpow(n)¶
Tensor power of the Lmap.
- Parameters
n (int) – number of copies of the Lmap to tensor together
- Returns
\(U^{\otimes n}\).
- Return type
- reorder_legs(perm, inplace=False)¶
Arbitrary reordering of Lmap input/output subsystems (tensor legs).
- Parameters
perm (Iterable[Iterable[int]]) – (t_1, t_2, …) where t_i are sequences of nonnegative integers, one for each Lmap index (normally two). Concatenated together the t_i must form a full permutation.
- Returns
copy of the Lmap with permuted leg order
- Return type
Differs from
Lmap.reorder
in thatreorder_legs
also allows permuting input legs into output legs and vice versa, i.e. there is just one big permutation for all the legs.
- reorder(perm, inplace=False)¶
Change the relative order of the input and/or output subsystems.
- Parameters
perm (tuple[Sequence[int]]) – 2-tuple of permutations of subsystem indices, (perm_out, perm_in)
- Returns
Copy of the Lmap with permuted subsystem order.
- Return type
A permutation can be either None (identity/do nothing), a pair (a, b) of subsystems to be swapped, or a tuple containing a full permutation of the subsystems. Two subsystems to be swapped must be in decreasing order so as not to mistake the two-element identity permutation (0, 1) for a swap.
reorder((None, (2, 1, 0))) # ignore first index, reverse the order of subsystems in the second reorder(((5, 2), None)) # swap the subsystems 2 and 5 in the first index, ignore the second
NOTE: The full permutations are interpreted in the same sense as numpy.transpose() understands them, i.e. the permutation tuple is the new ordering of the old subsystem indices. This is the inverse of the mathematically more common “one-line” notation.