File size: 3,098 Bytes
b7d9967 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Utility functions for OperatorFlow"""
from qiskit.opflow.operator_base import OperatorBase
from qiskit.utils.deprecation import deprecate_func
@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/opflow_migration.",
)
def commutator(op_a: OperatorBase, op_b: OperatorBase) -> OperatorBase:
r"""
Deprecated: Compute commutator of `op_a` and `op_b`.
.. math::
AB - BA.
Args:
op_a: Operator A
op_b: Operator B
Returns:
OperatorBase: the commutator
"""
return (op_a @ op_b - op_b @ op_a).reduce()
@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/opflow_migration.",
)
def anti_commutator(op_a: OperatorBase, op_b: OperatorBase) -> OperatorBase:
r"""
Deprecated: Compute anti-commutator of `op_a` and `op_b`.
.. math::
AB + BA.
Args:
op_a: Operator A
op_b: Operator B
Returns:
OperatorBase: the anti-commutator
"""
return (op_a @ op_b + op_b @ op_a).reduce()
@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/opflow_migration.",
)
def double_commutator(
op_a: OperatorBase,
op_b: OperatorBase,
op_c: OperatorBase,
sign: bool = False,
) -> OperatorBase:
r"""
Deprecated: Compute symmetric double commutator of `op_a`, `op_b` and `op_c`.
See McWeeny chapter 13.6 Equation of motion methods (page 479)
If `sign` is `False`, it returns
.. math::
[[A, B], C]/2 + [A, [B, C]]/2
= (2ABC + 2CBA - BAC - CAB - ACB - BCA)/2.
If `sign` is `True`, it returns
.. math::
\lbrace[A, B], C\rbrace/2 + \lbrace A, [B, C]\rbrace/2
= (2ABC - 2CBA - BAC + CAB - ACB + BCA)/2.
Args:
op_a: Operator A
op_b: Operator B
op_c: Operator C
sign: False anti-commutes, True commutes
Returns:
OperatorBase: the double commutator
"""
sign_num = 1 if sign else -1
op_ab = op_a @ op_b
op_ba = op_b @ op_a
op_ac = op_a @ op_c
op_ca = op_c @ op_a
op_abc = op_ab @ op_c
op_cba = op_c @ op_ba
op_bac = op_ba @ op_c
op_cab = op_c @ op_ab
op_acb = op_ac @ op_b
op_bca = op_b @ op_ca
res = (
op_abc
- sign_num * op_cba
+ 0.5 * (-op_bac + sign_num * op_cab - op_acb + sign_num * op_bca)
)
return res.reduce()
|