operations.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Quantum Operations
  2. ==================
  3. There are a number of operations you can perform on quantum registers
  4. with QCGPU.
  5. Measurement
  6. -----------
  7. Measurement of a register in QCGPU doesn’t collapse the state (although
  8. this may be added in the future). When you measure the state, you can
  9. specify the number of times to sample. The output of this ``measure``
  10. function is a dictionary with the bitstrings of the outputs, along with
  11. the number of times they were measured.
  12. You can measure a register as follows,
  13. .. code:: python
  14. import qcgpu
  15. register = qcgpu.State(5)
  16. register.measure(samples=1000)
  17. # {'00000': 1000}
  18. There is also a convenience method to measure only a single qubit.
  19. Again, the state is not collapsed
  20. .. code:: python
  21. import qcgpu
  22. register = qcgpu.State(5)
  23. register.h(0)
  24. register.measure_qubit(0, samples=1000)
  25. # {'1': 523, '0': 477}
  26. Probability
  27. -----------
  28. QCGPU provides another method for getting the probability of each
  29. outcome.
  30. The probability of getting an outcome :math:`j` from a state
  31. :math:`\lvert \psi \rangle = \sum_{j = 0}^{2^n - 1} \alpha_j \lvert j \rangle`
  32. is
  33. .. math::
  34. P(j) = \lvert \alpha_j \lvert^2
  35. The method ``probabilities`` returns a numpy array with each of the
  36. values corresponding to :math:`\lvert \alpha_j \lvert ^2` for each index
  37. :math:`j`.
  38. .. code:: python
  39. import qcgpu
  40. register = qcgpu.State(1)
  41. register.h(0)
  42. register.probabilities() # [0.5, 0.5]
  43. This method is particularly useful to plot the probabilities of each
  44. outcome.