vector package provides the Vector type — a dense slice of complex128 values used to represent quantum state amplitudes. The q simulator builds its state vector from this type and applies gate matrices to it via Apply.
Most users interact with qubits through the Q simulator rather than the
Vector type directly. You only need this package when working with low-level state manipulation or building utilities on top of the simulator internals.Creating vectors
New
Vector from the given complex128 values.
Zero
n with all elements set to 0+0i.
Methods
Clone
v. Modifying the clone does not affect the original.
Dual
z becomes conj(z). Used internally when computing inner and outer products.
Mul
z.
Apply
m|v⟩. This is how quantum gates are applied to a state vector.
InnerProduct
⟨w|v⟩ — the inner product of v with w. Computed as Σ vᵢ · conj(wᵢ).
OuterProduct
|v⟩⟨w| — the outer product of v and w as a *matrix.Matrix. The result has len(v.Data) rows and len(w.Data) columns.
TensorProduct
v ⊗ w. For vectors of lengths p and q, the result has length p·q.
Equal
true if v and w have the same length and every pair of elements is within tolerance. Default tolerances come from the epsilon package (AbsTol = 1e-8, RelTol = 1e-5).
Real / Imag
[]float64.
String
Package-level helpers
TensorProductN
v ⊗ v ⊗ ... ⊗ v (n times). If n is omitted, returns v unchanged.
InnerProduct vs OuterProduct
InnerProduct vs OuterProduct
| Operation | Call | Result type | Meaning |
|---|---|---|---|
| Inner product | v.InnerProduct(w) | complex128 | ⟨w|v⟩ — scalar overlap |
| Outer product | v.OuterProduct(w) | *matrix.Matrix | |v⟩⟨w| — rank-1 matrix |
|ψ⟩, ψ.OuterProduct(ψ) gives the density matrix of the pure state.Relationship to the simulator state vector
Relationship to the simulator state vector
The
q simulator stores the full quantum state as a Vector internally. When you call qsim.H(q0) or any other gate method, the simulator constructs the appropriate matrix and calls Apply on the state vector.You can inspect the amplitudes after a simulation run through qsim.State() rather than accessing the vector directly.