From d5ce7d7d7576bf54d23d1edb638664845a3084d6 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Tue, 26 Jul 2022 15:45:03 +0200 Subject: [PATCH 1/9] Modify get_max_sum_from_clause function --- .gitignore | 2 ++ vqf/preprocessing.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 50e17d5..fbdb9df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.pyc /vqf-venv/* +*.ipynb +/venv/* diff --git a/vqf/preprocessing.py b/vqf/preprocessing.py index e373a08..c5fee41 100644 --- a/vqf/preprocessing.py +++ b/vqf/preprocessing.py @@ -237,15 +237,20 @@ def create_basic_clauses(m_dict, p_dict, q_dict, z_dict, apply_preprocessing=Tru clauses (list): See module documentation at the top. """ clauses = [] - n_c = len(m_dict) + int(np.ceil(len(m_dict)/2)) - 1 + + n_p = len(m_dict) + n_q = int(np.ceil(len(m_dict)/2)) + n_c = n_p + n_q - 1 + for i in range(n_c): clause = 0 for j in range(i+1): - clause += q_dict.get(j, 0) * p_dict.get(i-j, 0) - clause += -m_dict.get(i, 0) + clause += q_dict.get(j, 0) * p_dict.get(i-j, 0) # term 1 in eq 2 + + clause += -m_dict.get(i, 0) # term 3 in eq 2 for j in range(i+1): - clause += z_dict.get((j, i), 0) + clause += z_dict.get((j, i), 0) # term 2 in eq 2 if type(clause) == int: clause = sympify(clause) @@ -264,7 +269,7 @@ def create_basic_clauses(m_dict, p_dict, q_dict, z_dict, apply_preprocessing=Tru z_dict[(i, j)] = 0 for j in range(1, n_c): - clause += - 2**j * z_dict.get((i, i+j), 0) + clause += - 2**j * z_dict.get((i, i+j), 0) # term 4 in eq 2 if clause == 0: clause = sympify(clause) @@ -286,11 +291,15 @@ def get_max_sum_from_clause(clause): """ max_sum = 0 + if clause.func == Mul: if isinstance(clause.args[0], Number) and clause.args[0] > 0: max_sum += int(clause.args[0]) + elif isinstance(term.args[0], Number) and term.args[0] < 0: + pass else: max_sum += 1 + elif clause.func == Add: for term in clause.args: if isinstance(term, Number): From 513b4f4490768d583e19128f987f184bf7e13753 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Tue, 11 Apr 2023 23:12:34 +0200 Subject: [PATCH 2/9] Revert "Modify get_max_sum_from_clause function" This reverts commit d5ce7d7d7576bf54d23d1edb638664845a3084d6. --- .gitignore | 2 -- vqf/preprocessing.py | 19 +++++-------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index fbdb9df..50e17d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ *.pyc /vqf-venv/* -*.ipynb -/venv/* diff --git a/vqf/preprocessing.py b/vqf/preprocessing.py index c5fee41..e373a08 100644 --- a/vqf/preprocessing.py +++ b/vqf/preprocessing.py @@ -237,20 +237,15 @@ def create_basic_clauses(m_dict, p_dict, q_dict, z_dict, apply_preprocessing=Tru clauses (list): See module documentation at the top. """ clauses = [] - - n_p = len(m_dict) - n_q = int(np.ceil(len(m_dict)/2)) - n_c = n_p + n_q - 1 - + n_c = len(m_dict) + int(np.ceil(len(m_dict)/2)) - 1 for i in range(n_c): clause = 0 for j in range(i+1): - clause += q_dict.get(j, 0) * p_dict.get(i-j, 0) # term 1 in eq 2 - - clause += -m_dict.get(i, 0) # term 3 in eq 2 + clause += q_dict.get(j, 0) * p_dict.get(i-j, 0) + clause += -m_dict.get(i, 0) for j in range(i+1): - clause += z_dict.get((j, i), 0) # term 2 in eq 2 + clause += z_dict.get((j, i), 0) if type(clause) == int: clause = sympify(clause) @@ -269,7 +264,7 @@ def create_basic_clauses(m_dict, p_dict, q_dict, z_dict, apply_preprocessing=Tru z_dict[(i, j)] = 0 for j in range(1, n_c): - clause += - 2**j * z_dict.get((i, i+j), 0) # term 4 in eq 2 + clause += - 2**j * z_dict.get((i, i+j), 0) if clause == 0: clause = sympify(clause) @@ -291,15 +286,11 @@ def get_max_sum_from_clause(clause): """ max_sum = 0 - if clause.func == Mul: if isinstance(clause.args[0], Number) and clause.args[0] > 0: max_sum += int(clause.args[0]) - elif isinstance(term.args[0], Number) and term.args[0] < 0: - pass else: max_sum += 1 - elif clause.func == Add: for term in clause.args: if isinstance(term, Number): From e8895824040364dc7e2b465b3e7b04cb2c7d1cc5 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Wed, 12 Apr 2023 00:19:36 +0200 Subject: [PATCH 3/9] Fixing version conflict --- .gitignore | 4 ++++ pip_freeze.txt | 62 +++++++++++++++++++++++++----------------------- requirements.txt | 6 ++--- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 50e17d5..6f627da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.pyc /vqf-venv/* +.venv/ +build/ +dist/ +vqf.egg-info/ diff --git a/pip_freeze.txt b/pip_freeze.txt index b9ed869..9c8cead 100644 --- a/pip_freeze.txt +++ b/pip_freeze.txt @@ -1,30 +1,32 @@ -antlr4-python3-runtime==4.7.2 -certifi==2019.3.9 -chardet==3.0.4 -cycler==0.10.0 -decorator==4.4.0 -funcsigs==1.0.2 -future==0.17.1 -idna==2.8 -immutables==0.6 -kiwisolver==1.1.0 -matplotlib==3.1.0rc2 -mock==3.0.5 -mpmath==1.1.0 -msgpack==0.6.1 -networkx==2.3 -numpy==1.16.3 -pyparsing==2.4.0 -pyquil==2.6.0 -python-dateutil==2.8.0 -python-rapidjson==0.7.1 -pyzmq==18.0.1 -quantum-grove==2.0.0b0 -requests==2.21.0 -rpcq==2.5.1 -ruamel.yaml==0.15.94 -scipy==1.3.0rc2 -six==1.12.0 -sympy==1.4 -typing==3.6.6 -urllib3==1.24.3 \ No newline at end of file +antlr4-python3-runtime +certifi +chardet +cycler +decorator +funcsigs +future +idna +immutables +kiwisolver +matplotlib +mock +mpmath +msgpack +networkx +numpy +pyparsing +pyquil +python-dateutil +python-rapidjson +pyzmq +quantum-grove +requests +rpcq +ruamel.yaml +scipy +six +sympy +typing +urllib3 +poetry +setuptools \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ee3cc8c..2705e8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -sympy==1.4 -pandas==0.24.2 -pytest==4.6.2 \ No newline at end of file +sympy +pandas +pytest From 18ec6b1e15d817492ad29a894875c8e70239dd3a Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Wed, 12 Apr 2023 00:20:10 +0200 Subject: [PATCH 4/9] Making the package instalable --- pyproject.toml | 15 +++++++++++++++ setup.py | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 pyproject.toml create mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..228eb68 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "vqf" +version = "0.1.0" +description = "This repository contains implementation of the algorithm presented in the article \"Variational Quantum Factoring\", by Eric R. Anschuetz, Jonathan P. Olson, Alán Aspuru-Guzik, Yudong Cao." +authors = ["Michal Stechly"] +license = "MIT" +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.10" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c4abcc3 --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup, find_packages + +setup( + name="vqf", + version="0.1.0", + description="This repository contains implementation of the algorithm presented in the article \"Variational Quantum Factoring\", by Eric R. Anschuetz, Jonathan P. Olson, Alán Aspuru-Guzik, Yudong Cao.", + author="Michal Stechly", + license="MIT", + packages=find_packages(), + python_requires=">=3.10", + install_requires=[ + # add any package dependencies here + ], + classifiers=[ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], +) From e4de76b0498664c82b11285a43da49fed8346981 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Wed, 12 Apr 2023 08:43:56 +0200 Subject: [PATCH 5/9] Adding dependencies to setup.py --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index c4abcc3..ae1bf98 100644 --- a/setup.py +++ b/setup.py @@ -8,9 +8,7 @@ license="MIT", packages=find_packages(), python_requires=">=3.10", - install_requires=[ - # add any package dependencies here - ], + install_requires=open("requirements.txt").readlines(), classifiers=[ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", From 4990b6193d75ebb6ca7e06bd256c2409a0d3d106 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah <67621237+Mostafa-Atallah2020@users.noreply.github.com> Date: Sun, 18 Jun 2023 01:14:58 +0300 Subject: [PATCH 6/9] Update setup.py --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index ae1bf98..51cb323 100644 --- a/setup.py +++ b/setup.py @@ -3,16 +3,16 @@ setup( name="vqf", version="0.1.0", - description="This repository contains implementation of the algorithm presented in the article \"Variational Quantum Factoring\", by Eric R. Anschuetz, Jonathan P. Olson, Alán Aspuru-Guzik, Yudong Cao.", + description="This repository contains an implementation of the algorithm presented in the article \"Variational Quantum Factoring\", by Eric R. Anschuetz, Jonathan P. Olson, Alán Aspuru-Guzik, Yudong Cao.", author="Michal Stechly", - license="MIT", + license="Apache", packages=find_packages(), python_requires=">=3.10", install_requires=open("requirements.txt").readlines(), classifiers=[ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", - "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: Apache License", "Operating System :: OS Independent", ], ) From ad53d642022a0127013ef138d774d2d23b3dd386 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Sun, 18 Jun 2023 01:34:08 +0300 Subject: [PATCH 7/9] Add installation guidelines on README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 95b31b3..788e444 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,15 @@ I do not claim that the preprocessing part is perfect, though from manual inspec - Current version of code doesn't produce correct results for number 1465 (factors: 293 and 5). This doesn't happen always (see note about randomness above). - There are still some additional rules to add / cases to fix (see TODO in `preprocessing.py`). - In cases exhibiting some form of symmetry (as described [here](https://arxiv.org/pdf/1411.6758.pdf)), procedure of calculating squared overlap might give wrong results. The fix for numbers 56153 and 291311, has been hardcoded, but it's far from being elegant and general solution. + +## Installation + +To install this package, run the following command: + +``` +pip install git+https://github.com/mstechly/vqf.git +``` + +Please note that the installation requires the correct versions of `pyquil` and `grove` as specified in the `setup.py` file. + +Please let me know if you have any further questions or need additional information! From 3a2a070805435379721110d7d6bd02019dcd0757 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Sun, 18 Jun 2023 01:35:08 +0300 Subject: [PATCH 8/9] Update README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 788e444..175d7e1 100644 --- a/README.md +++ b/README.md @@ -74,4 +74,3 @@ pip install git+https://github.com/mstechly/vqf.git Please note that the installation requires the correct versions of `pyquil` and `grove` as specified in the `setup.py` file. -Please let me know if you have any further questions or need additional information! From f15e520228fb848f76e738b715ecb131ea455346 Mon Sep 17 00:00:00 2001 From: Mostafa Atallah Date: Sun, 18 Jun 2023 01:38:04 +0300 Subject: [PATCH 9/9] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 228eb68..758516c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "vqf" version = "0.1.0" description = "This repository contains implementation of the algorithm presented in the article \"Variational Quantum Factoring\", by Eric R. Anschuetz, Jonathan P. Olson, Alán Aspuru-Guzik, Yudong Cao." authors = ["Michal Stechly"] -license = "MIT" +license = "Apache" readme = "README.md" [tool.poetry.dependencies]