Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPS sudden performance degradation on measure #619

Closed
merav-aharoni opened this issue Feb 18, 2020 · 3 comments
Closed

MPS sudden performance degradation on measure #619

merav-aharoni opened this issue Feb 18, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@merav-aharoni
Copy link
Contributor

Informations

  • Qiskit Aer version: 0.14
  • Python version:
  • Operating system: Linux

What is the current behavior?

Since Qiskit version 0.14, measurement in MPS is very slow.

Steps to reproduce the problem

import qiskit
n = 25 
circ = qiskit.QuantumCircuit(n, n)
circ.measure(range(n), range(n))
sim = qiskit.Aer.get_backend('qasm_simulator')
res = qiskit.execute(circ, sim, shots=100, backend_options={'method': "statevector"}).result()
print("qasm time " + str(res.time_taken))
res = qiskit.execute(circ, sim, shots=100, backend_options={"method": "matrix_product_state", "fusion_enable":False }).result()
print("mps time " + str(res.time_taken)) 

Results:

qasm time 0.3851964473724365
mps time 32.857303857803345

The run-time depends on the number of shots. When I run 1000 shots, time goes up to 300 sec!

What is the expected behavior?

Up to Qiskit 0.13.0, this circuit ran in less than 1 second.

Suggested solutions

Did anything in Aer change that could cause this problem?
Note that I disabled fusion, to make sure that is not causing the problem.

@merav-aharoni merav-aharoni added the bug Something isn't working label Feb 18, 2020
@merav-aharoni
Copy link
Contributor Author

This appears to be a bug in parallelization. When I remove the #pragma omp parallel for collapse(2) in the function MPS_Tensor::contract_2_dimensions, the performance on this tests goes down from 18 sec to 0.5 sec. @atilag , can you check what changed in the parallelization? adding also @yaelbh to this thread.

@chriseclectic
Copy link
Member

chriseclectic commented Feb 24, 2020

@merav-aharoni I would recommend adding OMP conditions like we use in the statevector and density matrix simulators.

The QubitVector class has the following on all its pragmas:

#pragma omp parallel for if (num_qubits_ > omp_threshold_ && omp_threads_ > 1) num_threads(omp_threads_)

The omp_threshold_ parameter can be set using config options, and a default value should be set based on your profiling of when it is beneficial to use multithreading (at the moment use 14 qubits by default for qubitvector/statevector_state).

@chriseclectic
Copy link
Member

Closed by #638

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants