Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.8KB

  1. # -*- coding: utf-8 -*-
  2. """
  3. This module handles operations on the Clifford group. It makes extensive use of the lookup tables in ``abp.tables``.
  4. The code to generate those tables is included in this distribution as ``abp/build_tables.py``
  5. This package emumerates and labels the single-qubit Clifford group, and provides methods for matrix multiplication and conjugation.
  6. It also includes the look-up table for the CZ gate.
  7. There are 24 members of the single-qubit Clifford group. You can refer to some of them by multiple names.
  8. The complete set of aliases for single-qubit Cliffords is as follows:
  9. ======= =========================
  10. Index Aliases
  11. ======= =========================
  12. 0 ``IA, identity, identity_h``
  13. 1 ``XA, px, px_h``
  14. 2 ``YA, py, py_h``
  15. 3 ``ZA, pz, pz_h``
  16. 4 ``IB``
  17. 5 ``XB, sqz, msqz_h, phase_h``
  18. 6 ``YB, msqz, sqz_h, phase``
  19. 7 ``ZB``
  20. 8 ``IC``
  21. 9 ``XC, msqy, sqy_h``
  22. 10 ``YC, hadamard, hadamard_h``
  23. 11 ``ZC, sqy, msqy_h``
  24. 12 ``ID``
  25. 13 ``XD``
  26. 14 ``YD, sqx, msqx_h``
  27. 15 ``ZD, msqx, sqx_h``
  28. 16 ``IE``
  29. 17 ``XE``
  30. 18 ``YE``
  31. 19 ``ZE``
  32. 20 ``IF``
  33. 21 ``XF``
  34. 22 ``YF``
  35. 23 ``ZF``
  36. ======= =========================
  37. """
  38. from __future__ import absolute_import
  39. from __future__ import print_function
  40. from .tables import *
  41. from six.moves import range
  42. # Aliases
  43. identity = by_name["identity"]
  44. hadamard = by_name["hadamard"]
  45. px = by_name["px"]
  46. py = by_name["py"]
  47. pz = by_name["pz"]
  48. msqx_h = by_name["msqx_h"]
  49. sqz_h = by_name["sqz_h"]
  50. class Thing(object):
  51. def __init__(self):
  52. """ Constructor """
  53. return None
  54. def hunt(self):
  55. """ Pete is cool """
  56. pass
  57. def conjugate(operator, unitary):
  58. """ Returns transform * vop * transform^dagger and a phase in {+1, -1} """
  59. return measurement_table[operator, unitary]
  60. def use_old_cz():
  61. """ Use the CZ lookup table from A&B's code, rather than our own. Useful for testing. """
  62. global cz_table
  63. from .anders_cz import cz_table
  64. def get_name(i):
  65. """ Get the name of this clifford """
  66. return "IXYZ"[i & 0x03] + "ABCDEF"[i / 4]
  67. def human_name(i):
  68. """ Get the human-readable name of this clifford - slow """
  69. choices = sorted((key for key, value in list(by_name.items()) if value == i), key=len)
  70. return choices[-1]
  71. def is_diagonal(v):
  72. """ Checks if a VOP is diagonal or not """
  73. return v in {0, 3, 5, 6}
  74. if __name__ == '__main__':
  75. from itertools import groupby
  76. for i in range(24):
  77. members = [key for key, value in list(by_name.items()) if value == i and str(key)!=str(i)]
  78. members = sorted(members, key=len)
  79. print(("* {}: {}".format(i, ", ".join(members))))