I’m interested in making a simulation of boson sampling with a cost function and a basic gradient descent optimization.

Is it possible to use a cost function of my own creation to do so?

Also, if possible I’d like to use optimization on a general unitary matrix instead of a circuit, is something like this possible too?

# Boson sampling with optimization

Hi @segev. I’d recommend you to have a look at Strawberry Fields and the TensorFlow backend (here’s a tutorial on how to use it to optimize over parameters using custom loss functions and gradient descent). There are a few other tutorials related to circuit optimization and machine learning there as well.

If you’d like to use PennyLane instead, there’s a Strawberry Fields plugin which you can also use to optimize over our GBS hardware, if you have an API key.

Also, if possible I’d like to use optimization on a general unitary matrix instead of a circuit, is something like this possible too?

This is a bit tricky. In PennyLane, there’s the interferometer gate which decomposes a unitary into arrays of beamsplitters and rotation gates. You could also implement the same circuit in Strawberry Fields. Also, look into the GBS device, which embeds an adjacency matrix onto the GBS. That might be of interest to you!