Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Importing qualtran is very slow (~3.2s)

Open anurudhp opened this issue 1 year ago • 3 comments

import timeit

t = timeit.timeit('import qualtran', number=1)
print(t)

averages around 3.2s. Perhaps some dependency is causing this.

(Alternatively run python -m timeit -n 1 -r 1 "import qualtran")

anurudhp avatar May 13 '24 16:05 anurudhp

do you want to do some profiling to figure out what might be the cause?

mpharrigan avatar May 13 '24 17:05 mpharrigan

I ran python -X importtime -c "import qualtran" (after #949), it seems import cirq takes up most of the time:

import time: self [us] | cumulative | imported package
...
import time:      1377 |    1072314 |     cirq
import time:      4683 |    1076997 |   qualtran._infra.gate_with_registers
...
import time:       349 |    1564730 | qualtran

anurudhp avatar May 13 '24 19:05 anurudhp

It would be nice if we could defer importing cirq "as needed" as well. Ideally, this would only happen if you were using a bloq that wraps a cirq gate or uses cirq functionality somehow (or if using any of the cirq interop). It's blocked by the fact that GateWithRegisters is in the top-level namespace and descends from cirq.Gate.

mpharrigan avatar May 16 '24 20:05 mpharrigan