Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

121 lignes
2.5KB

  1. var ngbh = {};
  2. var vops = {};
  3. var meta = {};
  4. function add_node(node, m) {
  5. ngbh[node] = {};
  6. vops[node] = clifford.hadamard;
  7. meta[node] = m ? m : {};
  8. }
  9. function add_nodes(nodes) {
  10. nodes.forEach(add_node);
  11. }
  12. function add_edge(a, b) {
  13. ngbh[a][b] = true;
  14. ngbh[b][a] = true;
  15. }
  16. function add_edges(edges) {
  17. edges.forEach(function(e) {
  18. add_edge(e[0], e[1]);
  19. });
  20. }
  21. function del_edge(a, b) {
  22. delete ngbh[a][b];
  23. delete ngbh[b][a];
  24. }
  25. function has_edge(a, b) {
  26. return Object.prototype.hasOwnProperty.call(ngbh[a], b);
  27. }
  28. function toggle_edge(a, b) {
  29. if (has_edge(a, b)) {
  30. del_edge(a, b);
  31. } else {
  32. add_edge(a, b);
  33. }
  34. }
  35. function get_swap(node, avoid) {
  36. for (var i in ngbh[node]) {
  37. if (i != avoid) {return i;}
  38. }
  39. return avoid;
  40. }
  41. function remove_vop(node, avoid) {
  42. var swap_qubit = get_swap(node, avoid);
  43. var decomposition = decompositions[vops[node]];
  44. for (var i=decomposition.length-1; i >=0; --i) {
  45. var v = decomposition[i];
  46. local_complementation(v == "x" ? a : swap_qubit);
  47. }
  48. }
  49. function local_complementation(node) {
  50. var keys = Object.keys(ngbh[node]);
  51. for (var i=0; i < keys.length; ++i) {
  52. for (var j=i+1; j < keys.length; ++j) {
  53. toggle_edge(keys[i], keys[j]);
  54. }
  55. vops[i] = times_table[vops[keys[i]]][sqz_h];
  56. }
  57. vops[node] = times_table[vops[node]][msqx_h];
  58. }
  59. function act_local_rotation(node, operation) {
  60. var rotation = clifford[operation];
  61. vops[node] = times_table[rotation][vops[node]];
  62. }
  63. function act_hadamard(node){
  64. act_local_rotation(node, 10);
  65. }
  66. function is_sole_member(node, group){
  67. return group.length == 1 && group[0] == node;
  68. }
  69. function act_cz(a, b){
  70. if (is_sole_member(ngbh[a], b)) {
  71. remove_vop(a, b);
  72. }
  73. if (is_sole_member(ngbh[b], a)) {
  74. remove_vop(b, a);
  75. }
  76. if (is_sole_member(ngbh[a], b)) {
  77. remove_vop(a, b);
  78. }
  79. var edge = has_edge(a, b);
  80. var new_state = cz_table[edge ? 1 : 0][vops[a]][vops[b]];
  81. vops[a] = new_state[1];
  82. vops[b] = new_state[2];
  83. if (new_state[0] != edge){
  84. toggle_edge(a, b);
  85. }
  86. }
  87. function edgelist() {
  88. var seen = {};
  89. var output = [];
  90. for (var i in ngbh) {
  91. for (var j in ngbh[i]) {
  92. if (!Object.prototype.hasOwnProperty.call(seen, j)){
  93. output.push([i, j]);
  94. }
  95. }
  96. seen[i] = true;
  97. }
  98. return output;
  99. }
  100. function log_graph_state() {
  101. console.log(JSON.stringify(vops));
  102. console.log(JSON.stringify(ngbh));
  103. }