hybridlane.ops.functions¶
Functions¶
|
Compute the matrix representation in the Fock basis. |
Package Contents¶
- hybridlane.ops.functions.fock_matrix(op: Callable | type[Operator] | Sequence[Operator] | QuantumScript, wire_order: pennylane.wires.WiresLike | None = None, wire_dims: Mapping[Any, int] | None = None) Callable[Ellipsis, TransformOutput][source]¶
- hybridlane.ops.functions.fock_matrix(op: Operator | PauliWord | PauliSentence, wire_order: pennylane.wires.WiresLike | None = None, wire_dims: Mapping[Any, int] | None = None) pennylane.typing.TensorLike
Compute the matrix representation in the Fock basis.
Like
matrix(), this transform can be applied to many types including operators, tapes, and quantum functions. It differs from the original by also requiring awire_dimsargument, which is a mapping of wire labels to their corresponding Hilbert space dimensions.- Parameters:
op – The operator, tape, or quantum function to compute the matrix representation of.
wire_order – The order of the wires in the resulting matrix
wire_dims – A mapping of wire labels to their corresponding Hilbert space dimensions.
- Returns:
If
opis an operator, it returns the matrix. Otherwise, it acts like a transform
See also
Example
It can be used to create a new function that returns the matrix of a quantum function.
def test_fn(theta): qp.X(0) hl.CR(theta, wires=(0, 1)) qp.X(0) return hl.expval(hl.N(1))
>>> matrix_fn = hl.fock_matrix(test_fn, wire_order=(0, 1), wire_dims={0: 2, 1: 3}) >>> matrix_fn(0.123) array([[1. +0.j , 0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ], [0. +0.j , 0.9981+0.0615j, 0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ], [0. +0.j , 0. +0.j , 0.9924+0.1227j, 0. +0.j , 0. +0.j , 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 1. +0.j , 0. +0.j , 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j , 0.9981-0.0615j, 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j , 0.9924-0.1227j]])
It can obtain the matrix for a single operator:
>>> hl.fock_matrix(hl.K(0.123, wires=0), wire_dims={0: 4}) array([[1. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ], [0. +0.j , 0.9924-0.1227j, 0. +0.j , 0. +0.j ], [0. +0.j , 0. +0.j , 0.8814-0.4724j, 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 0.4473-0.8944j]])
Like
qp.matrix, this can also be done in a functional form:>>> hl.fock_matrix(hl.K, wire_dims={0: 4}, wire_order=[0])(0.123, wires=0) array([[1. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ], [0. +0.j , 0.9924-0.1227j, 0. +0.j , 0. +0.j ], [0. +0.j , 0. +0.j , 0.8814-0.4724j, 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 0.4473-0.8944j]])