cuda-quantum icon indicating copy to clipboard operation
cuda-quantum copied to clipboard

[RFC] Python frontend for photonic simulator

Open khalatepradnya opened this issue 1 year ago • 4 comments

Required prerequisites

  • [X] Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

  • Add support to use the photonics simulator with photonics-cpu target from Python frontend of CUDA-Q

  • Proposed API

    • Gates (same as those supported on C++ frontend):

      1. plus(q: qudit) -> None,
      2. phase_shift(q: qudit, phi: float) -> None,
      3. beam_splitter(q: qudit, r: qudit, theta: float) -> None,
      4. mz(q: qudit) -> int and mz(q: list[qudit]) -> list[int]
    • Handler is inferred from the target

    • Custom handler must provide API for defining a qudit of level = N, for example, qudit(3)

    • APIs

      • Synchronous sampling: cudaq.sample(*args, **kwargs)
      • State retrieval: cudaq.get_state(*args, **kwargs)
  • Example

import cudaq

cudaq.set_target("photonics-cpu")


@cudaq.kernel
def photonicsKernel():    
    qutrits = [qudit(3) for i in range(2)]
    plus(qutrits[0])
    plus(qutrits[1])
    plus(qutrits[1])
    mz(qutrits)


counts = cudaq.sample(photonicsKernel)
print(counts)

state = cudaq.get_state(photonicsKernel)
print(state)

khalatepradnya avatar Jul 15 '24 23:07 khalatepradnya

For vis, @Omar-ORCA

khalatepradnya avatar Jul 15 '24 23:07 khalatepradnya

For vis, @Omar-ORCA

LGTM

Omar-ORCA avatar Jul 16 '24 07:07 Omar-ORCA

Updated the decorator as per inputs from @amccaskey

khalatepradnya avatar Jul 31 '24 03:07 khalatepradnya

Let's have a quick sync on implementation to make sure we are not missing anything that will lead to some technical pain across the different scenarios in the future. We'll set something up for a larger group and once we have confirmation that works across the board, we can approve and move forward with it. Acknowledged that the API looks good - not we need to talk implementation. :)

bettinaheim avatar Jul 31 '24 18:07 bettinaheim

The use of the plus gate in photonics circuits is not intuitive, changing it for the set of create and annihilate gates makes more sense. The following changes will be needed:

Required prerequisites

  • [x] Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

  • Add support to use the photonics simulator with photonics-cpu target from Python frontend of CUDA-Q
  • Add support to use the photonics simulator with photonics target from Python frontend of CUDA-Q
  • Proposed API

    • Gates (same as those supported on C++ frontend):

      1. plus(q: qudit) -> None,
      2. phase_shift(q: qudit, phi: float) -> None,
      3. beam_splitter(q: qudit, r: qudit, theta: float) -> None,
      4. mz(q: qudit) -> int and mz(q: list[qudit]) -> list[int]
  1. create(q: qudit) -> None,
  2. annihilate(q: qudit) -> None,
  3. plus(q: qudit) -> None, (to be deprecated)
  4. phase_shift(q: qudit, phi: float) -> None,
  5. beam_splitter(q: qudit, r: qudit, theta: float) -> None,
  6. mz(q: qudit) -> int and mz(q: list[qudit]) -> list[int]
  • Handler is inferred from the target> * Custom handler must provide API for defining a qudit of level = N, for example, qudit(3)
    • APIs

      • Synchronous sampling: cudaq.sample(*args, **kwargs)
      • State retrieval: cudaq.get_state(*args, **kwargs)
  • Example
import cudaq

cudaq.set_target("photonics-cpu")


@cudaq.kernel
def photonicsKernel():    
    qutrits = [qudit(3) for i in range(2)]
    plus(qutrits[0])
    plus(qutrits[1])
    plus(qutrits[1])
    mz(qutrits)


counts = cudaq.sample(photonicsKernel)
print(counts)

state = cudaq.get_state(photonicsKernel)
print(state)
@cudaq.kernel
def photonicsKernel():    
     qutrits = [qudit(3) for i in range(2)]
     create(qutrits[0])
     create(qutrits[1])
     create(qutrits[1])
     mz(qutrits)

Omar-ORCA avatar Oct 18 '24 09:10 Omar-ORCA

@boschmitt for visibility

khalatepradnya avatar Oct 18 '24 16:10 khalatepradnya