Skip to main content

Setting up a JijZept subscription

To use JijZept, please contact Jij Inc. After that, you can start using JijZept.

In the following, we assume that you have already created an account and applied to Jij Inc. for the use of JijZept.

JijZept Project

You can sign up with JijZept, you cannot start yet. You have to create a project at JijZept portal.

This section describes the project and the process to the start with the contract.

Create project

After the sign up, you can create a project at JijZept portal.
The credit for using JijZept is granted on a per-project.

Please create a credit before submitting a request for credit to be granted.

After the creating an account, then go to "TopPage" in the upper right corner to "Projects" and create a project with an appropriate name using "+ Add New Project".

Request to grant credits to projects

Once you have created a project, please give Jij the name of the project you have created, and after Jij completes the process, the project will be credited.

Once a project has been credited, you can see the credits on the "TopPage".

The Admin user who created the project can add "Standard members" to the project. After having the person you wish to add as a "Standard member" create a JijZept account, please go to the Project page and add the user to the "Standard member" list using the email address from the account.

Adding a "Standard member" to a project allows you to share the credits granted to that project.

Once you have confirmed that your project has been credited, proceed as follows to obtain an API key.

API key

Go to the "Top Page" of the portal site. It is OK if "Product" is displayed as shown in the figure below.

note

If you do not have any Projects, please create a Project and apply to Jij, or ask to be added as a Member to the Project of someone who has applied to use the service in the same organization.

Next, navigate to the "home page" of the portal site. If you have selected a project with a subscription, the remaining credits and available solver names will be displayed. Also, if you select the "Product" pencil mark, a detailed product screen will appear as shown below.

Next, click on the API key or "+ Add Keys" to generate a key. You can use any name as the name of the key. Here, we will use "Sample."

You will be issued a "primary key" to use. Please copy it and use it when using JijZept's Python SDK.

Getting started

Install the Python SDK required to use JijZept from PyPI.

info

To use JijZept, we recommend that you build a Python virtual environment using the standard Python tools such as venv or poetry, and configure JijZept in the virtual environment.

pip install jijmodeling jijzept

Now let's throw a request to JijZept. Create a working directory and navigate to it.

mkdir jijzept_sample; cd jijzept_sample

Create the following Python file named sample.py.

import jijzept as jz

sampler = jz.JijSASampler(token="**API key**", url="https://api.jijzept.com")
response = sampler.sample_qubo({("q0", "q1"): -1})
print(response.record)

For the first argument of jz.JijSASampler, enter the "API key" you just created in the portal site's Dashboard.

When this script is executed, the Python SDK throws the problem to JijZept and displays the solution given by the solver, as shown below.

rec.array([([1, 1], -1., 1)],
dtype=[('sample', 'i1', (2,)), ('energy', '<f8'), ('num_occurrences', '<i8')])
info

You can see a log of issues sent to JijZept by setting the environment variable JIJZEPT_VERBOSE.

uploading instance ...
submitting query ...
submitted to the queue.
Your solution_id is e90902ajfa09039204ajdfada.
rec.array([([1, 1], -1., 1)],
dtype=[('sample', 'i1', (2,)), ('energy', '<f8'), ('num_occurrences', '<i8')])

You are now ready to get started with JijZept! Next, we will show you how to write the token and API URL settings in a configuration file separate from the source code.

info

If the request does not work because a proxy needs to be configured, set the environment variables HTTP_PROXY and HTTPS_PROXY to the host and port of the proxy.

Creating JijZept configuration files

Now, create a configuration file for JijZept using the "API key" you obtained above.

Create a config.toml file with the extension .toml. It is also recommended that you add config.toml to your .gitignore file and place it outside of git's control since this file will contain API keys, etc.

The config.toml file is written as follows

[default]
url = "https://api.jijzept.com/"
token = "0123456789abcdefg"

Set url to "https://api.jijzept.com/". Set token to the "API key" you obtained in portal site.

This completes the initial configuration. Next, let's try to use JijZept with the information described in this config.toml.

Specify the configuration file you described as the config argument instead of the token and url.

from jijzept import JijSASampler

qubo = {('q_0', 'q_1'): -2, ('q_0', 'q_0'): 1}
sampler = JijSASampler(config='config.toml')
response = sampler.sample_qubo(qubo)

JijZept with JijModeling

In this section, we try constructing a simple constrained optimization problem using JijModeling. Then, we solve the model using JijZept.

minidixis.t.ixi=1xi{0,1}\min \sum_i d_i x_i\\ \mathrm{s.t.} \sum_i x_i = 1 \\ x_i \in \{0, 1\}

Next we construct the above model by JijModeling.

JijModeling

import jijmodeling as jm

# one-dimension array
d = jm.Placeholder('d', dim=1)
N = d.shape[0]
# one-dimension binary decision variable array with same shape of `d`.
x = jm.Binary('x', shape=N)
# dummy index which is used in summation.
i = jm.Element('i', N)

problem = jm.Problem('test_problem')
cost = jm.Sum(i, d[i]*x[i])
problem += cost
# constraint
problem += Constraint('one-hot', jm.Sum(i, x[i]) == 1)

Please see jijmodeling documentation for more information.

Solving problems with jijzept

from jijzept import JijSASampler

# instance data for `Placeholder` `d`
data_d = [1.0, 0.1, 2, 1]

sampler = JijSASampler(config='config.toml')
response = sampler.sample_model(
problem,
feed_dict={'d': data_d},
multipliers={'one-hot': 1.0},
search=True,
num_search=10
)

If you use jijmodeling, use .sample_model.

You can also use .sample for BinaryQuadraticModel as provided by OpenJij, or .sample_ising or .sample_qubo for dictionary types.

Here are the arguments for .sample_model.

  • feed_dict: a dictionary of concrete values to be set to variables constructed with Placeholder. Corresponds to the instance in question.
  • multipliers: Sets the value of the multiplier to be used for penalty terms and so on. Placeholders not set in feed_dict will be recognized as undetermined multipliers. The Constraint class is automatically multiplied by the Placeholder class variable by default, so set the value here.
  • search: If True, search for feasible solutions by adjusting the value set in multipliers as the constraint strength. At most num_reads x num_search times annealing will be performed.
  • num_search: You can set the maximum number of parameter updates when search is set to True. However, if a feasible solution is obtained during the update, the number of updates will be less than or equal to the number of updates set in num_search, because the update will stop.