mindquantum.core.operators.count_qubits

View Source On Gitee
mindquantum.core.operators.count_qubits(operator)[source]

Calculate the number of qubits on which operator acts before removing the unused qubit.

Note

In some case, we need to remove the unused index.

Parameters

operator (Union[FermionOperator, QubitOperator, QubitExcitationOperator]) – FermionOperator or QubitOperator or QubitExcitationOperator.

Returns

int, The minimum number of qubits on which operator acts.

Raises

TypeError – Operator of invalid type.

Examples

>>> from mindquantum.core.operators import QubitOperator,FermionOperator, count_qubits
>>> qubit_op = QubitOperator("X1 Y2")
>>> count_qubits(qubit_op)
3
>>> fer_op = FermionOperator("1^")
>>> count_qubits(fer_op)
2