3
$\begingroup$

I'm trying to use the .compose() method to join two parametrized circuits, specifically TwoLocal instances from the qiskit.circuit.library.

While I would expect that .num_parameters_settable() would be the sum of the parameters in each circuit, the final circuit will have only as many settable parameters as only one of them.

Version: qiskit-0.26.2

Thank you very much for your help!

My code is:

from qiskit.circuit.library import TwoLocal
import numpy as np

    rot = TwoLocal(
        int(np.sum(num_qubits)),
        "ry",
        [],
        reps=1,
        skip_final_rotation_layer=True,
        parameter_prefix="p",
    )

    var = TwoLocal(
            int(np.sum(num_qubits)),
            "ry",
            "cx",
            entanglement="linear",
            reps=1,
            skip_final_rotation_layer=True,
        )
    rot.num_parameters_settable()
    >> 2
    rot.compose(var, inplace=True)
    rot.num_parameters_settable()
    >> 2
$\endgroup$
3
$\begingroup$

Looking at the documentation for TwoLocal, you can see that .num_parameters_settable refers to the number of parameters originally available in the circuit.

Documentation for num_parameters_settable

However, .num_parameters will give you what you are looking for. I tried it with your code setting num_qubits=2 and it indeed works as you want. This property is defined as:

enter image description here

Meaning that it actually updates when an action like .compose() is made on the circuit.

$\endgroup$

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.