main.py 1.5 KB
Newer Older
Q
Quleaf 已提交
1
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
Q
Quleaf 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
main
"""

Q
Quleaf 已提交
19 20 21
import scipy
from numpy import trace as np_trace
from paddle_quantum.utils import pauli_str_to_matrix
Q
Quleaf 已提交
22 23 24 25
from paddle_quantum.GIBBS.Paddle_GIBBS import Paddle_GIBBS


def main():
Q
Quleaf 已提交
26
    # Generate Pauli string representing a specific Hamiltonian
Q
Quleaf 已提交
27 28
    H = [[-1.0, 'z0,z1'], [-1.0, 'z1,z2'], [-1.0, 'z0,z2']]

Q
Quleaf 已提交
29
    # Generate the matrix form of the Hamiltonian
Q
Quleaf 已提交
30
    N_SYS_B = 3  # Number of qubits in subsystem B used to generate Gibbs state
Q
Quleaf 已提交
31 32
    hamiltonian = pauli_str_to_matrix(H, N_SYS_B)

Q
Quleaf 已提交
33 34
    # Generate the target Gibbs state rho
    beta = 1.5  # Set inverse temperature beta
Q
Quleaf 已提交
35 36
    rho_G = scipy.linalg.expm(-1 * beta * hamiltonian) / np_trace(scipy.linalg.expm(-1 * beta * hamiltonian))

Q
Quleaf 已提交
37
    # Convert to the data type supported by Paddle Quantum
Q
Quleaf 已提交
38 39 40 41
    hamiltonian = hamiltonian.astype("complex128")
    rho_G = rho_G.astype("complex128")

    rho_B = Paddle_GIBBS(hamiltonian, rho_G)
Q
Quleaf 已提交
42 43 44 45 46
    print(rho_B)


if __name__ == '__main__':
    main()