QuantumComputer.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:QuantumComputing 作者: corbett 项目源码 文件源码
def separate_state(qubit_state):
        """This only works if the state is fully separable at present

        Throws exception if not a separable state"""
        n_entangled=QuantumRegister.num_qubits(qubit_state)
        if list(qubit_state.flat).count(1)==1:
            separated_state=[]
            idx_state=list(qubit_state.flat).index(1)
            add_factor=0
            size=qubit_state.shape[0]
            while(len(separated_state)<n_entangled):
                size=size/2
                if idx_state<(add_factor+size):
                    separated_state+=[State.zero_state]
                    add_factor+=0
                else:
                    separated_state+=[State.one_state]
                    add_factor+=size
            return separated_state
        else:
            # Try a few naive separations before giving up
            cardinal_states=[State.zero_state,State.one_state,State.plus_state,State.minus_state,State.plusi_state,State.minusi_state]
            for separated_state in itertools.product(cardinal_states, repeat=n_entangled):
                candidate_state=reduce(lambda x,y:np.kron(x,y),separated_state)
                if np.allclose(candidate_state,qubit_state):
                    return separated_state
            # TODO: more general separation methods
            raise StateNotSeparableException("TODO: Entangled qubits not represented yet in quantum computer implementation. Can currently do manual calculations; see TestBellState for Examples")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号