C2QA / bosonic-qiskit

Extension of Qiskit to support hybrid boson-qubit simulations for the NQI C2QA effort.
BSD 2-Clause "Simplified" License
44 stars 8 forks source link

Functions for adding arbitrary unitary matrices to bosonic qiskit circuits, and a rework of cv_fockcounts #92

Closed liu-zixiong closed 1 year ago

liu-zixiong commented 1 year ago

Hi Tim,

I'm not sure what the etiquette is for pull requests, but I figured it might be good to list the changes I've been working on. Here are a couple of new functions that Kevin told me would be good to add.

  1. Added util.fockmap() with unit test. Allows user to generate matrices by specifying arbitrary mappings between a set of input and output fock states.
  2. Added _operators.gate_frommatrix. Used by _cv_gate_frommatrix when appending ParameterizedUnitaryGate
  3. Added _circuit.cv_gate_frommatrix with unit test. Converts user specified unitary matrices to gates in the circuit. Meant to be used with fockmap() to generate any arbitrary gate.
  4. Added CVCircuit property _qumode_qubits_indicesgrouped. Same as _qumode_qubitsindices, but it groups the qubits that belong to same qumodes together. Returns nested list.
  5. Created util.newcounts() with unit test. Meant as a replacement to _util.cvfockcounts. Instead of taking in (counts, qubit_qumode_list), newcounts only needs needs (circuit, result) as its arguments and does the rest. newcounts depends on the __final_qumodemapping auxiliary function, and __final_measurementmapping that I lifted from the Mthree package.
  6. Integrated newcounts() into simulate() as an argument named _returnfockcounts
tjstavenger-pnnl commented 1 year ago

I'm definitely supportive of PRs and having someone review the changes before pushing to main. I don't want to be the only gatekeeper though -- if you've been working with Kevin on this work, you could have him review too (or instead of me).

I also appreciate the test cases -- definitely helpful while you're developing and also into the future to help ensure new changes don't break your code.

Is the copied Mthree code the same as this PyPI package? https://pypi.org/project/mthree/ Should we just add it as a dependency to the requirements.txt instead of copying in the code?

liu-zixiong commented 1 year ago

Hi Tim, Kevin has been the person who suggested that we add these features to the repo but he hasn't actually looked at the actual way I've implemented his suggestions. But he has said that you're the primary developer for the repo, so I figured it might be good for you to have a look through as you'd have a higher chance of bumping into the pieces I've changed (especially with the new arg I added on simulate). For now I'll just add Kevin to the list of reviewers just in case he wants to take a look.

I'm currently working on a tutorial for error correction in bosonic qiskit using the binomial kitten code, and that tutorial will have examples of how one would use the features I've added. It's almost done, I just need to integrate your newest discretize code into the tutorial. But if you want a sense of how the features I've added would be used I can push the current version onto the repo so that you can take a look.

The copied Mthree code is exactly from that package. Kevin and I didn't think that it would be necessary to add the whole package in since I'm only using a single function, but if you disagree I can also replace the code with an import and add Mthree it as a dependency. Either way would work.