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

Separate the gate definition from the QubitCircuit.propagators method #83

Merged
merged 2 commits into from
Aug 3, 2021

Conversation

BoxiLi
Copy link
Member

@BoxiLi BoxiLi commented Jul 24, 2021

Changes

  • Merge the duplicated QubitCircuit.propagators methods.
  • Move the definition for gate operators to the Gate class: one method defining the compact gate operator as Qobj, while the other one expands it to the full Hilbert space. This makes it easier to define subclasses for each gate later.
  • Rename a previously undocumented QubitCircuit.get_inds method to get_all_qubits and add documentation. It was added recently but never documented.

There are two new method for Gate: get_qobj and get_compact_qobj. Although they could be merged to one, I made them two different methods because if for custom gate, I wish that the user only need to define get_compact_qobj, without having to consider permutation and expanding etc. And in get_qobj, we take care of that.

The special case is the global phase gate. Currently, in propagators it always gives a matrix with the full dimension. However, it should be treated as just a complex number, which is more efficient. I suspect that in the circuit simulation with precomputed unitaries the global phase gate is not properly handled. But I will leave this for another PR.

**Changes**
- Merge the duplicated `QubitCircuit.propagators` methods.
- Move the definition for gate operators to the `Gate` class: one method defining the compact gate operator as Qobj, while the other one expands it to the full Hilbert space. This makes it easier to define subclasses for each gate later.
- Rename a previously undocumented `QubitCircuit.get_inds` method to `get_all_qubits` and add documentation. It was added recently but never documented.
Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

I left some questions, but this looks great as a first step.

src/qutip_qip/circuit.py Show resolved Hide resolved
src/qutip_qip/circuit.py Outdated Show resolved Hide resolved
src/qutip_qip/circuit.py Show resolved Hide resolved
@BoxiLi BoxiLi changed the title Separate the gate definition from the propagators Separate the gate definition from the QubitCircuit.propagators method Aug 3, 2021
@BoxiLi
Copy link
Member Author

BoxiLi commented Aug 3, 2021

Hmmm, I understand that code climate does not like 20 if-else, neither do I. But let's leave it to another PR.

@hodgestar
Copy link
Contributor

Still approved!

@BoxiLi BoxiLi merged commit 8b49a89 into qutip:master Aug 3, 2021
@BoxiLi BoxiLi added this to the qutip-qip-0.2.0 milestone Sep 29, 2021
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.

None yet

2 participants