tequila-basic 1.8.9__tar.gz → 1.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/PKG-INFO +22 -3
  2. tequila-basic-1.8.9/src/tequila_basic.egg-info/PKG-INFO → tequila-basic-1.9.1/README.md +12 -11
  3. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/requirements.txt +1 -0
  4. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/_gates_impl.py +42 -9
  5. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/gates.py +98 -64
  6. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/fermionic_functions.py +77 -16
  7. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/fermionic_methods.py +5 -2
  8. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/hamiltonian/paulis.py +1 -1
  9. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/optimizer_gd.py +2 -1
  10. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/orbital_optimizer.py +13 -7
  11. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/pyscf_interface.py +11 -17
  12. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/qc_base.py +29 -7
  13. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_cirq.py +15 -25
  14. tequila-basic-1.9.1/src/tequila/version.py +2 -0
  15. tequila-basic-1.8.9/README.md → tequila-basic-1.9.1/src/tequila_basic.egg-info/PKG-INFO +30 -1
  16. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila_basic.egg-info/SOURCES.txt +34 -1
  17. tequila-basic-1.9.1/tests/test_TrotErr.py +118 -0
  18. tequila-basic-1.9.1/tests/test_adapt.py +72 -0
  19. tequila-basic-1.9.1/tests/test_array.py +39 -0
  20. tequila-basic-1.9.1/tests/test_binary_pauli.py +330 -0
  21. tequila-basic-1.9.1/tests/test_binary_utils.py +134 -0
  22. tequila-basic-1.9.1/tests/test_bitstrings.py +91 -0
  23. tequila-basic-1.9.1/tests/test_braket.py +277 -0
  24. tequila-basic-1.9.1/tests/test_chemistry.py +727 -0
  25. tequila-basic-1.9.1/tests/test_chemistry_f12.py +56 -0
  26. tequila-basic-1.9.1/tests/test_chemistry_madness.py +259 -0
  27. tequila-basic-1.9.1/tests/test_circuits.py +392 -0
  28. tequila-basic-1.9.1/tests/test_fermionic_meas.py +115 -0
  29. tequila-basic-1.9.1/tests/test_gd_optimizer.py +98 -0
  30. tequila-basic-1.9.1/tests/test_gpyopt.py +80 -0
  31. tequila-basic-1.9.1/tests/test_gradient.py +532 -0
  32. tequila-basic-1.9.1/tests/test_hamiltonian_arithmetic.py +342 -0
  33. tequila-basic-1.9.1/tests/test_krylov.py +43 -0
  34. tequila-basic-1.9.1/tests/test_mappings.py +104 -0
  35. tequila-basic-1.9.1/tests/test_noise.py +210 -0
  36. tequila-basic-1.9.1/tests/test_noise_opt.py +88 -0
  37. tequila-basic-1.9.1/tests/test_objectives.py +738 -0
  38. tequila-basic-1.9.1/tests/test_phoenics.py +68 -0
  39. tequila-basic-1.9.1/tests/test_pyzx.py +178 -0
  40. tequila-basic-1.9.1/tests/test_qasm.py +234 -0
  41. tequila-basic-1.9.1/tests/test_qtensor.py +80 -0
  42. tequila-basic-1.9.1/tests/test_recompilation_routines.py +160 -0
  43. tequila-basic-1.9.1/tests/test_scipy.py +151 -0
  44. tequila-basic-1.9.1/tests/test_simulator_backends.py +438 -0
  45. tequila-basic-1.9.1/tests/test_symbolic_simulator.py +57 -0
  46. tequila-basic-1.9.1/tests/test_torch_interface.py +59 -0
  47. tequila-basic-1.9.1/tests/test_unary_state_prep.py +83 -0
  48. tequila-basic-1.9.1/tests/test_variable.py +72 -0
  49. tequila-basic-1.9.1/tests/test_zzz_cleanup.py +10 -0
  50. tequila-basic-1.8.9/src/tequila/version.py +0 -2
  51. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/LICENSE +0 -0
  52. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/MANIFEST.in +0 -0
  53. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/setup.cfg +0 -0
  54. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/setup.py +0 -0
  55. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/__init__.py +0 -0
  56. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/__init__.py +0 -0
  57. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/_unary_state_prep_impl.py +0 -0
  58. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/adapt/__init__.py +0 -0
  59. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/adapt/adapt.py +0 -0
  60. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/krylov/__init__.py +0 -0
  61. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/krylov/krylov.py +0 -0
  62. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/robustness/__init__.py +0 -0
  63. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/robustness/helpers.py +0 -0
  64. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/robustness/interval.py +0 -0
  65. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/apps/unary_state_prep.py +0 -0
  66. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/autograd_imports.py +0 -0
  67. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/__init__.py +0 -0
  68. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/circuit.py +0 -0
  69. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/compiler.py +0 -0
  70. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/gradient.py +0 -0
  71. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/noise.py +0 -0
  72. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/pyzx.py +0 -0
  73. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/qasm.py +0 -0
  74. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/circuit/qpic.py +0 -0
  75. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/__init__.py +0 -0
  76. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/binary_rep.py +0 -0
  77. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/binary_utils.py +0 -0
  78. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/compile_groups.py +0 -0
  79. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/ev_utils.py +0 -0
  80. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/grouping/overlapping_methods.py +0 -0
  81. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/hamiltonian/__init__.py +0 -0
  82. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/hamiltonian/paulistring.py +0 -0
  83. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/hamiltonian/qubit_hamiltonian.py +0 -0
  84. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/ml/__init__.py +0 -0
  85. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/ml/interface_torch.py +0 -0
  86. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/ml/ml_api.py +0 -0
  87. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/ml/utils_ml.py +0 -0
  88. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/objective/__init__.py +0 -0
  89. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/objective/braket.py +0 -0
  90. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/objective/objective.py +0 -0
  91. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/objective/qtensor.py +0 -0
  92. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/__init__.py +0 -0
  93. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/_containers.py +0 -0
  94. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/optimizer_base.py +0 -0
  95. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/optimizer_gpyopt.py +0 -0
  96. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/optimizer_phoenics.py +0 -0
  97. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/optimizers/optimizer_scipy.py +0 -0
  98. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/__init__.py +0 -0
  99. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/chemistry_tools.py +0 -0
  100. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/encodings.py +0 -0
  101. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/madness_interface.py +0 -0
  102. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/quantumchemistry/psi4_interface.py +0 -0
  103. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/__init__.py +0 -0
  104. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_api.py +0 -0
  105. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_base.py +0 -0
  106. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_pyquil.py +0 -0
  107. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_qibo.py +0 -0
  108. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_qiskit.py +0 -0
  109. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_qlm.py +0 -0
  110. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_qulacs.py +0 -0
  111. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_qulacs_gpu.py +0 -0
  112. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/simulators/simulator_symbolic.py +0 -0
  113. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/tools/__init__.py +0 -0
  114. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/tools/convenience.py +0 -0
  115. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/tools/qng.py +0 -0
  116. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/tools/random_generators.py +0 -0
  117. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/utils/__init__.py +0 -0
  118. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/utils/bitstrings.py +0 -0
  119. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/utils/exceptions.py +0 -0
  120. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/utils/joined_transformation.py +0 -0
  121. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/utils/keymap.py +0 -0
  122. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/utils/misc.py +0 -0
  123. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/wavefunction/__init__.py +0 -0
  124. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila/wavefunction/qubit_wavefunction.py +0 -0
  125. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila_basic.egg-info/dependency_links.txt +0 -0
  126. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila_basic.egg-info/requires.txt +0 -0
  127. {tequila-basic-1.8.9 → tequila-basic-1.9.1}/src/tequila_basic.egg-info/top_level.txt +0 -0
@@ -1,12 +1,20 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tequila-basic
3
- Version: 1.8.9
3
+ Version: 1.9.1
4
4
  Summary: A High-Level Abstraction Framework for Quantum Algorithms
5
5
  Home-page: https://github.com/tequilahub/tequila
6
- Author: Jakob Kottmann and Sumner Alperin-Lea and Teresa Tamayo-Mendoza and Alba Cervera-Lierta and Cyrille Lavigne and Tzu-Ching Yen and Vladyslav Verteletskyi and Philipp Schleich and Abhinav Anand and Matthias Degroote and Skylar Chaney and Maha Kesibi and Naomi Grace Curnow and Brandon Solo and Georgios Tsilimigkounakis and Claudia Zendejas-Morales and Artur F Izmaylov and Alan Aspuru-Guzik ...
6
+ Author: Tequila Developers
7
7
  Author-email: jakob.kottmann@gmail.com
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
+ Requires-Dist: numpy
11
+ Requires-Dist: scipy<1.11
12
+ Requires-Dist: sympy
13
+ Requires-Dist: autograd
14
+ Requires-Dist: setuptools
15
+ Requires-Dist: pytest
16
+ Requires-Dist: openfermion~=1.0
17
+ Requires-Dist: dataclasses; python_version < "3.7"
10
18
 
11
19
  [![License: MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg)](LICENCE) [![DOI](https://zenodo.org/badge/259718912.svg)](https://zenodo.org/badge/latestdoi/259718912) [![PyPI version](https://badge.fury.io/py/tequila-basic.svg)](https://badge.fury.io/py/tequila-basic) ![CI](https://github.com/tequilahub/tequila/actions/workflows/ci_basic.yml/badge.svg)
12
20
 
@@ -25,7 +33,7 @@ Tequila can execute the underlying quantum expectation values on state of the ar
25
33
 
26
34
  # Installation
27
35
  Recommended Python version is 3.8-3.9.
28
- Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.
36
+ Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.
29
37
 
30
38
  ## Install from PyPi
31
39
  **Do not** install like this: (Minecraft lovers excluded)
@@ -238,6 +246,17 @@ K. Gratsea, C. Sun, P.D. Johnson
238
246
  When to Reject a Ground State Preparation Algorithm
239
247
  [arxiv:2212.09492](https://doi.org/10.48550/arXiv.2212.09492)
240
248
 
249
+ R.P. Pothukuchi, L. Lufkin, Y.J. Shen, A. Simon, R. Thorstenson, B.E. Trevisan, M. Tu, M. Yang, B. Foxman, V. S. Pothukuchi, G. Epping, B. J. Jongkees, T.-H. Kyaw, J. R. Busemeyer, J. D Cohen, A. Bhattacharjee
250
+ Quantum Cognitive Modeling: New Applications and Systems Research Directions
251
+ [arxiv:2309.00597](https://arxiv.org/abs/2309.00597)
252
+
253
+ T.-H. Kyaw, M. B. Soley, B. Allen, P. Bergold, C. Sun, V.S. Batista and A. Aspuru-Guzik
254
+ Boosting quantum amplitude exponentially in variational quantum algorithms
255
+ [10.1088/2058-9565/acf4ba](doi.org/10.1088/2058-9565/acf4ba)
256
+
257
+ A.G. Cadavid, I. Montalban, A. Dalal, E. Solano, N.N. Hegade
258
+ Efficient DCQO Algorithm within the Impulse Regime for Portfolio Optimization
259
+ [arxiv:2308.15475](https://arxiv.org/abs/2308.15475)
241
260
 
242
261
  Let us know, if you want your research project and/or tutorial to be included in this list!
243
262
 
@@ -1,13 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: tequila-basic
3
- Version: 1.8.9
4
- Summary: A High-Level Abstraction Framework for Quantum Algorithms
5
- Home-page: https://github.com/tequilahub/tequila
6
- Author: Jakob Kottmann and Sumner Alperin-Lea and Teresa Tamayo-Mendoza and Alba Cervera-Lierta and Cyrille Lavigne and Tzu-Ching Yen and Vladyslav Verteletskyi and Philipp Schleich and Abhinav Anand and Matthias Degroote and Skylar Chaney and Maha Kesibi and Naomi Grace Curnow and Brandon Solo and Georgios Tsilimigkounakis and Claudia Zendejas-Morales and Artur F Izmaylov and Alan Aspuru-Guzik ...
7
- Author-email: jakob.kottmann@gmail.com
8
- Description-Content-Type: text/markdown
9
- License-File: LICENSE
10
-
11
1
  [![License: MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg)](LICENCE) [![DOI](https://zenodo.org/badge/259718912.svg)](https://zenodo.org/badge/latestdoi/259718912) [![PyPI version](https://badge.fury.io/py/tequila-basic.svg)](https://badge.fury.io/py/tequila-basic) ![CI](https://github.com/tequilahub/tequila/actions/workflows/ci_basic.yml/badge.svg)
12
2
 
13
3
  # Tequila
@@ -25,7 +15,7 @@ Tequila can execute the underlying quantum expectation values on state of the ar
25
15
 
26
16
  # Installation
27
17
  Recommended Python version is 3.8-3.9.
28
- Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.
18
+ Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows.
29
19
 
30
20
  ## Install from PyPi
31
21
  **Do not** install like this: (Minecraft lovers excluded)
@@ -238,6 +228,17 @@ K. Gratsea, C. Sun, P.D. Johnson
238
228
  When to Reject a Ground State Preparation Algorithm
239
229
  [arxiv:2212.09492](https://doi.org/10.48550/arXiv.2212.09492)
240
230
 
231
+ R.P. Pothukuchi, L. Lufkin, Y.J. Shen, A. Simon, R. Thorstenson, B.E. Trevisan, M. Tu, M. Yang, B. Foxman, V. S. Pothukuchi, G. Epping, B. J. Jongkees, T.-H. Kyaw, J. R. Busemeyer, J. D Cohen, A. Bhattacharjee
232
+ Quantum Cognitive Modeling: New Applications and Systems Research Directions
233
+ [arxiv:2309.00597](https://arxiv.org/abs/2309.00597)
234
+
235
+ T.-H. Kyaw, M. B. Soley, B. Allen, P. Bergold, C. Sun, V.S. Batista and A. Aspuru-Guzik
236
+ Boosting quantum amplitude exponentially in variational quantum algorithms
237
+ [10.1088/2058-9565/acf4ba](doi.org/10.1088/2058-9565/acf4ba)
238
+
239
+ A.G. Cadavid, I. Montalban, A. Dalal, E. Solano, N.N. Hegade
240
+ Efficient DCQO Algorithm within the Impulse Regime for Portfolio Optimization
241
+ [arxiv:2308.15475](https://arxiv.org/abs/2308.15475)
241
242
 
242
243
  Let us know, if you want your research project and/or tutorial to be included in this list!
243
244
 
@@ -13,6 +13,7 @@ openfermion ~= 1.0 # can not be smaller than 1.0
13
13
 
14
14
  #optional quantum backends
15
15
  #cirq >= 0.9.2 #
16
+ #cirq_google
16
17
  #qiskit>=0.30
17
18
  #pyquil<3.0 # you also need to install the forest-sdk
18
19
  ##qulacs-gpu # you can't have #qulacs and #qulacs-gpu at the same time
@@ -6,7 +6,7 @@ from tequila.utils.exceptions import TequilaException
6
6
  from tequila.objective.objective import Variable, FixedVariable, assign_variable
7
7
  from tequila.hamiltonian import PauliString, QubitHamiltonian, paulis
8
8
  from tequila.tools import list_assignment
9
- from numpy import pi, sqrt
9
+ import numpy as np
10
10
 
11
11
  from dataclasses import dataclass
12
12
 
@@ -234,12 +234,12 @@ class DifferentiableGateImpl(ParametrizedGateImpl):
234
234
  if r is None:
235
235
  r = self.eigenvalues_magnitude
236
236
 
237
- s = pi / (4 * r)
237
+ s = np.pi / (4 * r)
238
238
  if self.is_controlled() and not self.assume_real:
239
239
  # following https://arxiv.org/abs/2104.05695
240
240
  shifts = [s, -s, 3 * s, -3 * s]
241
- coeff1 = (sqrt(2) + 1)/sqrt(8) * r
242
- coeff2 = (sqrt(2) - 1)/sqrt(8) * r
241
+ coeff1 = (np.sqrt(2) + 1)/np.sqrt(8) * r
242
+ coeff2 = (np.sqrt(2) - 1)/np.sqrt(8) * r
243
243
  coefficients = [coeff1, -coeff1, -coeff2, coeff2]
244
244
  circuits = []
245
245
  for i, shift in enumerate(shifts):
@@ -344,7 +344,7 @@ class PowerGateImpl(ParametrizedGateImpl):
344
344
 
345
345
  @property
346
346
  def power(self):
347
- return self.parameter/pi
347
+ return self.parameter/np.pi
348
348
 
349
349
  def __init__(self, name, generator: QubitHamiltonian, target: list, power, control: list = None):
350
350
  if generator is None:
@@ -353,7 +353,7 @@ class PowerGateImpl(ParametrizedGateImpl):
353
353
  if name is None:
354
354
  assert generator is not None
355
355
  name = str(generator)
356
- super().__init__(name=name, parameter=power * pi, target=target, control=control, generator=generator)
356
+ super().__init__(name=name, parameter=power * np.pi, target=target, control=control, generator=generator)
357
357
 
358
358
 
359
359
  class GeneralizedRotationImpl(DifferentiableGateImpl):
@@ -376,11 +376,44 @@ class GeneralizedRotationImpl(DifferentiableGateImpl):
376
376
  targets += [k for k in ps.keys()]
377
377
  return tuple(set(targets))
378
378
 
379
- def __init__(self, angle, generator, control=None, eigenvalues_magnitude=0.5, steps=1, assume_real=False):
380
- super().__init__(eigenvalues_magnitude=eigenvalues_magnitude, assume_real=assume_real, name="GenRot", parameter=angle, target=self.extract_targets(generator), control=control)
379
+ def __init__(self, angle, generator, p0=None, control=None, target=None, eigenvalues_magnitude=0.5, steps=1, name="GenRot", assume_real=False):
380
+ if target == None:
381
+ target = self.extract_targets(generator)
382
+ super().__init__(eigenvalues_magnitude=eigenvalues_magnitude, generator=generator, assume_real=assume_real, name=name, parameter=angle, target=target, control=control)
381
383
  self.steps = steps
382
- self.generator = generator
384
+ if control is None and p0 is not None:
385
+ # augment p0 for control qubits
386
+ # Qp = 1/2(1+Z) = |0><0|
387
+ p0 = p0*paulis.Qp(control)
388
+ self.p0 = p0
389
+
390
+ def shifted_gates(self):
391
+ if not self.assume_real:
392
+ # following https://arxiv.org/abs/2104.05695
393
+ s = 0.5 * np.pi
394
+ shifts = [s, -s, 3 * s, -3 * s]
395
+ coeff1 = 0.25 * (np.sqrt(2) + 1)/np.sqrt(2)
396
+ coeff2 = 0.25 * (np.sqrt(2) - 1)/np.sqrt(2)
397
+ coefficients = [coeff1, -coeff1, -coeff2, coeff2]
398
+ circuits = []
399
+ for i, shift in enumerate(shifts):
400
+ shifted_gate = copy.deepcopy(self)
401
+ shifted_gate.parameter += shift
402
+ circuits.append((coefficients[i], shifted_gate))
403
+ return circuits
383
404
 
405
+ r = 0.25
406
+ s = 0.5*np.pi
407
+
408
+ Up1 = copy.deepcopy(self)
409
+ Up1._parameter = self.parameter+s
410
+ Up2 = GeneralizedRotationImpl(angle=s, generator=self.p0, eigenvalues_magnitude=r) # controls are in p0
411
+ Um1 = copy.deepcopy(self)
412
+ Um1._parameter = self.parameter-s
413
+ Um2 = GeneralizedRotationImpl(angle=-s, generator=self.p0, eigenvalues_magnitude=r) # controls are in p0
414
+
415
+ return [(2.0 * r, [Up1, Up2]), (-2.0 * r, [Um1, Um2])]
416
+
384
417
  class ExponentialPauliGateImpl(DifferentiableGateImpl):
385
418
  """
386
419
  Same convention as for rotation gates:
@@ -361,10 +361,13 @@ def Rp(paulistring: typing.Union[PauliString, str], angle, control: typing.Union
361
361
  return ExpPauli(paulistring=paulistring, angle=angle, control=control, *args, **kwargs)
362
362
 
363
363
 
364
+ def GenRot(*args, **kwargs):
365
+ return GeneralizedRotation(*args, **kwargs)
366
+
364
367
  def GeneralizedRotation(angle: typing.Union[typing.List[typing.Hashable], typing.List[numbers.Real]],
365
368
  generator: QubitHamiltonian,
366
369
  control: typing.Union[list, int] = None,
367
- eigenvalues_magnitude: float = 0.5,
370
+ eigenvalues_magnitude: float = 0.5, p0=None,
368
371
  steps: int = 1, assume_real=False) -> QCircuit:
369
372
  """
370
373
 
@@ -393,6 +396,8 @@ def GeneralizedRotation(angle: typing.Union[typing.List[typing.Hashable], typing
393
396
  list of control qubits
394
397
  eigenvalues_magnitude
395
398
  magnitude of eigenvalues, in most papers referred to as "r" (default 0.5)
399
+ p0
400
+ possible nullspace projector (if the rotation is happens in Q = 1-P0). See arxiv:2011.05938
396
401
  steps
397
402
  possible Trotterization steps (default 1)
398
403
 
@@ -403,7 +408,7 @@ def GeneralizedRotation(angle: typing.Union[typing.List[typing.Hashable], typing
403
408
 
404
409
  return QCircuit.wrap_gate(
405
410
  impl.GeneralizedRotationImpl(angle=assign_variable(angle), generator=generator, control=control,
406
- eigenvalues_magnitude=eigenvalues_magnitude, steps=steps, assume_real=assume_real))
411
+ eigenvalues_magnitude=eigenvalues_magnitude, steps=steps, assume_real=assume_real, p0=p0))
407
412
 
408
413
 
409
414
 
@@ -473,7 +478,7 @@ def Trotterized(generator: QubitHamiltonian = None,
473
478
  return QCircuit.wrap_gate(impl.TrotterizedGateImpl(generator=generator, angle=angle, steps=steps, control=control, randomize=randomize, **kwargs))
474
479
 
475
480
 
476
- def SWAP(first: int, second: int, control: typing.Union[int, list] = None, power: float = None, *args,
481
+ def SWAP(first: int, second: int, angle: float = None, control: typing.Union[int, list] = None, power: float = None, *args,
477
482
  **kwargs) -> QCircuit:
478
483
  """
479
484
  Notes
@@ -486,10 +491,12 @@ def SWAP(first: int, second: int, control: typing.Union[int, list] = None, power
486
491
  target qubit
487
492
  second: int
488
493
  target qubit
494
+ angle: numeric type or hashable type
495
+ exponent in the for e^{-i a/2 G}
489
496
  control
490
497
  int or list of ints
491
498
  power
492
- numeric type (fixed exponent) or hashable type (parametrized exponent)
499
+ numeric type (fixed exponent) or hashable type (parametrized exponent in the form (SWAP)^n
493
500
 
494
501
  Returns
495
502
  -------
@@ -498,12 +505,82 @@ def SWAP(first: int, second: int, control: typing.Union[int, list] = None, power
498
505
  """
499
506
 
500
507
  target = [first, second]
508
+ if angle is not None:
509
+ assert power is None
510
+ angle = assign_variable(angle)
511
+ elif power is not None:
512
+ angle = assign_variable(power)*np.pi
501
513
  generator = 0.5 * (paulis.X(target) + paulis.Y(target) + paulis.Z(target) - paulis.I(target))
502
- if power is None or power in [1, 1.0]:
514
+ if angle is None or power in [1, 1.0]:
503
515
  return QGate(name="SWAP", target=target, control=control, generator=generator)
504
516
  else:
505
- return GeneralizedRotation(angle=power * np.pi, control=control, generator=generator,
517
+ return GeneralizedRotation(angle=angle, control=control, generator=generator,
506
518
  eigenvalues_magnitude=0.25)
519
+
520
+
521
+ def iSWAP(first: int, second: int, control: typing.Union[int, list] = None, power: float = 1.0, *args,
522
+ **kwargs) -> QCircuit:
523
+ """
524
+ Notes
525
+ ----------
526
+ iSWAP gate
527
+ .. math::
528
+ iSWAP = e^{i\\frac{\\pi}{4} (X \\otimes X + Y \\otimes Y )}
529
+
530
+ Parameters
531
+ ----------
532
+ first: int
533
+ target qubit
534
+ second: int
535
+ target qubit
536
+ control
537
+ int or list of ints
538
+ power
539
+ numeric type (fixed exponent) or hashable type (parametrized exponent)
540
+
541
+ Returns
542
+ -------
543
+ QCircuit
544
+
545
+ """
546
+
547
+ generator = paulis.from_string(f"X({first})X({second}) + Y({first})Y({second})")
548
+
549
+ p0 = paulis.Projector("|00>") + paulis.Projector("|11>")
550
+ p0 = p0.map_qubits({0:first, 1:second})
551
+
552
+ gate = QubitExcitationImpl(angle=power*(-np.pi/2), target=generator.qubits, generator=generator, p0=p0, control=control, compile_options="vanilla", *args, **kwargs)
553
+
554
+ return QCircuit.wrap_gate(gate)
555
+
556
+
557
+ def Givens(first: int, second: int, control: typing.Union[int, list] = None, angle: float = None, *args,
558
+ **kwargs) -> QCircuit:
559
+ """
560
+ Notes
561
+ ----------
562
+ Givens gate G
563
+ .. math::
564
+ G = e^{-i\\theta \\frac{(Y \\otimes X - X \\otimes Y )}{2}}
565
+
566
+ Parameters
567
+ ----------
568
+ first: int
569
+ target qubit
570
+ second: int
571
+ target qubit
572
+ control
573
+ int or list of ints
574
+ angle
575
+ numeric type (fixed exponent) or hashable type (parametrized exponent), theta in the above formula
576
+
577
+ Returns
578
+ -------
579
+ QCircuit
580
+
581
+ """
582
+
583
+ return QubitExcitation(target=[second,first], angle=2*angle, control=control, *args, **kwargs) # twice the angle since theta is not divided by two in the matrix exponential
507
584
 
508
585
 
509
586
  """
@@ -965,11 +1042,7 @@ and should all implement a compile function that
965
1042
  returns a QCircuit of primitive tq gates
966
1043
  """
967
1044
 
968
- class QubitExcitationImpl(impl.DifferentiableGateImpl):
969
-
970
- @property
971
- def steps(self):
972
- return 1
1045
+ class QubitExcitationImpl(impl.GeneralizedRotationImpl):
973
1046
 
974
1047
  def __init__(self, angle, target, generator=None, p0=None, assume_real=True, control=None, compile_options=None):
975
1048
  angle = assign_variable(angle)
@@ -990,15 +1063,9 @@ class QubitExcitationImpl(impl.DifferentiableGateImpl):
990
1063
  else:
991
1064
  assert generator is not None
992
1065
  assert p0 is not None
993
-
994
- super().__init__(name="QubitExcitation", parameter=angle, target=target, control=control)
995
- self.generator = generator
996
- if control is not None:
997
- # augment p0 for control qubits
998
- # Qp = 1/2(1+Z) = |0><0|
999
- p0 = p0*paulis.Qp(control)
1000
- self.p0 = p0
1001
- self.assume_real = assume_real
1066
+
1067
+ super().__init__(name="QubitExcitation", angle=angle, generator=generator, target=target, p0=p0, control=control, assume_real=assume_real, steps=1)
1068
+
1002
1069
  if compile_options is None:
1003
1070
  self.compile_options = "optimize"
1004
1071
  elif hasattr(compile_options, "lower"):
@@ -1007,26 +1074,21 @@ class QubitExcitationImpl(impl.DifferentiableGateImpl):
1007
1074
  self.compile_options = compile_options
1008
1075
 
1009
1076
  def map_qubits(self, qubit_map: dict):
1010
- mapped_generator = self.generator.map_qubits(qubit_map=qubit_map)
1011
- mapped_p0 = self.p0.map_qubits(qubit_map=qubit_map)
1012
- mapped_control = self.control
1013
- if mapped_control is not None:
1014
- mapped_control=tuple([qubit_map[i] for i in self.control])
1015
- result = copy.deepcopy(self)
1016
- result.generator=mapped_generator
1017
- result.p0 = mapped_p0
1018
- result._target = tuple([qubit_map[x] for x in self.target])
1019
- result._control = mapped_control
1020
- result.finalize()
1021
- return result
1077
+ mapped = super().map_qubits(qubit_map)
1078
+ mapped.p0 = self.p0.map_qubits(qubit_map=qubit_map)
1079
+ return mapped
1022
1080
 
1023
1081
  def compile(self, exponential_pauli=False, *args, **kwargs):
1024
1082
  # optimized compiling for single and double qubit excitaitons following arxiv:2005.14475
1025
1083
  # Alternative representation in arxiv:2104.05695 (not implemented -> could be added and controlled with optional compile keywords)
1084
+ if self.is_controlled():
1085
+ control = list(self.control)
1086
+ else:
1087
+ control = []
1026
1088
  if self.compile_options == "optimize" and len(self.target) == 2 and exponential_pauli:
1027
1089
  p,q = self.target
1028
1090
  U0 = X(target=p, control=q)
1029
- U1 = Ry(angle=self.parameter, target=q, control=p)
1091
+ U1 = Ry(angle=self.parameter, target=q, control=[p]+control)
1030
1092
  return U0 + U1 + U0
1031
1093
  elif self.compile_options == "optimize" and len(self.target) == 4 and exponential_pauli:
1032
1094
  p,r,q,s = self.target
@@ -1035,39 +1097,11 @@ class QubitExcitationImpl(impl.DifferentiableGateImpl):
1035
1097
  U0 += X(target=r, control=p)
1036
1098
  U0 += X(target=q)
1037
1099
  U0 += X(target=s)
1038
- U1 = Ry(angle=-self.parameter, target=p, control=[q,r,s])
1100
+ U1 = Ry(angle=-self.parameter, target=p, control=[q,r,s]+control)
1039
1101
  return U0 + U1 + U0.dagger()
1040
1102
  else:
1041
- return Trotterized(angle=self.parameter, generator=self.generator, steps=1)
1042
-
1043
- def shifted_gates(self):
1044
- if not self.assume_real:
1045
- # following https://arxiv.org/abs/2104.05695
1046
- s = 0.5 * np.pi
1047
- shifts = [s, -s, 3 * s, -3 * s]
1048
- coeff1 = 0.25 * (np.sqrt(2) + 1)/np.sqrt(2)
1049
- coeff2 = 0.25 * (np.sqrt(2) - 1)/np.sqrt(2)
1050
- coefficients = [coeff1, -coeff1, -coeff2, coeff2]
1051
- circuits = []
1052
- for i, shift in enumerate(shifts):
1053
- shifted_gate = copy.deepcopy(self)
1054
- shifted_gate.parameter += shift
1055
- circuits.append((coefficients[i], shifted_gate))
1056
- return circuits
1057
-
1058
- r = 0.25
1059
- s = 0.5*np.pi
1060
-
1061
- Up1 = copy.deepcopy(self)
1062
- Up1._parameter = self.parameter+s
1063
- Up1 = QCircuit.wrap_gate(Up1)
1064
- Up2 = GeneralizedRotation(angle=s, generator=self.p0, eigenvalues_magnitude=r) # controls are in p0
1065
- Um1 = copy.deepcopy(self)
1066
- Um1._parameter = self.parameter-s
1067
- Um1 = QCircuit.wrap_gate(Um1)
1068
- Um2 = GeneralizedRotation(angle=-s, generator=self.p0, eigenvalues_magnitude=r) # controls are in p0
1069
-
1070
- return [(2.0 * r, Up1 + Up2), (-2.0 * r, Um1 + Um2)]
1103
+ return Trotterized(angle=self.parameter, generator=self.generator, steps=1, control=self.control)
1104
+
1071
1105
 
1072
1106
  def _convert_Paulistring(paulistring: typing.Union[PauliString, str, dict]) -> PauliString:
1073
1107
  '''
@@ -871,22 +871,69 @@ def compute_meas_alloc(varbs, obt=None, tbts=None, n_qubits=None, mix=0.0):
871
871
  for i in range(len(meas_alloc)):
872
872
  if meas_alloc[i] < 1e-6:
873
873
  meas_alloc[i] = 1e-6
874
- return np.real( meas_alloc/np.sum(meas_alloc) )
874
+ return np.real( meas_alloc/np.sum(meas_alloc))
875
875
 
876
- def get_orb_rot(U, tol = 1e-12):
876
+ def depth_eff_order_mf(N):
877
+ '''
878
+ Returns index ordering for linear depth circuit
879
+
880
+ For example N = 6 gives elimination order
881
+ [ 0. 0. 0. 0. 0. 0.]
882
+ [ 7. 0. 0. 0. 0. 0.]
883
+ [ 5. 10. 0. 0. 0. 0.]
884
+ [ 3. 8. 12. 0. 0. 0.]
885
+ [ 2. 6. 11. 14. 0. 0.]
886
+ [ 1. 4. 9. 13. 15. 0.]
887
+ '''
888
+ l = []
889
+ for c in range(0, N-1):
890
+ for r in range(1, N):
891
+ if r - c > 0:
892
+ l.append([r, c, 2*c - r + N])
893
+ l.sort(key=lambda x: x[2])
894
+ return [(a[0], a[1]) for a in l]
895
+
896
+ def get_orb_rot(U, qubit_list = [], method = 'short', tol = 1e-12):
877
897
  '''
878
898
  Construct sequence of orbital rotations that implement mean-field unitary given by NxN unitary U
879
899
  Currently supported only for real U
880
900
  '''
881
- U[abs(U) < tol] = 0
882
- theta, phi = given_rotation(U, tol)
901
+
902
+ N = len(U)
883
903
  C = tq.QCircuit()
884
- for i, p in enumerate(phi):
885
- C += n_rotation(i, p)
904
+
905
+ if qubit_list == []:
906
+ qubit_list = list(range(N))
907
+
908
+ assert len(qubit_list) >= len(U), 'Insufficient qubits for orbital rotation' #check if sufficient qubits
909
+
910
+ U[abs(U) < tol] = 0
911
+
912
+ if method == 'naive':
913
+ theta_list, phi_list = given_rotation(U, tol)
914
+ elif method == 'short':
915
+ ordering = depth_eff_order_mf(N)
916
+ theta_list, phi_list = given_rotation(U, tol, ordering)
917
+
918
+ #filter
919
+ theta_list_new = []
920
+ for i, theta in enumerate(theta_list):
921
+ if abs(theta[0] % (2*np.pi)) > tol:
922
+ theta_list_new.append(theta)
923
+
924
+ phi_list_new = []
925
+ for i, phi in enumerate(phi_list):
926
+ if abs(phi[0]) > tol:
927
+ phi_list_new.append(phi)
928
+
929
+ for phi in phi_list_new:
930
+ C += n_rotation(qubit_list[phi[1]], phi[0])
931
+
886
932
  gates = []
887
- for th in theta:
888
- gates.append(orbital_rotation(th[1], th[2], -th[0]))
933
+ for theta in theta_list_new:
934
+ gates.append(orbital_rotation(qubit_list[theta[1]], qubit_list[theta[2]], -theta[0]))
889
935
  gates.reverse()
936
+
890
937
  for gate in gates:
891
938
  C += gate
892
939
  return C
@@ -894,7 +941,7 @@ def get_orb_rot(U, tol = 1e-12):
894
941
  def orbital_rotation(i, j, theta):
895
942
  '''
896
943
  Implements exp(theta(a^_i a_j - a^_j a_i))
897
- Right now restricted to |i-j| <= 1
944
+ Right now restricted to |i-j| <= 1 and jordan wigner transform.
898
945
  '''
899
946
  if abs(i-j) <= 1:
900
947
  return tq.gates.CNOT(control=i, target=j) + tq.gates.Ry(angle=2*theta, target=i, control=j) + tq.gates.CNOT(control=i, target=j)
@@ -902,25 +949,39 @@ def orbital_rotation(i, j, theta):
902
949
  def n_rotation(i, phi):
903
950
  return tq.gates.Rz(angle = phi, target=i)
904
951
 
905
- def given_rotation(U, tol = 1e-12): #verified
952
+ def given_rotation(U, tol = 1e-12, ordering = None):
906
953
  '''
907
954
  Decomposes the Unitary into a set of Rz by angle phi and Givens Rotations by angle theta.
908
955
  Input:
909
- U (np.array):
956
+ U (np.array): Rotation matrix
957
+ tol: tolerance for U elements
910
958
  '''
911
- #filter small values
959
+
912
960
  U[abs(U) < tol] = 0
913
961
  n = U.shape[0]
962
+
914
963
  theta = []
915
964
  phi = []
916
- for c in range(n):
917
- for r in range(n-1, c, -1):
965
+ if ordering is None:
966
+ for c in range(n):
967
+ for r in range(n-1, c, -1):
968
+ t = np.arctan2(-U[r,c], U[r-1,c])
969
+ theta.append((t, r, r-1))
970
+
971
+ g = givens_matrix(n,r,r-1,t)
972
+ U = np.dot(g, U)
973
+ else:
974
+ for r, c in ordering:
918
975
  t = np.arctan2(-U[r,c], U[r-1,c])
919
- theta.append([t, r, r-1])
976
+ theta.append((t, r, r-1))
977
+
920
978
  g = givens_matrix(n,r,r-1,t)
921
979
  U = np.dot(g, U)
980
+
922
981
  for i in range(n):
923
- phi.append(np.angle(U[i,i]))
982
+ ph = np.angle(U[i,i])
983
+ phi.append((ph, i))
984
+
924
985
  return theta, phi
925
986
 
926
987
  def givens_matrix(n, p, q, theta): #verified
@@ -214,12 +214,15 @@ def do_svd(h_ferm, n_elec):
214
214
  return all_uops, cartan_obt, cartan_tbts, meas_alloc
215
215
 
216
216
 
217
- def get_fermion_wise(H, U):
217
+ def get_fermion_wise(H, U, qubit_list = []):
218
+ '''
219
+ Return z_form and orbital rotations over qubits at qubit_list
220
+ '''
218
221
 
219
222
  H = ferm.cartan_tbt_to_ferm(H, spin_orb = True)
220
223
  z_form = QubitHamiltonian(jordan_wigner(H))
221
224
 
222
- circuit = ferm.get_orb_rot(U, tol = 1e-12)
225
+ circuit = ferm.get_orb_rot(U, qubit_list=qubit_list, tol = 1e-12)
223
226
  return [z_form, circuit]
224
227
 
225
228
  def get_init_ops(h_ferm, mol_name, calc_type, spin_orb, save=True):
@@ -209,7 +209,7 @@ def Sm(qubit) -> QubitHamiltonian:
209
209
  Initialize
210
210
 
211
211
  .. math::
212
- \\frac{1}{2} \\left( \\sigma_x + i \\sigma_y \\right)
212
+ \\frac{1}{2} \\left( \\sigma_x - i \\sigma_y \\right)
213
213
 
214
214
  Parameters
215
215
  ----------
@@ -334,11 +334,12 @@ class OptimizerGD(Optimizer):
334
334
 
335
335
 
336
336
  if not self.silent:
337
+ self.__dx = numpy.asarray(self.__dx)
337
338
  print("%3i %+15.8f %+7.2e %7.3e %7.3e %s"
338
339
  % (step,
339
340
  e,
340
341
  e-last,
341
- numpy.max(abs(self.__dx)),
342
+ numpy.max([abs(x) for x in self.__dx]),
342
343
  numpy.sqrt(numpy.average(self.__dx**2)),
343
344
  comment))
344
345