Skip to content

MPI support for state and expectation calculations - #135

Open
Vinitha-balachandran wants to merge 6 commits into
mainfrom
mpi_support_quimb
Open

MPI support for state and expectation calculations#135
Vinitha-balachandran wants to merge 6 commits into
mainfrom
mpi_support_quimb

Conversation

@Vinitha-balachandran

Copy link
Copy Markdown
Contributor

Added mpi support in quimb

@Tankya2
Tankya2 requested a review from a team April 10, 2026 09:48
Comment on lines +196 to +202
if self.rank > 0:
state = np.array(0)

if return_array:
statevector = state.flatten() if self.rank == 0 else state
else:
statevector = state if self.rank == 0 else state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-root ranks return np.array(0) which is an ambiguous scalar value.

Suggested change
if self.rank > 0:
state = np.array(0)
if return_array:
statevector = state.flatten() if self.rank == 0 else state
else:
statevector = state if self.rank == 0 else state
if self.rank == 0:
statevector = state.flatten() if return_array else state
else:
statevector = None

Comment thread src/qibotn/backends/quimb.py Outdated
coeff = coeff.real

target_size = int(2**nqubits / comm.size)
opt = ctg.ReusableHyperOptimizer(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this outside the loop and then use the opt object? If you reuse it it will discard cached results.

Comment thread src/qibotn/backends/quimb.py Outdated
Comment on lines +582 to +585
op_str = opstr.lower()
ops = qu.pauli(op_str[0])
for c in op_str[1:]:
ops = ops & qu.pauli(c)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can reuse this function?

Suggested change
op_str = opstr.lower()
ops = qu.pauli(op_str[0])
for c in op_str[1:]:
ops = ops & qu.pauli(c)
ops = _string_to_quimb_operator(opstr)

Comment thread src/qibotn/backends/quimb.py Outdated
circ.apply_gate(
quimb_gate_name,
*params,
*qubits,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*qubits,
*qubits,
parametrize=is_parametrized,

@scarrazza scarrazza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Vinitha-balachandran, could you please add a tests for the two new MPI functions?

Comment thread src/qibotn/backends/quimb.py Outdated


def dense_vector_tn_mpi_qu(
qasm: str, nqubits, initial_state, mps_opts, backend="numpy"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest including a final arg with optimizer options so we avoid hardcoding values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scarrazza Thanks Stefano for the suggestions, I have addressed them all in the new commit. Also, added two pytests for the new functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants