Is there a way that can obtain sparse matrix of quantum circuit? I used to check my quantum circuit with quantum_info.Operator, but for large number of qubits, it is difficult because of the memory allocation limit. Is it available in qiskit? or should I build elementary gates in sparse matrix format? Thank you!

  • $\begingroup$ What do you mean by irrelevant? $\endgroup$ Dec 8, 2020 at 0:54
  • $\begingroup$ Sorry, I misused the word. I mean the quantum circuit cannot be converted to matrix because of the large size of matrix. $\endgroup$
    – Jin
    Dec 8, 2020 at 1:48
  • $\begingroup$ As an extreme example consider $H^{\otimes n}$. $\endgroup$
    – AHusain
    Dec 8, 2020 at 2:41

1 Answer 1


There are classes for Operators, States, Channels, Measures, Randomness, Analysis and Synthesis in Quantum Information ( qiskit.quantum_info ).

There is a specific class called SparsePauliOp. It is constructed as a Sparse N-qubit operator in a Pauli basis representation. It seems to be using SciPy internally for creating the sparse matrix. It can be used for performing operator arithmetic for hundred of qubits if the number of non-zero Pauli basis terms is sufficiently small. Please find further details here in the Qiskit Terra API specifications. Qiskit Aqua as has a class called Matrix Operator where we can pass a Sparse Matrix. Please find further details here in the Qiskit Aqua API specifications.

  • $\begingroup$ Thank you for your comment. Then 2-qubit gates (ex. CNOT) can be built by the classes that you recommended? $\endgroup$
    – Jin
    Dec 8, 2020 at 4:13
  • $\begingroup$ You could use qiskit.quantum_info.two_qubit_cnot_decompose. Please find the details here - qiskit.org/documentation/stubs/… $\endgroup$
    – Gokul Alex
    Dec 8, 2020 at 4:47

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.