From d33d50e1a43c883e7b39a062290a715d02b50612 Mon Sep 17 00:00:00 2001 From: TimWeaving Date: Tue, 8 Oct 2024 17:36:09 +0100 Subject: [PATCH] Removed py3dmol as a dependency --- poetry.lock | 16 +--------------- pyproject.toml | 1 - symmer/utils.py | 34 ---------------------------------- tests/test_symmer_utils.py | 13 +------------ 4 files changed, 2 insertions(+), 62 deletions(-) diff --git a/poetry.lock b/poetry.lock index 74091227..bf3ad990 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2558,20 +2558,6 @@ files = [ [package.extras] tests = ["pytest"] -[[package]] -name = "py3dmol" -version = "2.4.0" -description = "An IPython interface for embedding 3Dmol.js views in Jupyter notebooks" -optional = false -python-versions = "*" -files = [ - {file = "py3Dmol-2.4.0-py2.py3-none-any.whl", hash = "sha256:e7d27ffdf9326850e4c6dac55ec047ce023ffaf87d8032278982a4d3d78d3973"}, - {file = "py3Dmol-2.4.0.tar.gz", hash = "sha256:5cbeb125771abdedf051845bbb8df30306338a92a1852c9934c3ec85ba482a78"}, -] - -[package.extras] -ipython = ["IPython"] - [[package]] name = "pycodestyle" version = "2.8.0" @@ -3790,4 +3776,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "17a853a1287459499c42a8559227f2b5d1ef4ddedd10f531f02ffce9baa9ebb5" +content-hash = "0ebae7433e51c9b3d5a63553a4d6ab65144b44e911cd041d345d4b49e563cdc3" diff --git a/pyproject.toml b/pyproject.toml index 3a246ffb..87b55f8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,6 @@ ray = "2.10" sphinx-design = "^0.5.0" myst-nb = "^0.17.2" sphinx-copybutton = "^0.5.2" -py3dmol = "^2.0.4" scipy = "1.9.3" urllib3 = "1.26.6" diff --git a/symmer/utils.py b/symmer/utils.py index a961f971..c61c2b49 100644 --- a/symmer/utils.py +++ b/symmer/utils.py @@ -3,7 +3,6 @@ import scipy as sp from typing import List, Tuple, Union from functools import reduce -import py3Dmol from scipy.sparse import csr_matrix from scipy.sparse import kron as sparse_kron from symmer.operators.utils import _rref_binary @@ -225,39 +224,6 @@ def gram_schmidt_from_quantum_state(state:Union[np.array, list, QuantumState]) - return M - -def Draw_molecule( - xyz_string: str, width: int = 400, height: int = 400, style: str = "sphere" - ) -> py3Dmol.view: - """Draw molecule from xyz string. - - Note if molecule has unrealistic bonds, then style should be sphere. Otherwise stick style can be used - which shows bonds. - - TODO: more styles at http://3dmol.csb.pitt.edu/doc/$3Dmol.GLViewer.html - - Args: - xyz_string (str): xyz string of molecule - width (int): width of image - height (int): Height of image - style (str): py3Dmol style ('sphere' or 'stick') - - Returns: - view (py3dmol.view object). Run view.show() method to print molecule. - """ - view = py3Dmol.view(width=width, height=height) - view.addModel(xyz_string, "xyz") - if style == "sphere": - view.setStyle({'sphere': {"radius": 0.2}}) - elif style == "stick": - view.setStyle({'stick': {}}) - else: - raise ValueError(f"unknown py3dmol style: {style}") - - view.zoomTo() - return view - - def get_sparse_matrix_large_pauliwordop(P_op: PauliwordOp) -> csr_matrix: """ In order to build the sparse matrix (e.g. above 18 qubits), this function goes through each pauli term diff --git a/tests/test_symmer_utils.py b/tests/test_symmer_utils.py index 52601126..e714dc45 100644 --- a/tests/test_symmer_utils.py +++ b/tests/test_symmer_utils.py @@ -1,10 +1,9 @@ from symmer.operators import PauliwordOp, QuantumState -from symmer.utils import (exact_gs_energy, random_anitcomm_2n_1_PauliwordOp,Draw_molecule, +from symmer.utils import (exact_gs_energy, random_anitcomm_2n_1_PauliwordOp, tensor_list, gram_schmidt_from_quantum_state, product_list, get_sparse_matrix_large_pauliwordop, matrix_allclose) import numpy as np from openfermion import QubitOperator -import py3Dmol H2_sto3g = {'qubit_encoding': 'jordan_wigner', 'unit': 'angstrom', @@ -446,16 +445,6 @@ def test_gram_schmidt_from_quantum_state_numpy_array(): assert np.allclose(U_gram[:, 0], psi_norm), 'first column of U_gram not correct' assert np.allclose(U_gram @ U_gram.conj().T, np.eye(2 ** nq)), 'U_gram not unitary' - -def test_Draw_molecule(): - - xyz = H2_sto3g['geometry'] - viewer_sphere = Draw_molecule(xyz, width=400, height=400, style='sphere') - assert isinstance(viewer_sphere, py3Dmol.view) - - viewer_stick = Draw_molecule(xyz, width=400, height=400, style='stick') - assert isinstance(viewer_stick, py3Dmol.view) - def test_get_sparse_matrix_large_pauliwordop(): for nq in range(2,6): n_terms = 10*nq