Is your feature request related to a use case or problem?
Gemini Code Assist reported the following for linear_qubit_operator.py. This looks simple enough to do, but it should be checked for correctness, and some kind of unit tests should be added to go along with this.
Performance/Memory Overhead in Single-Process Path (Lines 189-190):
Using functools.reduce(numpy.add, ...) creates $N-1$ intermediate numpy arrays, where $N$ is the number of operators. For large state vectors, this causes significant memory churn and garbage collection overhead.
Fix:
Initialize a single zero array and accumulate the results in-place using += as suggested below.
if self.options.processes <= 1:
res = numpy.zeros(x.shape, dtype=complex)
for operator in self.linear_operators:
res += operator * x
return res
Originally posted by @gemini-code-assist[bot] in #1404 (comment)
What solution or approach do you envision?
GCA's suggestion should be implemented and tested.
How urgent is this for you?
P3 – not blocked; it's an idea
Is your feature request related to a use case or problem?
Gemini Code Assist reported the following for linear_qubit_operator.py. This looks simple enough to do, but it should be checked for correctness, and some kind of unit tests should be added to go along with this.
Performance/Memory Overhead in Single-Process Path (Lines 189-190):
Using$N-1$ intermediate numpy arrays, where $N$ is the number of operators. For large state vectors, this causes significant memory churn and garbage collection overhead.
functools.reduce(numpy.add, ...)createsFix:
Initialize a single zero array and accumulate the results in-place using
+=as suggested below.Originally posted by @gemini-code-assist[bot] in #1404 (comment)
What solution or approach do you envision?
GCA's suggestion should be implemented and tested.
How urgent is this for you?
P3 – not blocked; it's an idea