Skip to content

Commit

Permalink
examples for num_ancillas and num_clbits
Browse files Browse the repository at this point in the history
  • Loading branch information
abbycross committed Dec 12, 2024
1 parent 25c67a3 commit 4d738b6
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,8 @@ def op_start_times(self) -> list[int]:
# Transpile the circuit with a specific basis gates list and print the resulting circuit
backend = GenericBackendV2(2, basis_gates=['u1', 'u2', 'u3', 'cx'])
pm = generate_preset_pass_manager(optimization_level=1, backend=backend, scheduling_method='alap')
pm = generate_preset_pass_manager(optimization_level=1,
backend=backend, scheduling_method='alap')
transpiled_qc = pm.run(qc)
print("Transpiled circuit with basis gates ['u1', 'u2', 'u3', 'cx']:")
print(transpiled_qc)
Expand Down Expand Up @@ -3820,12 +3821,63 @@ def num_qubits(self) -> int:

@property
def num_ancillas(self) -> int:
"""Return the number of ancilla qubits."""
"""Return the number of ancilla qubits.
Example:
.. plot::
:include-source:
:nofigs:
from qiskit import QuantumCircuit, QuantumRegister, AncillaRegister
# Create a 2-qubit quantum circuit
reg = QuantumRegister(2)
qc = QuantumCircuit(reg)
# Create an ancilla register with 1 qubit
anc = AncillaRegister(1)
qc.add_register(anc) # Add the ancilla register to the circuit
print("Number of ancilla qubits:")
print(qc.num_ancillas)
.. code-block:: text
Number of ancilla qubits:
1
"""
return len(self.ancillas)

@property
def num_clbits(self) -> int:
"""Return number of classical bits."""
"""Return number of classical bits.
Example:
.. plot::
:include-source:
:nofigs:
from qiskit import QuantumCircuit
# Create a new circuit with two qubits and one classical bit
qc = QuantumCircuit(2, 1)
# Add a Hadamard gate to qubit 0
qc.h(0)
# Perform a controlled-X gate on qubit 1, controlled by qubit 0
qc.cx(0, 1)
print("Number of classical bits:")
print(qc.num_clbits)
"""
return self._data.num_clbits

# The stringified return type is because OrderedDict can't be subscripted before Python 3.9, and
Expand Down

0 comments on commit 4d738b6

Please sign in to comment.