QuTiP TypeError: Incompatible Qobj shapes with tensor product

痴心易碎 提交于 2019-12-24 09:59:19

问题


I am trying to perform this simple operation

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

but i got

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

I am using Anaconda in Ubuntu 14.04LTS x64.

~$ 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

How to solve this issue?


回答1:


I think I know what's causing the issue in your case.

Let's begin by looking at the operator that you specify.

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

What this tells you is that that you basically have four quantum gates that act on four individual qubits. The first two gates is Hadamard gates that act on the first two qubits and then you have the Identity which does nothing to the two second qubits.

when you write basis(16,1) QuTiP basically interprets this as one qubit that lives in a Hilbert space with 16 dimensions instead of the tensor product of four qubits.

To solve your problem you should instead specify your ket vector as tensor product of four qubits.

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

Then you write a*b to get the output that you desire.



来源:https://stackoverflow.com/questions/51179989/qutip-typeerror-incompatible-qobj-shapes-with-tensor-product

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!