|
1 | 1 | # [Tensor Products and Partial Traces](@id doc:Tensor-products-and-Partial-Traces) |
2 | 2 |
|
3 | | -This page is still under construction, please visit [API](@ref doc-API) first. |
| 3 | +```@setup tensor_products |
| 4 | +using QuantumToolbox |
| 5 | +``` |
| 6 | + |
| 7 | +## [Tensor products](@id doc:Tensor-products) |
| 8 | + |
| 9 | +To describe the states of multipartite quantum systems (such as two coupled qubits, a qubit coupled to an oscillator, etc.) we need to expand the Hilbert space by taking the tensor product of the state vectors for each of the system components. Similarly, the operators acting on the state vectors in the combined Hilbert space (describing the coupled system) are formed by taking the tensor product of the individual operators. |
| 10 | + |
| 11 | +In `QuantumToolbox`, the function [`tensor`](@ref) (or [`kron`](@ref)) is used to accomplish this task. This function takes a collection of [`Ket`](@ref) or [`Operator`](@ref) as argument and returns a composite [`QuantumObject`](@ref) for the combined Hilbert space. The function accepts an arbitrary number of [`QuantumObject`](@ref) as argument. The `type` of returned [`QuantumObject`](@ref) is the same as that of the input(s). |
| 12 | + |
| 13 | +A collection of [`QuantumObject`](@ref): |
| 14 | +```@example tensor_products |
| 15 | +tensor(sigmax(), sigmax(), sigmax()) |
| 16 | +``` |
| 17 | + |
| 18 | +or a `Vector{QuantumObject}`: |
| 19 | + |
| 20 | +```@example tensor_products |
| 21 | +op_list = fill(sigmax(), 3) |
| 22 | +tensor(op_list) |
| 23 | +``` |
| 24 | + |
| 25 | +!!! warning "Beware of type-stability!" |
| 26 | + Please note that `tensor(op_list)` or `kron(op_list)` with `op_list` is a `Vector` is type-instable and can hurt performance. It is recommended to use `tensor(op_list...)` or `kron(op_list...)` instead. See the Section [The Importance of Type-Stability](@ref doc:Type-Stability) for more details. |
| 27 | + |
| 28 | +For example, the state vector describing two qubits in their ground states is formed by taking the tensor product of the two single-qubit ground state vectors: |
| 29 | + |
| 30 | +```@example tensor_products |
| 31 | +tensor(basis(2, 0), basis(2, 0)) |
| 32 | +``` |
| 33 | + |
| 34 | +One can generalize to more qubits by adding more component state vectors in the argument list to the [`tensor`](@ref) (or [`kron`](@ref)) function, as illustrated in the following example: |
| 35 | + |
| 36 | +```@example tensor_products |
| 37 | +states = QuantumObject[ |
| 38 | + normalize(basis(2, 0) + basis(2, 1)), |
| 39 | + normalize(basis(2, 0) + basis(2, 1)), |
| 40 | + basis(2, 0) |
| 41 | +] |
| 42 | +tensor(states...) |
| 43 | +``` |
| 44 | +This state is slightly more complicated, describing two qubits in a superposition between the up and down states, while the third qubit is in its ground state. |
| 45 | + |
| 46 | +To construct operators that act on an extended Hilbert space of a combined system, we similarly pass a list of operators for each component system to the [`tensor`](@ref) (or [`kron`](@ref)) function. For example, to form the operator that represents the simultaneous action of the ``\sigma_x`` operator on two qubits: |
| 47 | + |
| 48 | +```@example tensor_products |
| 49 | +tensor(sigmax(), sigmax()) |
| 50 | +``` |
| 51 | + |
| 52 | +To create operators in a combined Hilbert space that only act on a single component, we take the tensor product of the operator acting on the subspace of interest, with the identity operators corresponding to the components that are to be unchanged. For example, the operator that represents ``\sigma_z`` on the first qubit in a two-qubit system, while leaving the second qubit unaffected: |
| 53 | + |
| 54 | +```@example tensor_products |
| 55 | +tensor(sigmaz(), qeye(2)) |
| 56 | +``` |
| 57 | + |
| 58 | +## Example: Constructing composite Hamiltonians |
| 59 | + |
| 60 | +The [`tensor`](@ref) (or [`kron`](@ref)) function is extensively used when constructing Hamiltonians for composite systems. Here we’ll look at some simple examples. |
| 61 | + |
| 62 | +### Two coupled qubits |
| 63 | + |
| 64 | +First, let’s consider a system of two coupled qubits. Assume that both the qubits have equal energy splitting, and that the qubits are coupled through a ``\sigma_x \otimes \sigma_x`` interaction with strength ``g = 0.05`` (in units where the bare qubit energy splitting is unity). The Hamiltonian describing this system is: |
| 65 | + |
| 66 | +```@example tensor_products |
| 67 | +H = tensor(sigmaz(), qeye(2)) + |
| 68 | + tensor(qeye(2), sigmaz()) + |
| 69 | + 0.05 * tensor(sigmax(), sigmax()) |
| 70 | +``` |
| 71 | + |
| 72 | +### Three coupled qubits |
| 73 | + |
| 74 | +The two-qubit example is easily generalized to three coupled qubits: |
| 75 | + |
| 76 | +```@example tensor_products |
| 77 | +H = tensor(sigmaz(), qeye(2), qeye(2)) + |
| 78 | + tensor(qeye(2), sigmaz(), qeye(2)) + |
| 79 | + tensor(qeye(2), qeye(2), sigmaz()) + |
| 80 | + 0.5 * tensor(sigmax(), sigmax(), qeye(2)) + |
| 81 | + 0.25 * tensor(qeye(2), sigmax(), sigmax()) |
| 82 | +``` |
| 83 | + |
| 84 | +### A two-level system coupled to a cavity: The Jaynes-Cummings model |
| 85 | + |
| 86 | +The simplest possible quantum mechanical description for light-matter interaction is encapsulated in the Jaynes-Cummings model, which describes the coupling between a two-level atom and a single-mode electromagnetic field (a cavity mode). Denoting the energy splitting of the atom and cavity ``\omega_a`` and ``\omega_c``, respectively, and the atom-cavity interaction strength ``g``, the Jaynes-Cummings Hamiltonian can be constructed as: |
| 87 | + |
| 88 | +```math |
| 89 | +H = \frac{\omega_a}{2}\sigma_z + \omega_c a^\dagger a + g (a^\dagger \sigma_- + a \sigma_+) |
| 90 | +``` |
| 91 | + |
| 92 | +```@example tensor_products |
| 93 | +N = 6 # cavity fock space truncation |
| 94 | +ωc = 1.25 # frequency of cavity |
| 95 | +ωa = 1.0 # frequency of two-level atom |
| 96 | +g = 0.75 # interaction strength |
| 97 | +
|
| 98 | +a = tensor(qeye(2), destroy(N)) # cavity annihilation operator |
| 99 | +
|
| 100 | +# two-level atom operators |
| 101 | +σm = tensor(destroy(2), qeye(N)) |
| 102 | +σz = tensor(sigmaz(), qeye(N)) |
| 103 | +
|
| 104 | +H = 0.5 * ωa * σz + ωc * a' * a + g * (a' * σm + a * σm') |
| 105 | +``` |
| 106 | + |
| 107 | +## [Partial trace](@id doc:Partial-trace) |
| 108 | + |
| 109 | +The partial trace is an operation that reduces the dimension of a Hilbert space by eliminating some degrees of freedom by averaging (tracing). In this sense it is therefore the converse of the tensor product. It is useful when one is interested in only a part of a coupled quantum system. For open quantum systems, this typically involves tracing over the environment leaving only the system of interest. In `QuantumToolbox` the function [`ptrace`](@ref) is used to take partial traces. [`ptrace`](@ref) takes one [`QuantumObject`](@ref) as an input, and also one argument `sel`, which marks the component systems that should be kept, and all the other components are traced out. |
| 110 | + |
| 111 | +Remember that the index of `Julia` starts from `1`, and all the elements in `sel` should be positive `Integer`. Therefore, the type of `sel` can be either `Integer`, `Tuple`, `SVector`, or `Vector`. |
| 112 | + |
| 113 | +!!! warning "Beware of type-stability!" |
| 114 | + Although it supports also `Vector` type, it is recommended to use `Tuple` or `SVector` from [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl) to improve performance. For a brief explanation on the impact of the type of `sel`, see the section [The Importance of Type-Stability](@ref doc:Type-Stability). |
| 115 | + |
| 116 | +For example, the density matrix describing a single qubit obtained from a coupled two-qubit system is obtained via: |
| 117 | + |
| 118 | +```@example tensor_products |
| 119 | +ψ = tensor( |
| 120 | + basis(2, 0), |
| 121 | + basis(2, 1), |
| 122 | + normalize(basis(2, 0) + basis(2, 1)) |
| 123 | +) |
| 124 | +``` |
| 125 | + |
| 126 | +```@example tensor_products |
| 127 | +ptrace(ψ, 1) # trace out 2nd and 3rd systems |
| 128 | +``` |
| 129 | + |
| 130 | +```@example tensor_products |
| 131 | +ptrace(ψ, (1, 3)) # trace out 2nd system |
| 132 | +``` |
| 133 | + |
| 134 | +Note that the partial trace always results in a [`Operator`](@ref) (density matrix), regardless of whether the composite system is a pure state (described by a [`Ket`](@ref)) or a mixed state (described by a [`Operator`](@ref)): |
| 135 | + |
| 136 | +```@example tensor_products |
| 137 | +ψ1 = normalize(basis(2, 0) + basis(2, 1)) |
| 138 | +ψ2 = basis(2, 0) |
| 139 | +ψT = tensor(ψ1, ψ2) |
| 140 | +``` |
| 141 | + |
| 142 | +```@example tensor_products |
| 143 | +ptrace(ψT, 1) |
| 144 | +``` |
| 145 | + |
| 146 | +```@example tensor_products |
| 147 | +ρT = tensor(ket2dm(ψ1), ket2dm(ψ1)) |
| 148 | +``` |
| 149 | + |
| 150 | +```@example tensor_products |
| 151 | +ptrace(ρT, 1) |
| 152 | +``` |
0 commit comments