From 423c8e7bf147565c5a1bb457165a1572f322a1e1 Mon Sep 17 00:00:00 2001 From: "J. S. Kottmann" Date: Wed, 20 Mar 2024 22:41:21 +0100 Subject: [PATCH] Update qasm.py (#335) * Update qasm.py * Update ci_chemistry_psi4.yml (psi4 --> conda-forge channel) * Update README.md --- .github/workflows/ci_chemistry_psi4.yml | 4 +-- README.md | 4 +-- src/tequila/circuit/qasm.py | 34 +++++++++++++++++-------- 3 files changed, 28 insertions(+), 14 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 . 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. diff --git a/src/tequila/circuit/qasm.py b/src/tequila/circuit/qasm.py index 7eb567ee..16a35b57 100644 --- a/src/tequila/circuit/qasm.py +++ b/src/tequila/circuit/qasm.py @@ -313,19 +313,33 @@ 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))) + 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"): - 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))) + angle = 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() + name = "".join(name) + G = getattr(gates, name) + 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) return gates.U(theta=angles[0], phi=angles[1], lambd=angles[2],