photonics.py 850 B

1234567891011121314151617181920212223242526272829303132
  1. from defs import Channel
  2. import numpy as np
  3. class PhotonicCoder:
  4. def encode(self, data: np.ndarray) -> np.ndarray:
  5. """
  6. """
  7. raise NotImplemented("encode function not defined")
  8. def decode(self, data: np.ndarray) -> np.ndarray:
  9. """
  10. """
  11. raise NotImplemented("decode function not defined")
  12. class PhotonicSimulation:
  13. """
  14. This is a main class that will contain coder/channel and all
  15. necessary useful methods to run/monitor simulation
  16. """
  17. def __init__(self, coder: PhotonicCoder, channel: Channel):
  18. self.coder = coder
  19. self.channel = channel
  20. def run(self, data: np.ndarray) -> np.ndarray:
  21. encoded = self.coder.encode(data)
  22. transmitted = self.channel.forward(encoded)
  23. decoded = self.coder.decode(transmitted)
  24. return decoded