我正在尝试执行此简单操作
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
如何解决此问题?
答案 0 :(得分: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
以获得所需的输出。