# Prepending initial state to a quantum circuit in Qiskit

I am trying to generate a Quantum Phase Estimation (QPE) circuit in QISKIT the following way.

1 - First, I generate a QPE circuit with the following code:

### building inverse quantum fourier transform circuit
iqft = StandardIQFTS(2)
iqft_circ = QuantumCircuit(QuantumRegister(2))
iqft.construct_circuit(mode='circuit', qubits=iqft_circ.qubits, circuit=iqft_circ, do_swaps=True)

### Defining matrix operator
matrix = np.array([[1,0],[0,np.exp(1j*np.pi/4)]])

### Defining Quantum Phase Estimation object
eigs_qpe = EigsQPE(MatrixOperator(matrix=matrix),
iqft,
num_time_slices=2,
num_ancillae=2,
expansion_mode='trotter',
expansion_order=1,
evo_time=2,
negative_evals=False,
ne_qfts=[None,None])

### Generating circuit
eigs_circ = eigs_qpe.construct_circuit(mode="circuit")
eigs_circ.draw(output="mpl")


2 - Then I want to prepend the following initial state to the previous circuit

vector = np.array([0,1])
initial_state = Custom(1,state_vector=vector)


Thus getting a QPE computed on the initial_state. Is it possible to do this, for example by accessing eigs_circ.data and prepending the proper gates that generate the initial_state?

If you have the circuit, you can get the registers the circuit acts on from eigs_circ.qregs. You can then create another circuit using the returned quantum register, add an instruction to it (initialize) and then add these two circuits together. Your final code should look something like
qregs = eigs_circ.qregs         # NB this is a list

• The line qc = QuantumCircuit(qregs) throws the error message AttributeError: 'list' object has no attribute 'name'. Nevertheless, qc = QuantumCircuit(*qregs) does the trick. Feb 8 '20 at 20:42