From af3cd11a4220dd1a8e6ab52f50a6356d08eab0fb Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Thu, 29 Mar 2018 18:19:36 -0400 Subject: [PATCH] style: Minor PEP8 fixes --- docs/ising_qaoa.rst | 2 +- grove/pyqaoa/qaoa.py | 2 +- grove/tests/ising/test_ising.py | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/ising_qaoa.rst b/docs/ising_qaoa.rst index 2ed332b..92aeb84 100644 --- a/docs/ising_qaoa.rst +++ b/docs/ising_qaoa.rst @@ -227,7 +227,7 @@ we set the following biases on \\( \\sigma_{0} \\) and \\( \\sigma_{1}\\): qvm_connection = api.QVMConnection() - J = {(0,1,2): -3} + J = {(0, 1, 2): -3} h = {0: 1, 1: -1} We can now run the algorithm ten times with step size 2 to collect statistics (this might take a couple of minutes): diff --git a/grove/pyqaoa/qaoa.py b/grove/pyqaoa/qaoa.py index 8103aab..612f48d 100644 --- a/grove/pyqaoa/qaoa.py +++ b/grove/pyqaoa/qaoa.py @@ -139,7 +139,7 @@ def get_parameterized_program(self): cost_para_programs = [] driver_para_programs = [] - for idx in range(self.steps): + for _ in range(self.steps): cost_list = [] driver_list = [] for cost_pauli_sum in self.cost_ham: diff --git a/grove/tests/ising/test_ising.py b/grove/tests/ising/test_ising.py index b03b44f..a9f36c8 100644 --- a/grove/tests/ising/test_ising.py +++ b/grove/tests/ising/test_ising.py @@ -13,8 +13,8 @@ def test_energy_value(): assert(np.isclose(ener_ising, -9.9)) - J = {(0, 1, 2): 1.2, (0, 1, 2, 3): 2.5 , (0, 2, 3): 0.5, (1, 3): 3.1} - h = {0: -2.4, 1: 5.2 , 3: -0.3} + J = {(0, 1, 2): 1.2, (0, 1, 2, 3): 2.5, (0, 2, 3): 0.5, (1, 3): 3.1} + h = {0: -2.4, 1: 5.2, 3: -0.3} sol = [1, -1, -1, 1] ener_ising = energy_value(h, J, sol) @@ -42,7 +42,7 @@ def test_ising_mock(): with patch("pyquil.api.QVMConnection") as cxn: # Mock the response cxn.run_and_measure.return_value = [[1, 0, 1, 0]] - cxn.expectation.return_value = [0, 0, 0, 0] # dummy + cxn.expectation.return_value = [0, 0, 0, 0] # dummy # checkerboard with couplings J = {(0, 1): 1, (0, 2): 1, (1, 3): 1, (2, 3): 1} @@ -56,7 +56,7 @@ def test_ising_mock(): with patch("pyquil.api.QVMConnection") as cxn: # Mock the response cxn.run_and_measure.return_value = [[1, 0, 1, 0]] - cxn.expectation.return_value = [0, 0, 0, 0] # dummy + cxn.expectation.return_value = [0, 0, 0, 0] # dummy # checkerboard with biases J = {} @@ -70,7 +70,7 @@ def test_ising_mock(): with patch("pyquil.api.QVMConnection") as cxn: # Mock the response cxn.run_and_measure.return_value = [[1, 0, 1, 0, 1]] - cxn.expectation.return_value = [0, 0, 0, 0, 0] # dummy + cxn.expectation.return_value = [0, 0, 0, 0, 0] # dummy J = {(0, 4): -1} h = {0: 1, 1: -1, 2: 1, 3: -1} @@ -83,10 +83,10 @@ def test_ising_mock(): with patch("pyquil.api.QVMConnection") as cxn: # Mock the response cxn.run_and_measure.return_value = [[0, 1, 1, 0]] - cxn.expectation.return_value = [0, 0, 0, 0, 0, 0, 0] # dummy + cxn.expectation.return_value = [0, 0, 0, 0, 0, 0, 0] # dummy - J = {(0, 1, 2): 1.2, (0, 1, 2, 3): 2.5 , (0, 2, 3): 0.5, (1, 3): 3.1} - h = {0: -2.4, 1: 5.2 , 3: -0.3} + J = {(0, 1, 2): 1.2, (0, 1, 2, 3): 2.5, (0, 2, 3): 0.5, (1, 3): 3.1} + h = {0: -2.4, 1: 5.2, 3: -0.3} p = 1 most_freq_string_ising, energy_ising, circuit = ising_qaoa(h, J, num_steps=p, vqe_option=None, connection=cxn) @@ -96,7 +96,7 @@ def test_ising_mock(): with patch("pyquil.api.QVMConnection") as cxn: # Mock the response cxn.run_and_measure.return_value = [[0, 1, 1, 0]] - cxn.expectation.return_value = [0, 0, 0, 0, 0, 0, 0] # dummy + cxn.expectation.return_value = [0, 0, 0, 0, 0, 0, 0] # dummy swap_mixer = [] for i in range(4): @@ -105,8 +105,8 @@ def test_ising_mock(): swap_mixer.append(PauliSum([PauliTerm("X", i, 0.5) * PauliTerm("X", j, 1.0)])) swap_mixer.append(PauliSum([PauliTerm("Y", i, 0.5) * PauliTerm("Y", j, 1.0)])) - J = {(0, 1, 2): 1.2, (0, 1, 2, 3): 2.5 , (0, 2, 3): 0.5, (1, 3): 3.1} - h = {0: -2.4, 1: 5.2 , 3: -0.3} + J = {(0, 1, 2): 1.2, (0, 1, 2, 3): 2.5, (0, 2, 3): 0.5, (1, 3): 3.1} + h = {0: -2.4, 1: 5.2, 3: -0.3} p = 1 most_freq_string_ising, energy_ising, circuit = ising_qaoa(h, J, driver_operators=swap_mixer, num_steps=p, vqe_option=None, connection=cxn)