Skip to content

Conversation

aaryav-3
Copy link

@aaryav-3 aaryav-3 commented Aug 29, 2025

Summary

This PR fixes GitHub issue #14726 by ensuring that matrix multiplication using the @ operator on quantum states does not cause problems with output dimensions or data types.


Checklist

  • I have added the tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Details and Comments

This change introduces a method implementing the __rmatmul__ magic function within QuantumState, allowing these operations to be handled separately and preventing unexpected type or dimension issues.

@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Aug 29, 2025
@CLAassistant
Copy link

CLAassistant commented Aug 29, 2025

CLA assistant check
All committers have signed the CLA.

@aaryav-3 aaryav-3 force-pushed the fix-operator-quantumstate-mul branch from f9bae63 to be730a3 Compare August 29, 2025 07:28
@aaryav-3 aaryav-3 marked this pull request as ready for review September 3, 2025 05:41
@aaryav-3 aaryav-3 requested a review from a team as a code owner September 3, 2025 05:41
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@eliarbel eliarbel removed the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Sep 3, 2025
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Thanks for having a look, I left some comments below.

ret._op_shape = self._op_shape.transpose()
return ret

def compose(self, other: Operator, qargs: list | None = None, front: bool = False) -> Operator:
Copy link
Contributor

Choose a reason for hiding this comment

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

The argument front is not handled right now. I would suggest we just raise an error if this is True and the input is a Statevector.

If $\langle\psi| O$ style multiplication is desired in the future we can still add it, but given that we don't really have a representation of a bra vector I wouldn't open this can of worms here.

Copy link
Author

@aaryav-3 aaryav-3 Sep 8, 2025

Choose a reason for hiding this comment

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

Thank you for your comments. I’ve handled this with an exception, and since thedot()method sets front=True, I updated group.py to handle the statevector dot product as a special case. I’d love to hear your opinion on this approach.
Apologies for the delayed reply — I had drafted this earlier but only just realized I hadn’t sent it.

@coveralls
Copy link

coveralls commented Sep 16, 2025

Pull Request Test Coverage Report for Build 17762403317

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 2 files are covered.
  • 14 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.004%) to 88.292%

Files with Coverage Reduction New Missed Lines %
crates/circuit/src/parameter/parameter_expression.rs 1 82.79%
crates/qasm2/src/expr.rs 1 93.63%
crates/transpiler/src/passes/gate_direction.rs 1 96.3%
crates/qasm2/src/lex.rs 5 91.75%
crates/qasm2/src/parse.rs 6 96.62%
Totals Coverage Status
Change from base Build 17755812814: 0.004%
Covered Lines: 92738
Relevant Lines: 105036

💛 - Coveralls

@ShellyGarion ShellyGarion added the mod: quantum info Related to the Quantum Info module (States & Operators) label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: quantum info Related to the Quantum Info module (States & Operators)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants