hybridlane.ops.qumode.TwoModeSum¶
- class hybridlane.ops.qumode.TwoModeSum(lambda_, wires, id=None)¶
Bases:
pennylane.operation.CVOperationTwo-mode summing gate \(SUM(\lambda)\)
This continuous-variable gate implements the unitary
\[SUM(\lambda) = \exp[\frac{\lambda}{2}(a + \ad)(b^\dagger - b)]\]where \(\lambda \in \mathbb{R}\) is a real parameter. The action on the wavefunction is given by
\[SUM(\lambda)\ket{x_a}\ket{x_b} = \ket{x_a}\ket{x_b + \lambda x_a}\]in the position basis (see Box III.6 of [1]).
- Parameters:
lambda_ (pennylane.typing.TensorLike)
wires (pennylane.wires.WiresLike)
id (str | None)
- num_params = 1¶
Number of trainable parameters that the operator depends on.
By default, this property returns as many parameters as were used for the operator creation. If the number of parameters for an operator subclass is fixed, this property can be overwritten to return the fixed value.
- Returns:
number of parameters
- Return type:
- num_wires = 2¶
Number of wires the operator acts on.
- ndim_params = (0,)¶
Number of dimensions per trainable parameter of the operator.
By default, this property returns the numbers of dimensions of the parameters used for the operator creation. If the parameter sizes for an operator subclass are fixed, this property can be overwritten to return the fixed value.
- Returns:
Number of dimensions for each trainable parameter.
- Return type:
- grad_method = 'F'¶
Gradient computation method.
'A': analytic differentiation using the parameter-shift method.'F': finite difference numerical differentiation.None: the operation may not be differentiated.
Default is
'F', orNoneif the Operation has zero parameters.
- resource_keys¶
The set of parameters that affects the resource requirement of the operator.
All decomposition rules for this operator class are expected to have a resource function that accepts keyword arguments that match these keys exactly. The
resource_rep()function will also expect keyword arguments that match these keys when called with this operator type.The default implementation is an empty set, which is suitable for most operators.
See also
resource_params()
- property resource_params¶
A dictionary containing the minimal information needed to compute a resource estimate of the operator’s decomposition.
The keys of this dictionary should match the
resource_keysattribute of the operator class. Two instances of the same operator type should have identicalresource_paramsiff their decompositions exhibit the same counts for each gate type, even if the individual gate parameters differ.Examples
The
MultiRZhas non-emptyresource_keys:>>> qml.MultiRZ.resource_keys {'num_wires'}
The
resource_paramsof an instance ofMultiRZwill contain the number of wires:>>> op = qml.MultiRZ(0.5, wires=[0, 1]) >>> op.resource_params {'num_wires': 2}
Note that another
MultiRZmay have different parameters but the sameresource_params:>>> op2 = qml.MultiRZ(0.7, wires=[1, 2]) >>> op2.resource_params {'num_wires': 2}
- adjoint()¶
Create an operation that is the adjoint of this one. Used to simplify
Adjointoperators constructed byadjoint().Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.
Operator.adjointcan be optionally defined by Operator developers, whileadjoint()is the entry point for constructing generic adjoint representations.- Returns:
The adjointed operation.
>>> class MyClass(qml.operation.Operator): ... ... def adjoint(self): ... return self ... >>> op = qml.adjoint(MyClass(wires=0)) >>> op Adjoint(MyClass(wires=[0])) >>> op.decomposition() [MyClass(wires=[0])] >>> op.simplify() MyClass(wires=[0])
- pow(z)¶
A list of new operators equal to this one raised to the given power. This method is used to simplify
Powinstances created bypow()orop ** power.Operator.powcan be optionally defined by Operator developers, whilepow()orop ** powerare the entry point for constructing generic powers to exponents.- Parameters:
z (float) – exponent for the operator
- Returns:
list[
Operator]
>>> class MyClass(qml.operation.Operator): ... ... def pow(self, z): ... return [MyClass(self.data[0]*z, self.wires)] ... >>> op = MyClass(0.5, 0) ** 2 >>> op MyClass(0.5, wires=[0])**2 >>> op.decomposition() [MyClass(1.0, wires=[0])] >>> op.simplify() MyClass(1.0, wires=[0])
- simplify()¶
Reduce the depth of nested operators to the minimum.
- Returns:
simplified operator
- Return type:
.Operator
- label(decimals=None, base_label=None, cache=None)¶
A customizable string representation of the operator.
- Parameters:
- Returns:
label to use in drawings
- Return type:
Example:
>>> op = qml.RX(1.23456, wires=0) >>> op.label() 'RX' >>> op.label(base_label="my_label") 'my_label' >>> op = qml.RX(1.23456, wires=0, id="test_data") >>> op.label() 'RX\n("test_data")' >>> op.label(decimals=2) 'RX\n(1.23,"test_data")' >>> op.label(base_label="my_label") 'my_label\n("test_data")' >>> op.label(decimals=2, base_label="my_label") 'my_label\n(1.23,"test_data")'
If the operation has a matrix-valued parameter and a cache dictionary is provided, unique matrices will be cached in the
'matrices'key list. The label will contain the index of the matrix in the'matrices'list.>>> op2 = qml.QubitUnitary(np.eye(2), wires=0) >>> cache = {'matrices': []} >>> op2.label(cache=cache) 'U\n(M0)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True)] >>> op3 = qml.QubitUnitary(np.eye(4), wires=(0,1)) >>> op3.label(cache=cache) 'U\n(M1)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True), tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], requires_grad=True)]