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

Add threshold detector measurements to frontend & backends #134

Open
co9olguy opened this issue Jul 15, 2019 · 9 comments
Open

Add threshold detector measurements to frontend & backends #134

co9olguy opened this issue Jul 15, 2019 · 9 comments
Labels

Comments

@co9olguy
Copy link
Member

At the moment this can be hacked by doing MeasureFock and converting any nonzero results to a value of 1. However, there is likely a simpler way to implement these things by leveraging sampling algorithms in the hafnian library (at least for Gaussian and Fock backends).

@nquesada @josh146 thoughts?

@co9olguy co9olguy added backend enhancement New feature or request frontend labels Jul 15, 2019
@josh146
Copy link
Member

josh146 commented Jul 15, 2019

I would propose MeasureThreshold - more explicit to the user, fits with the existing approach we already use for new measurements in SF.

This allows the backends to implement this differently to MeasureFock, and they can just directly call hafnian.sample.torontonian_sample_state if applicable.

@nquesada
Copy link
Collaborator

I agree with Josh --- Mostly what is needed is some frontend operation and a way to communicate this to the backend. Ideally, for the Fock backends it should be not too hard to also construct conditional states after MeasureThreshold if the partial trace and post select on vacuum operations are available.

@co9olguy
Copy link
Member Author

Yep, only blocker I foresee here is (as usual), the TF backend, which has to implement all operations using tf ops

@nquesada
Copy link
Collaborator

Does the TF backend have operations for partial trace and postselection on vacuum? If so, conditional states after successful MeasureThreshold are just the difference of these two...

@co9olguy
Copy link
Member Author

co9olguy commented Jul 15, 2019

I was thinking more that actually implementing the sampling would be the harder part (since we can't just call hafnian lib)

@nquesada
Copy link
Collaborator

I think all the pieces are there and there is very minimal coding needed since the Fock backends already know about probabilities in the Fock basis.

@MattRos90
Copy link

Hi there!!! I'm trying to run some simulations using SF with TensorFlow backend and it would be really helpful to have a MeasureThreshold function with this backend. I have also tried to switch to Fock or Gaussian (1 shot) but it does not seem to be defined. I would be especially interested in manipulating the post-measurement state.

@co9olguy
Copy link
Member Author

co9olguy commented Mar 6, 2020

Hi @MattRos90

Thanks for your feedback. To help us distill what you're looking for, I have a couple questions:

Are you looking to carry out threshold measurements specifically with the TF backend, or would any backend do? (from a development perspective, it doesn't really matter so much, adding this feature to all backends will be roughly the same amount of work).

Note that measurements, being random, are not differentiable, which means you can't train circuits containing measurements. So there may not be any advantage to using the TF backend for this.

If you are not concerned with differentiability, as a quick workaround, you could use the existing MeasureFock measurement, then perform a little post-processing.
For example:

meas_fock_result # a numpy array of non-negative integers e.g., [0,2,5,0,1]
np.array(meas_fock_result >= 1, dtype=int) # [0,1,1,0,1]

@ziofil
Copy link
Collaborator

ziofil commented Mar 6, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants