1

我正在尝试执行这个简单的操作

tensor(hadamard_transform(1), hadamard_transform(1), identity(2), identity(2)) * basis(16,1)

但我得到了

Traceback (most recent call last):

  File "<ipython-input-163-ae66af2f799c>", line 1, in <module>
    tensor(hadamard_transform(1), hadamard_transform(1), identity(2), identity(2)) * basis(16,1)

  File "/home/abdallaessam/anaconda2/envs/Quantum/lib/python2.7/site-packages/qutip/qobj.py", line 515, in __mul__
    raise TypeError("Incompatible Qobj shapes")

TypeError: Incompatible Qobj shapes

我在 Ubuntu 14.04LTS x64 中使用 Anaconda。

~$ conda info

     active environment : Quantum
    active env location : /home/user/anaconda2/envs/Quantum
            shell level : 1
       user config file : /home/user/.condarc
 populated config files : /home/user/.condarc
          conda version : 4.5.4
    conda-build version : 3.10.5
         python version : 2.7.15.final.0
       base environment : /home/user/anaconda2  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/linux-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/linux-64
                          https://repo.anaconda.com/pkgs/pro/noarch
                          https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/user/anaconda2/pkgs
                          /home/user/.conda/pkgs
       envs directories : /home/user/anaconda2/envs
                          /home/user/.conda/envs
               platform : linux-64
             user-agent : conda/4.5.4 requests/2.18.4 CPython/2.7.15 Linux/3.13.0-141-generic ubuntu/14.04 glibc/2.19
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False


>>> from qutip import *
>>> about()

QuTiP: Quantum Toolbox in Python
Copyright (c) 2011 and later.
A. J. Pitchford, P. D. Nation, R. J. Johansson, A. Grimsmo, and C. Granade

QuTiP Version:      4.2.0
Numpy Version:      1.13.3
Scipy Version:      1.1.0
Cython Version:     0.28.3
Matplotlib Version: 2.2.2
Python Version:     2.7.15
Number of CPUs:     2
BLAS Info:          INTEL MKL
OPENMP Installed:   False
INTEL MKL Ext:      True
Platform Info:      Linux (x86_64)
Installation path:  /home/user/anaconda2/envs/Quantum/lib/python2.7/site-packages/qutip

如何解决这个问题?

4

1 回答 1

1

我想我知道是什么导致了您的问题。

让我们从查看您指定的运算符开始。

a = tensor(hadamard_transform(1), hadamard_transform(1), identity(2), identity(2))

这告诉你的是,你基本上有四个量子门,它们作用于四个单独的量子比特。前两个门是 Hadamard 门,它作用于前两个量子位,然后你拥有对第二个量子位没有任何作用的身份。

当您编写basis(16,1)QuTiP 时,基本上将其解释为一个存在于 16 维希尔伯特空间中的量子比特,而不是四个量子比特的张量积。

要解决您的问题,您应该将 ket 向量指定为四个量子位的张量积。

b = tensor([basis(2,0), basis(2,0), basis(2,0), basis(2,1)])

然后你写a*b得到你想要的输出。

于 2018-07-05T12:31:00.067 回答