0
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – Steve Wood
    Aug 26, 2022 at 17:25
  • $\begingroup$ Thanks @SteveWood! That definitely points me on the right direction. $\endgroup$ Aug 26, 2022 at 17:34

1 Answer 1

1
$\begingroup$

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')
$\endgroup$
1
  • $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Sep 2, 2022 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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