XanaduAI / strawberryfields

Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.
https://strawberryfields.ai
Apache License 2.0
754 stars 191 forks source link

Add properties to program that return True/False for when feed-forward or post-selection is used. #302

Closed thisac closed 3 years ago

thisac commented 4 years ago

At the moment there is no nice way of checking whether a circuit has feed-forwarding or post-selection. Currently, it can be done by e.g. (the try-except is needed since not only measurement circuit operations have the select property):

for c in program.circuit:
    try:
        if c.op.select:
            print("post-selection is used")
    except AttributeError:
        pass

    if c.op.measurement_deps:
        print("feed-forwarding is used")

It would be much nicer, and less overhead, to have properties in Program that return True/False for when feed-forwarding and/or post-selection is used, instead of having to check each operation in the circuit each time you want to run it.

if program.post_selection:
    print("post-selection is used")

if program.feed_forward:
    print("feed-forwarding is used")
felipeoyarce commented 3 years ago

Hey @thisac, I'm going to tackle this issue :smile:

co9olguy commented 3 years ago

Awesome @felipeoyarce! Feel free to open a PR and ask any questions you may have for the team about the implementation.

felipeoyarce commented 3 years ago

Awesome @felipeoyarce! Feel free to open a PR and ask any questions you may have for the team about the implementation.

Thanks @co9olguy!