From 1908378d71bbd38885bb787f8bb90ecd8a9e2751 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Mon, 18 Mar 2024 17:32:22 +0100 Subject: [PATCH 01/12] Update qasm.py Fixes issue #333 --- src/tequila/circuit/qasm.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 65878f76..3517662c 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -313,19 +313,26 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister return apply_custom_gate(custom_circuit=custom_circuit, qregisters_values=qregisters_values) if name in ("x", "y", "z", "h", "cx", "cy", "cz", "ch"): - return QCircuit.wrap_gate(gates.impl.QGateImpl(name=(name[1] if name[0] == 'c' else name).upper(), - control=get_qregister(args[0], qregisters) if name[0] == 'c' else None, - target=get_qregister(args[1 if name[0] == 'c' else 0], qregisters))) + G = getattr(gates, name.upper()) + control = get_qregister(args[0], qregisters), get_qregister(args[1], qregisters) + target = get_qregister(args[1 if name[0] == 'c' else 0], qregisters))) + return G(control=control, target=target) + if name in ("ccx", "ccy", "ccz"): - return QCircuit.wrap_gate(gates.impl.QGateImpl(name=name.upper()[2], - control=[get_qregister(args[0], qregisters), get_qregister(args[1], qregisters)], - target=get_qregister(args[2], qregisters))) + G = getattr(gates, name[2].upper()) + control = [get_qregister(args[0], qregisters), get_qregister(args[1], qregisters)] + target = get_qregister(args[2], qregisters))) + return G(control=control, target=target) + if name.startswith("rx(") or name.startswith("ry(") or name.startswith("rz(") or \ name.startswith("crx(") or name.startswith("cry(") or name.startswith("crz("): - return QCircuit.wrap_gate(gates.impl.RotationGateImpl(axis=name[2 if name[0] == 'c' else 1], - angle=get_angle(name)[0], - control=get_qregister(args[0], qregisters) if name[0] == 'c' else None, - target=get_qregister(args[1 if name[0] == 'c' else 0], qregisters))) + name = name.upper() + name = [x for x in name] + name[-1] = name[-1].lower() + name = "".join(name) + G = getattr(gates, name) + return G(angle=get_angle(name)[0],control=get_qregister(args[0], qregisters) if name[0] == 'c' else None,target=get_qregister(args[1 if name[0] == 'c' else 0], qregisters))) + if name.startswith("U("): angles = get_angle(name) return gates.U(theta=angles[0], phi=angles[1], lambd=angles[2], From 02f00d9e5a1543e701f6749706c514a96b0563c7 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Mon, 18 Mar 2024 17:35:53 +0100 Subject: [PATCH 02/12] Update qasm.py --- src/tequila/circuit/qasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 4c9e43eb..028098fc 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -315,7 +315,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister if name in ("x", "y", "z", "h", "cx", "cy", "cz", "ch"): G = getattr(gates, name.upper()) control = get_qregister(args[0], qregisters), get_qregister(args[1], qregisters) - target = get_qregister(args[1 if name[0] == 'c' else 0], qregisters))) + target = get_qregister(args[1 if name[0] == 'c' else 0], qregisters) return G(control=control, target=target) if name in ("ccx", "ccy", "ccz"): From b07aa8cafebf1c978b618d7e8503f67f47e4c55b Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Mon, 18 Mar 2024 17:39:05 +0100 Subject: [PATCH 03/12] Update qasm.py --- src/tequila/circuit/qasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 028098fc..f184dd6e 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -321,7 +321,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister if name in ("ccx", "ccy", "ccz"): G = getattr(gates, name[2].upper()) control = [get_qregister(args[0], qregisters), get_qregister(args[1], qregisters)] - target = get_qregister(args[2], qregisters))) + target = get_qregister(args[2], qregisters) return G(control=control, target=target) if name.startswith("rx(") or name.startswith("ry(") or name.startswith("rz(") or \ From 9e48076af850a83f972219389ff723c1e009b342 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Mon, 18 Mar 2024 17:42:07 +0100 Subject: [PATCH 04/12] Update qasm.py --- src/tequila/circuit/qasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index f184dd6e..ac6a3416 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -331,7 +331,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister name[-1] = name[-1].lower() name = "".join(name) G = getattr(gates, name) - return G(angle=get_angle(name)[0],control=get_qregister(args[0], qregisters) if name[0] == 'c' else None,target=get_qregister(args[1 if name[0] == 'c' else 0], qregisters))) + return G(angle=get_angle(name)[0],control=get_qregister(args[0], qregisters) if name[0] == 'c' else None,target=get_qregister(args[1 if name[0] == 'c' else 0], qregisters)) if name.startswith("U("): angles = get_angle(name) From 2dbe118c7ff53eb18fc1d69c29aaad937eacab56 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Mon, 18 Mar 2024 17:57:59 +0100 Subject: [PATCH 05/12] Update qasm.py --- src/tequila/circuit/qasm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index ac6a3416..0c68abcf 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -315,7 +315,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister if name in ("x", "y", "z", "h", "cx", "cy", "cz", "ch"): G = getattr(gates, name.upper()) control = get_qregister(args[0], qregisters), get_qregister(args[1], qregisters) - target = get_qregister(args[1 if name[0] == 'c' else 0], qregisters) + target = get_qregister(args[1 if name[0] == 'C' else 0], qregisters) return G(control=control, target=target) if name in ("ccx", "ccy", "ccz"): @@ -331,7 +331,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister name[-1] = name[-1].lower() name = "".join(name) G = getattr(gates, name) - return G(angle=get_angle(name)[0],control=get_qregister(args[0], qregisters) if name[0] == 'c' else None,target=get_qregister(args[1 if name[0] == 'c' else 0], qregisters)) + return G(angle=get_angle(name)[0],control=get_qregister(args[0], qregisters) if name[0] == 'C' else None,target=get_qregister(args[1 if name[0] == 'C' else 0], qregisters)) if name.startswith("U("): angles = get_angle(name) From da7854cfa4f555d62658a7b1a6d206d429e1c48c Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 14:08:49 +0100 Subject: [PATCH 06/12] Update qasm.py --- src/tequila/circuit/qasm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 0c68abcf..6076058d 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -314,8 +314,11 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister if name in ("x", "y", "z", "h", "cx", "cy", "cz", "ch"): G = getattr(gates, name.upper()) - control = get_qregister(args[0], qregisters), get_qregister(args[1], qregisters) - target = get_qregister(args[1 if name[0] == 'C' else 0], qregisters) + target = get_qregister(args[0], qregisters) + control = None + if name[0] == c: + control = get_qregister(args[0], qregisters) + target = get_qregister(args[1], qregisters) return G(control=control, target=target) if name in ("ccx", "ccy", "ccz"): From a0352bcd047b7aaf4e101587e699c82e269e8406 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 14:46:08 +0100 Subject: [PATCH 07/12] Update qasm.py --- src/tequila/circuit/qasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 6076058d..9aa8345e 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -316,7 +316,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister G = getattr(gates, name.upper()) target = get_qregister(args[0], qregisters) control = None - if name[0] == c: + if name[0].lower() == 'c': control = get_qregister(args[0], qregisters) target = get_qregister(args[1], qregisters) return G(control=control, target=target) From 3ad9644c7a4632c7b68b97ff13465cd950ab8560 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 22:12:49 +0100 Subject: [PATCH 08/12] Update qasm.py gettting closer --- src/tequila/circuit/qasm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 9aa8345e..5ccd0dac 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -329,6 +329,9 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister if name.startswith("rx(") or name.startswith("ry(") or name.startswith("rz(") or \ name.startswith("crx(") or name.startswith("cry(") or name.startswith("crz("): + get_angle(name)[0] + i = name.find('(') + name = name[0:i] name = name.upper() name = [x for x in name] name[-1] = name[-1].lower() From 827d080141d8d84676df658b55cf82225935beaf Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 22:19:28 +0100 Subject: [PATCH 09/12] Update qasm.py --- src/tequila/circuit/qasm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 5ccd0dac..c2e2f930 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -329,7 +329,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister if name.startswith("rx(") or name.startswith("ry(") or name.startswith("rz(") or \ name.startswith("crx(") or name.startswith("cry(") or name.startswith("crz("): - get_angle(name)[0] + angle = get_angle(name)[0] i = name.find('(') name = name[0:i] name = name.upper() @@ -337,7 +337,7 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister name[-1] = name[-1].lower() name = "".join(name) G = getattr(gates, name) - return G(angle=get_angle(name)[0],control=get_qregister(args[0], qregisters) if name[0] == 'C' else None,target=get_qregister(args[1 if name[0] == 'C' else 0], qregisters)) + return G(angle=angle,control=get_qregister(args[0], qregisters) if name[0] == 'C' else None,target=get_qregister(args[1 if name[0] == 'C' else 0], qregisters)) if name.startswith("U("): angles = get_angle(name) From a6738739182df3055902d9d106f10d44a98c47e0 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 22:27:08 +0100 Subject: [PATCH 10/12] Update qasm.py --- src/tequila/circuit/qasm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index c2e2f930..16a35b57 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -313,12 +313,13 @@ def parse_command(command: str, custom_gates_map: Dict[str, QCircuit], qregister return apply_custom_gate(custom_circuit=custom_circuit, qregisters_values=qregisters_values) if name in ("x", "y", "z", "h", "cx", "cy", "cz", "ch"): - G = getattr(gates, name.upper()) target = get_qregister(args[0], qregisters) control = None if name[0].lower() == 'c': control = get_qregister(args[0], qregisters) target = get_qregister(args[1], qregisters) + name = name[1] + G = getattr(gates, name.upper()) return G(control=control, target=target) if name in ("ccx", "ccy", "ccz"): From c10286e02468ac3c33f34dc649e11b7d2f3eef2e Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 22:29:36 +0100 Subject: [PATCH 11/12] Update ci_chemistry_psi4.yml --- .github/workflows/ci_chemistry_psi4.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_chemistry_psi4.yml b/.github/workflows/ci_chemistry_psi4.yml index ef9c1e3a..98481972 100644 --- a/.github/workflows/ci_chemistry_psi4.yml +++ b/.github/workflows/ci_chemistry_psi4.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8] + python-version: [3.9] steps: - uses: actions/checkout@v2 @@ -50,7 +50,7 @@ jobs: source $HOME/.bashrc source $CONDABASE/bin/activate conda activate test_psi4 - conda install psi4 python=3.8 -c psi4 + conda install psi4 python=3.9 -c conda-forge python -m pip install --upgrade pip python -m pip install -r requirements.txt python -m pip install -e . From 8a6b90e21317fefcb1abfaf0b90b111b6fe13477 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 22:30:16 +0100 Subject: [PATCH 12/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3cec3281..b415c3f3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Tequila can execute the underlying quantum expectation values on state of the ar - [talks and slides](https://kottmanj.github.io/talks_and_material/) # Installation -Recommended Python version is 3.8-3.9. +Recommended Python version is 3.9 - 3.10. Tequila supports linux, osx and windows. However, not all optional dependencies are supported on windows. ## Install from PyPi @@ -267,7 +267,7 @@ Currently supported ### [Psi4](https://github.com/psi4/psi4). In a conda environment this can be installed with ```bash -conda install psi4 -c psi4 +conda install psi4 -c conda-forge ``` Here is a small [tutorial](https://nbviewer.org/github/tequilahub/tequila-tutorials/blob/main/chemistry/ChemistryModule.ipynb) that illustrates the usage.