# qiskit-nature accessing circuit

There are some very nice examples on how to handle circuits using qiskit.

However, once we get to the qiskit-nature documentation, it feels like a complete new world for the untrained eye.

I am running something similar to the "Sampling the potential energy surface" example, where the circuit concept may be well hidden below those higher level objects.

I would like to access a qiskit.QuantumCircuit-like object, from the example above mentioned, in order to retrieve its properties, for example, estimating the computational cost, finding the amount of required qubits, circuit depth...

My guess was, somewhere after the GroundStateEigensolver (6th code block), but I can't find any method or attribute around, that could help.

Any clues on how to achieve this?

• The tutorial you refer is using VQE as the quantum algorithm. An operator will be built from the molecule/problem and converted to a qubit operator using the qubit convertor. That will determine the number of qubits. As to the circuits that entirely down to how VQE is configured and it seems to be using its default ansatz since nothing is explicitly specified. So you want circuits its all really about VQE and its ansatz. The operator will determine the circuit width. How many circuits are run will depend on the backend and how the sum of paulis expectation is computed. Aug 26, 2022 at 17:25
• Thanks @SteveWood! That definitely points me on the right direction. Aug 26, 2022 at 17:34

So far, I managed to access at least the "register length" (number of required qubits).

In basic circuit examples with qiskit we usually create circuits with a given register length.

With qiskit-nature, we don't interact directly with the circuits. Instead, we use higher level objects, which internally use handle those circuits.

As Steve Wood commented, the size of the register (amount of qubits) can be obtained after converting the problem into a binary operator.

In the example for sampling the PES above mentioned, in the 6th code block, the electronic structure problem (es_problem) is defined. From that one, we can obtain the second quantization operators by calling the second_q_ops() method. One of those operators (the one behind the key 'ElectronicEnergy') is the Hamiltonian, which contains the size of the register.

In code form:

...
second_q_op = es_problem.second_q_ops()
hamiltonian = second_q_op['ElectronicEnergy']
print(f'{hamiltonian.register_length} qbits used')


Update (June 2023):

Apparently, on qiskit nature version 0.6.2 this approach does not work anymore. Instead, the register length could be obtained by:

...
rl = es_problem.hamiltonian.electronic_integrals.register_length
print(f'{rl} qbits used')