Skip to content

Commit

Permalink
Update qasm.py (#335)
Browse files Browse the repository at this point in the history
* Update qasm.py
* Update ci_chemistry_psi4.yml (psi4 --> conda-forge channel)
* Update README.md
  • Loading branch information
kottmanj authored Mar 20, 2024
1 parent 3ded2f3 commit 423c8e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_chemistry_psi4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -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 .
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
34 changes: 24 additions & 10 deletions src/tequila/circuit/qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 423c8e7

Please sign in to comment.