--- sd_hide_title: true hide-toc: true --- # NEC (clients-NECVA2Client)= ## NEC Vector Annealing (VA) Service 2.0 [NEC](https://jpn.nec.com/nec-vector-annealing-service/) provides the QUBO solver, which runs on the vector supercomputer SX-Aurora TSUBASA. The Amplify SDK provides {py:class}`~amplify.NECVA2Client` which calls the NEC Vector Annealing Service 2.0 API with automatically detected and configured request parameters. :**Solver specification**: ```{list-table} :width: 100% :widths: 2 3 * - Client class - {py:class}`amplify.NECVA2Client` * - [Execution parameters](amplify.NECVA2Client.parameters){sup}`1` - {py:class}`amplify.NECVA2Client.Parameters` * - [Execution result](amplify.Result.client_result){sup}`2` - {py:class}`amplify.NECVA2Client.Result` * - [Execution time](amplify.Result.execution_time) ([details](#clients-NECVA2Client-exectime)) - {py:attr}`amplify.NECVA2Client.Result.Timing.execution_time` * - API method{sup}`3` - SAC Service Client (Python) * - API reference - [{bdg-info}`📖 User Guide`](/../_static/nec_vector_annealing_service_2.0_user_guide_v4.pdf) ``` 1: Corresponding to [API reference "3-3-2 solve_params"](/../_static/nec_vector_annealing_service_2.0_user_guide_v4.pdf) 2: Corresponding to [API reference "3-4. Response"](/../_static/nec_vector_annealing_service_2.0_user_guide_v4.pdf) 3: No need for additional installation ```{csv-table} :header-rows: 1 :stub-columns: 1 :width: 100% :widths: 1 1 1 1 1 ,Binary variable,Ising variable,Integer variable,Real variable Objective function,2nd,\-,\-,\- Equality constraint,\*,\-,\-,\- Inequality constraint,\*,\-,\-,\- ``` \*: Several 1st and 2nd order constraints described later are supported. :**Client class**: In addition to the [common interface of the client class](#client-common-interface), it has the following attributes. ```{list-table} :width: 100% :header-rows: 1 :widths: 1 1 3 * - Attribute - Data type - Details * - {py:attr}`~amplify.NECVA2Client.set_fixed` - {py:class}`bool` - If set as {py:obj}`True`, `fixed` constraints are detected from the model's constraints as many as possible and are passed to the `fixed` parameter which is a flip option. (Default: {py:obj}`True`) * - {py:attr}`~amplify.NECVA2Client.set_onehot` - {py:class}`bool` - If set as {py:obj}`True`, `onehot` constraints are detected from the model's constraints as many as possible and are passed to the `onehot` parameter which is a flip option. (Default: {py:obj}`True`) * - {py:attr}`~amplify.NECVA2Client.set_andzero` - {py:class}`bool` - If set as {py:obj}`True`, `andzero` constraints are detected from the model's constraints as many as possible and are passed to the `andzero` parameter which is a flip option. (Default: {py:obj}`True`) * - {py:attr}`~amplify.NECVA2Client.set_orone` - {py:class}`bool` - If set as {py:obj}`True`, `orone` constraints are detected from the model's constraints as many as possible and are passed to the `orone` parameter which is a flip option. (Default: {py:obj}`True`) * - {py:attr}`~amplify.NECVA2Client.set_supplement` - {py:class}`bool` - If set as {py:obj}`True`, `supplement` constraints are detected from the model's constraints as many as possible and are passed to the `supplement` parameter which is a flip option. (Default: {py:obj}`True`) * - {py:attr}`~amplify.NECVA2Client.set_maxone` - {py:class}`bool` - If set as {py:obj}`True`, `maxone` constraints are detected from the model's constraints as many as possible and are passed to the `maxone` parameter which is a flip option. (Default: {py:obj}`True`) * - {py:attr}`~amplify.NECVA2Client.set_minmaxone` - {py:class}`bool` - If set as {py:obj}`True`, `minmaxone` constraints are detected from the model's constraints as many as possible and are passed to the `minmaxone` parameter which is a flip option. (Default: {py:obj}`True`) ``` Flip option constraints are detected only when a constraint expression is set that matches the following form, including coefficients. $q_1, q_2, \dots , q_N$ ($N$ is a natural number) are binary variables independent of each other and $m, n, k$ are integer constants. ```{list-table} :width: 100% :header-rows: 1 :widths: 1 3 * - Attribute to set to {py:obj}`True` - Form of Constraint to detect * - {py:attr}`~amplify.NECVA2Client.set_fixed` - $q_1 + k = k$ $q_1 + k = k + 1$ * - {py:attr}`~amplify.NECVA2Client.set_onehot` - $q_1 + q_2 + \cdots + q_N + k = k + 1$ * - {py:attr}`~amplify.NECVA2Client.set_andzero` - $q_1 + q_2 + \cdots + q_N + k \leq k + N - 1$ $n q_1 q_2 + k = k$ * - {py:attr}`~amplify.NECVA2Client.set_orone` - $q_1 + q_2 + \cdots + q_N + k \geq k + 1$ $n (q_1 - 1)(q_2 - 1) + k = k$ * - {py:attr}`~amplify.NECVA2Client.set_supplement` - $n (q_1 - q_2 q_3) + k = k$ * - {py:attr}`~amplify.NECVA2Client.set_maxone` - $q_1 + q_2 + \cdots + q_N + k \leq n \quad (0 \leq n - k \leq N)$ * - {py:attr}`~amplify.NECVA2Client.set_minmaxone` - $m \leq q_1 + q_2 + \cdots + q_N + k \leq n \quad (0 \leq m - k, n - k \leq N)$ ``` ```{note} Regardless of whether the flip option is enabled, penalty functions of constraints are added to the objective function as needed. ``` (clients-NECVA2Client-exectime)= :**Execution time**: The NEC VA Service 2.0 returns the execution time for each sampling of VA but does not return the total processing time taken to find the solution. Therefore, in addition to the sampling time, the {py:class}`~amplify.NECVA2Client` independently measures and returns the response time of the `solve_qubo()` API of the SAC Service Client, the execution time of the the VA (which is also included in the response time), and the queue time. These timing attributes are stored in the `~amplify.NECVA2Client.Result.timing` attribute of the result class. ```{list-table} :width: 100% :header-rows: 1 :widths: 2 3 * - Attribute - Details * - {py:attr}`amplify.NECVA2Client.Result.Result.time` - VA sampling time for each read. * - {py:attr}`amplify.NECVA2Client.Result.Timing.solve_qubo_time` - Execution time of the `solve_qubo` Python API * - {py:attr}`amplify.NECVA2Client.Result.Timing.execution_time` - Execution time of the VA (including network overhead and queue time) * - {py:attr}`amplify.NECVA2Client.Result.Timing.queue_time` - Queue time ``` :**Configuration example**: ```{testcode} from amplify import NECVA2Client client = NECVA2Client() # Set API token client.token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Run in speed mode client.parameters.vector_mode = "speed" ``` :**Execution example**: ```python from amplify import VariableGenerator, Model, solve # Define decision variables and the objective function g = VariableGenerator() q = g.array("Binary", 2) f = q[0] * q[1] + q[0] - q[1] + 1 # Create a model model = Model(f) # Run the solver result = solve(model, client) # Print API execution time print(result.execution_time) ``` Obtain the solver version: ```python >>> client.version '2.0.2' ```