HGenerator.py 1.2 KB
Newer Older
Q
Quleaf 已提交
1 2
# !/usr/bin/env python3
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
Q
Quleaf 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15
#
# 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.

Q
Quleaf 已提交
16
r"""
Q
Quleaf 已提交
17 18 19
HGenerator
"""

Q
Quleaf 已提交
20
import numpy
Q
Quleaf 已提交
21
import scipy
Q
Quleaf 已提交
22
import scipy.stats
Q
Quleaf 已提交
23

Q
Quleaf 已提交
24
SEED = 13
Q
Quleaf 已提交
25 26 27 28 29

__all__ = ["generate_rho_sigma", ]


def generate_rho_sigma():
Q
Quleaf 已提交
30 31 32
    numpy.random.seed(SEED)
    V = scipy.stats.unitary_group.rvs(4)  # Generate a random unitary matrix
    D = numpy.diag([0.5, 0.3, 0.1, 0.1])  # Input the spectrum of the target state rho
Q
Quleaf 已提交
33
    V_H = V.conj().T
Q
Quleaf 已提交
34 35
    rho = V @ D @ V_H  # Generate rho
    # print(rho)  # Print quantum state rho
Q
Quleaf 已提交
36

Q
Quleaf 已提交
37
    # Input the quantum state sigma
Q
Quleaf 已提交
38
    sigma = numpy.diag([0.1, 0.2, 0.3, 0.4])
Q
Quleaf 已提交
39
    return rho, sigma