Customizable Gates and Multiple Fock cutoffs in StrawberryFields

Hi all! I’ve been trying the tutorial on implementing Hamiltonian simulations on StrawberryFields posted at Hamiltonian simulation — Strawberry Fields. I’m currently working on implementing such simulations for more complex Hamiltonians in the sense that there are terms involving more than 2 creation/annihilation operators. Is there any way I could add more customized gates to the source code?

As a comparison, the bosonic-qiskit platform developed by C2QA recently (GitHub - C2QA/bosonic-qiskit: Extension of Qiskit to support hybrid boson-qubit simulations for the NQI C2QA effort.) does allow adding my own gates by adding more functions to the circuits.py and operators.py file. So I guess my question could be rephrased as if there is something analogous in StrawberryFields. I’ve been looking into the StrawberryFields source code (GitHub - XanaduAI/strawberryfields: Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.) but I believe some set of instructions would really help me in ensuring that I don’t mess up anything.

Additionally, if I get it correctly, the TFBackend and FockBackend in StrawberryFields give me any cutoff I want but bosonic-qiskit only allows cutoff that are powers of 2 to be implementable on qiskit. However, bosonic-qiskit allows the creation of qumodes that have different Fock cutoffs while StrawberryFields only allows one Fock cutoff applied to all qumodes - is there anyway I can circumvent this? Thanks for any help you can provide!

Hey @vpn! Welcome to the forum :smiley:

Custom operations can definitely be created in SF. What you can do is either create a class that inherits from sf.Operation,

https://github.com/XanaduAI/strawberryfields/blob/9a9a352b5b8cf7b2915e45d1538b51d7d306cfc8/strawberryfields/ops.py#L70,

or sf.Gate,

https://github.com/XanaduAI/strawberryfields/blob/9a9a352b5b8cf7b2915e45d1538b51d7d306cfc8/strawberryfields/ops.py#L433,

and use a “stock” operation as a guideline for creating your custom one :slight_smile:.

… but bosonic-qiskit only allows cutoff that are powers of 2 to be implementable on qiskit. However, bosonic-qiskit allows the creation of qumodes that have different Fock cutoffs while StrawberryFields only allows one Fock cutoff applied to all qumodes - is there anyway I can circumvent this?

Do you mean more than 2 in the sense of more than 2 modes, or in the sense of cubic and higher order Hamiltonians? :thinking:

Hi @isaacdevlugt ,

Thanks a lot for your reply! I’ve been trying the past two days on trying to implement what you said, but to be honest I’m really new to python and github. As for the C2QA Bosonic-qiskit package I mentioned above, the instructions told me to add functions that correspond to the gate I desire in two .py files, which was straightforward enough for me to follow (and I could make a single-mode Kerr gate which is not yet available in that package). However, when I looked at the ops.py file that you suggested, I was confused with where to start with. For example, if I want to make a four-mode gate, let’s call it J, where J(z) = \exp{\left(z(a_1a_2^\dagger+a_1^\dagger a_2)(a_3a_4^\dagger+a_3^\dagger a_4)\right)} (each smaller bracket does look like a two-mode beamsplitter), then what should I do? (I would really appreciate if you could explain what a “stock” operation is too!)

For the second question… what I meant was, can I create a 2-mode Program where the Fock cutoff for the first mode is, say, 5, and that for the second mode is 10?

Thanks for any clarification and help you can provide again!

There are a couple of options I see here:

  1. Look at what’s in one of our other software packages called thewalrusThe Walrus Documentation — The Walrus 0.21.0-dev documentation — (the beamsplitter defined there), adjust as needed but define your new function in the same scope as your custom operation (don’t create something new inside thewalrus), then utilize it in your custom operation akin to what BSgate does with thewalrus’ beamsplitter function :sweat_smile:
  2. Define the operator in the exponent in a finite dimensional space (i.e., with some artificially large cutoffs) and then use the matrix exponential function from scipy. If the cutoffs are large enough you can then truncate after the exponentiation and chances are your tensor is somewhat correct. You’d lose differentiability though, if that’s one thing you were after.

what I meant was, can I create a 2-mode Program where the Fock cutoff for the first mode is, say, 5, and that for the second mode is 10

Unfortunately, that isn’t possible in StrawberryFields at this time.

I would really appreciate if you could explain what a “stock” operation is too!

I just mean one of the operators that already exists :slight_smile:. E.g., BSgate.