示例#1
0
def retrieve_state(qcircuit):
    """Retrieve the state by qcircuit."""
    backend = Aer.get_backend('statevector_simulator')
    n_tot_qubit = qcircuit.n_qubits
    job = execute(qcircuit, backend)
    result = job.result()
    state = result.get_statevector(qcircuit)
    # qiskit's column-major order
    state_Qobj = Qobj(state, dims=[[2] * n_tot_qubit, [1]])
    # python's row-major order
    state_Qobj_rowmajor = state_Qobj.permute(np.arange(0, n_tot_qubit)[::-1])
    state_rowmajor = np.array(state_Qobj_rowmajor)[:, 0]

    return state_rowmajor
示例#2
0
def retrieve_unitary_matrix(qcircuit):
    """Retrieve the matrix block-encoded by qcircuit.
    
    Args: 
        qcircuit: qiskit circuit, n_tot_qubit 

    Returns:
        UA: n_tot_qubit matrix.
    """
    backend = Aer.get_backend('unitary_simulator')
    n_tot_qubit = qcircuit.n_qubits
    job = execute(qcircuit, backend)
    result = job.result()
    UA = result.get_unitary(qcircuit)
    # qiskit's column-major order
    UA_Qobj = Qobj(UA, dims=[[2] * n_tot_qubit, [2] * n_tot_qubit])
    # python's row-major order
    UA_Qobj_rowmajor = UA_Qobj.permute(np.arange(0, n_tot_qubit)[::-1])
    UA = np.array(UA_Qobj_rowmajor)

    return UA