Skip to content

Commit

Permalink
Rename var_form to ansatz (#31)
Browse files Browse the repository at this point in the history
* change var_form to ansatz

* fix lint of test/regressor
  • Loading branch information
t-imamichi authored Apr 1, 2021
1 parent a7532ba commit 3a6a456
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
11 changes: 11 additions & 0 deletions test/algorithms/regressors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
18 changes: 10 additions & 8 deletions test/algorithms/regressors/test_neural_network_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
# that they have been altered from the originals.

""" Test Neural Network Regressor """
from ddt import ddt, data
from qiskit import QuantumCircuit, Aer
from qiskit.algorithms.optimizers import L_BFGS_B, COBYLA
from test import QiskitMachineLearningTestCase

import numpy as np
from ddt import data, ddt

from qiskit import Aer, QuantumCircuit
from qiskit.algorithms.optimizers import COBYLA, L_BFGS_B
from qiskit.circuit import Parameter
from qiskit.utils import QuantumInstance

from qiskit_machine_learning.algorithms.regressors import NeuralNetworkRegressor
from qiskit_machine_learning.neural_networks import TwoLayerQNN
from test import QiskitMachineLearningTestCase

import numpy as np


@ddt
Expand All @@ -43,6 +43,7 @@ def setUp(self):
num_samples = 20
eps = 0.2

# pylint: disable=invalid-name
lb, ub = -np.pi, np.pi
self.X = (ub - lb) * np.random.rand(num_samples, 1) + lb
self.y = np.sin(self.X[:, 0]) + eps * (2 * np.random.rand(num_samples) - 1)
Expand All @@ -55,7 +56,8 @@ def setUp(self):
('bfgs', 'statevector'),
('bfgs', 'qasm'),
)
def test_classifier_with_opflow_qnn(self, config):
def test_regressor_with_opflow_qnn(self, config):
""" Test Neural Network Regressor with Opflow QNN (Two Layer QNN)."""
opt, q_i = config

num_qubits = 1
Expand Down
3 changes: 1 addition & 2 deletions test/algorithms/regressors/test_qsvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
""" Test QSVR """

import unittest

from test import QiskitMachineLearningTestCase

import numpy as np
Expand All @@ -22,8 +21,8 @@
from qiskit.circuit.library import ZZFeatureMap
from qiskit.utils import QuantumInstance
from qiskit_machine_learning.algorithms import QSVR
from qiskit_machine_learning.kernels import QuantumKernel
from qiskit_machine_learning.exceptions import QiskitMachineLearningError
from qiskit_machine_learning.kernels import QuantumKernel


class TestQSVR(QiskitMachineLearningTestCase):
Expand Down
21 changes: 10 additions & 11 deletions test/algorithms/regressors/test_vqr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
""" Test Neural Network Regressor """

import unittest

from qiskit.circuit import Parameter

from test import QiskitMachineLearningTestCase

import numpy as np
from ddt import ddt, data
from ddt import data, ddt

from qiskit import Aer, QuantumCircuit
from qiskit.algorithms.optimizers import COBYLA, L_BFGS_B
from qiskit.circuit import Parameter
from qiskit.utils import QuantumInstance

from qiskit_machine_learning.algorithms import VQR


Expand All @@ -47,6 +45,7 @@ def setUp(self):
num_samples = 20
eps = 0.2

# pylint: disable=invalid-name
lb, ub = -np.pi, np.pi
self.X = (ub - lb) * np.random.rand(num_samples, 1) + lb
self.y = np.sin(self.X[:, 0]) + eps * (2 * np.random.rand(num_samples) - 1)
Expand All @@ -68,7 +67,7 @@ def setUp(self):
def test_vqr(self, config):
""" Test VQR."""

opt, q_i, has_var_form = config
opt, q_i, has_ansatz = config

if q_i == 'statevector':
quantum_instance = self.sv_quantum_instance
Expand All @@ -86,16 +85,16 @@ def test_vqr(self, config):
feature_map = QuantumCircuit(num_qubits, name='fm')
feature_map.ry(param_x, 0)

if has_var_form:
if has_ansatz:
param_y = Parameter('y')
var_form = QuantumCircuit(num_qubits, name='vf')
var_form.ry(param_y, 0)
ansatz = QuantumCircuit(num_qubits, name='vf')
ansatz.ry(param_y, 0)
else:
var_form = None
ansatz = None

# construct regressor
regressor = VQR(feature_map=feature_map,
var_form=var_form,
ansatz=ansatz,
optimizer=optimizer,
quantum_instance=quantum_instance)

Expand Down

0 comments on commit 3a6a456

Please sign in to comment.