1
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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
qc = QuantumCircuit(*qregs)
qc.initialize([0,1], 0)         # You need to specify the qubits to act on
overall_circ = qc + eigs_circ

The method for appending two circuits is here

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ The line qc = QuantumCircuit(qregs) throws the error message AttributeError: 'list' object has no attribute 'name'. Nevertheless, qc = QuantumCircuit(*qregs) does the trick. $\endgroup$ – NikPapadopoulos Feb 8 at 20:42
  • $\begingroup$ @NikPapadopoulos I'm glad this worked for you, I have updated the original answer with your correction - thanks! $\endgroup$ – met927 Feb 10 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.