Skip to main content
added 17 characters in body
Source Link
hft
  • 903
  • 3
  • 13

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the ascii art TextDrawing (ascii art) representation of the same circuit, the number of "layers" (or "columns" in the updated question) corresponds to the number of nodes. Here is a function that will return the number of "layers" (or "columns") shown in the diagram:

def num_layers(qc):
    return len(qc.draw(output='text').nodes)

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the ascii art TextDrawing of the same circuit, the number of "layers" (or "columns" in the updated question) corresponds to the number of nodes. Here is a function that will return the number of "layers" (or "columns") shown in the diagram:

def num_layers(qc):
    return len(qc.draw(output='text').nodes)

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the TextDrawing (ascii art) representation of the same circuit, the number of "layers" (or "columns" in the updated question) corresponds to the number of nodes. Here is a function that will return the number of "layers" (or "columns") shown in the diagram:

def num_layers(qc):
    return len(qc.draw(output='text').nodes)
added 52 characters in body
Source Link
hft
  • 903
  • 3
  • 13

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the ascii art TextDrawing of the same circuit, the number of "layers" (or "columns" in the updated question) corresponds to the number of nodes. Here is a function that will return the number of layers"layers" (or "columns") shown in the diagram.:

def num_layers(qc):
    return len(qc.draw(output='text').nodes)

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the ascii art TextDrawing of the same circuit, the number of "layers" corresponds to the number of nodes. Here is a function that will return the number of layers shown in the diagram.

def num_layers(qc):
    return len(qc.draw(output='text').nodes)

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the ascii art TextDrawing of the same circuit, the number of "layers" (or "columns" in the updated question) corresponds to the number of nodes. Here is a function that will return the number of "layers" (or "columns") shown in the diagram:

def num_layers(qc):
    return len(qc.draw(output='text').nodes)
Source Link
hft
  • 903
  • 3
  • 13

I would like to compute the number of layers in a Qiskit QuantumCircuit. To be clear about what I mean by number of layers, consider the following circuit as an example:

from qiskit.circuit.random import random_circuit

qc = random_circuit(4, 3, seed=0)
qc.draw('mpl')

enter image description here

In this case, I would expect number of layers = 5 ...

In the ascii art TextDrawing of the same circuit, the number of "layers" corresponds to the number of nodes. Here is a function that will return the number of layers shown in the diagram.

def num_layers(qc):
    return len(qc.draw(output='text').nodes)