diff --git a/docs/en/_toc.yml b/docs/en/_toc.yml index 861a3ce..a28e132 100644 --- a/docs/en/_toc.yml +++ b/docs/en/_toc.yml @@ -23,6 +23,7 @@ parts: - caption: Advanced chapters: - file: advanced/generation + - file: advanced/serialize - caption: Reference chapters: - url: https://jij-inc-jijmodeling.readthedocs-hosted.com/en/ diff --git a/docs/en/advanced/serialize.ipynb b/docs/en/advanced/serialize.ipynb new file mode 100644 index 0000000..5c1d40b --- /dev/null +++ b/docs/en/advanced/serialize.ipynb @@ -0,0 +1,87 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4c9e7601-a3f2-496b-88a0-88e76bd18e7c", + "metadata": {}, + "source": [ + "# Serialization\n", + "\n", + "JijModeling models can be easily serialized to [Protobuf](https://protobuf.dev) using the {py:func}`jijmodeling.to_protobuf` function or the {py:meth}`Problem.to_protobuf ` method." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "545186b3-caf3-4c92-a0a9-c7515923bffd", + "metadata": { + "execution": { + "iopub.execute_input": "2026-03-12T10:23:10.321467Z", + "iopub.status.busy": "2026-03-12T10:23:10.321374Z", + "iopub.status.idle": "2026-03-12T10:23:10.376977Z", + "shell.execute_reply": "2026-03-12T10:23:10.376503Z" + } + }, + "outputs": [], + "source": [ + "import jijmodeling as jm\n", + "\n", + "problem = jm.Problem(\"my problem\")\n", + "N = problem.Placeholder(\"N\", dtype=jm.DataType.NATURAL)\n", + "x = problem.BinaryVar(\"x\", shape=(N,))\n", + "problem += x.sum()\n", + "\n", + "serialized = problem.to_protobuf()" + ] + }, + { + "cell_type": "markdown", + "id": "033466c5-157a-4b25-90b7-f9d38f81067d", + "metadata": {}, + "source": [ + "To deserialize, use {py:func}`jijmodeling.from_protobuf` or {py:meth}`Problem.from_protobuf `." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "271e3da1-63a5-448e-ab1a-ccff3476b945", + "metadata": { + "execution": { + "iopub.execute_input": "2026-03-12T10:23:10.378484Z", + "iopub.status.busy": "2026-03-12T10:23:10.378387Z", + "iopub.status.idle": "2026-03-12T10:23:10.380514Z", + "shell.execute_reply": "2026-03-12T10:23:10.380057Z" + } + }, + "outputs": [], + "source": [ + "deserialized = jm.from_protobuf(serialized)" + ] + } + ], + "metadata": { + "jupytext": { + "default_lexer": "ipython3" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/ja/_toc.yml b/docs/ja/_toc.yml index 249bc8d..f12eff2 100644 --- a/docs/ja/_toc.yml +++ b/docs/ja/_toc.yml @@ -24,6 +24,7 @@ parts: - caption: Advanced chapters: - file: advanced/generation + - file: advanced/serialize - caption: Reference chapters: - url: https://jij-inc-jijmodeling.readthedocs-hosted.com/en/ diff --git a/docs/ja/advanced/serialize.ipynb b/docs/ja/advanced/serialize.ipynb new file mode 100644 index 0000000..fc9cfc8 --- /dev/null +++ b/docs/ja/advanced/serialize.ipynb @@ -0,0 +1,87 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4c9e7601-a3f2-496b-88a0-88e76bd18e7c", + "metadata": {}, + "source": [ + "# 数理モデルのシリアライズ\n", + "\n", + "JijModeling で作られた数理モデルは、[Protobuf](https://protobuf.dev) で簡単にシリアライズできます。具体的には、{py:func}`jijmodeling.to_protobuf`関数か`Problem.to_protobuf `メソッドを使えばシリアライズできます。" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b5807c3d-8bd3-4d3e-92bd-6cfa802cd625", + "metadata": { + "execution": { + "iopub.execute_input": "2026-03-13T08:01:47.482919Z", + "iopub.status.busy": "2026-03-13T08:01:47.482825Z", + "iopub.status.idle": "2026-03-13T08:01:47.536758Z", + "shell.execute_reply": "2026-03-13T08:01:47.536332Z" + } + }, + "outputs": [], + "source": [ + "import jijmodeling as jm\n", + "\n", + "problem = jm.Problem(\"my problem\")\n", + "N = problem.Placeholder(\"N\", dtype=jm.DataType.NATURAL)\n", + "x = problem.BinaryVar(\"x\", shape=(N,))\n", + "problem += x.sum()\n", + "\n", + "serialized = problem.to_protobuf()" + ] + }, + { + "cell_type": "markdown", + "id": "cd5e556f-94d3-4d72-a088-eb86bc0d01f2", + "metadata": {}, + "source": [ + "デシリアライズは、{py:func}`jijmodeling.from_protobuf` か{py:meth}`Problem.from_protobuf `で行えます。" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "fb7345c2-2252-4c3a-ae46-9e6318a4fa9a", + "metadata": { + "execution": { + "iopub.execute_input": "2026-03-13T08:01:47.538446Z", + "iopub.status.busy": "2026-03-13T08:01:47.538315Z", + "iopub.status.idle": "2026-03-13T08:01:47.540574Z", + "shell.execute_reply": "2026-03-13T08:01:47.540170Z" + } + }, + "outputs": [], + "source": [ + "deserialized = jm.from_protobuf(serialized)" + ] + } + ], + "metadata": { + "jupytext": { + "default_lexer": "ipython3" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/markdowns/en/advanced/serialize.md b/markdowns/en/advanced/serialize.md new file mode 100644 index 0000000..01ac8e9 --- /dev/null +++ b/markdowns/en/advanced/serialize.md @@ -0,0 +1,33 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.19.1 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +# Serialization + +JijModeling models can be easily serialized to [Protobuf](https://protobuf.dev) using the {py:func}`jijmodeling.to_protobuf` function or the {py:meth}`Problem.to_protobuf ` method. + +```{code-cell} ipython3 +import jijmodeling as jm + +problem = jm.Problem("my problem") +N = problem.Placeholder("N", dtype=jm.DataType.NATURAL) +x = problem.BinaryVar("x", shape=(N,)) +problem += x.sum() + +serialized = problem.to_protobuf() +``` + +To deserialize, use {py:func}`jijmodeling.from_protobuf` or {py:meth}`Problem.from_protobuf `. + +```{code-cell} ipython3 +deserialized = jm.from_protobuf(serialized) +``` diff --git a/markdowns/ja/advanced/serialize.md b/markdowns/ja/advanced/serialize.md new file mode 100644 index 0000000..68fa0e7 --- /dev/null +++ b/markdowns/ja/advanced/serialize.md @@ -0,0 +1,33 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.19.1 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +# 数理モデルのシリアライズ + +JijModeling で作られた数理モデルは、[Protobuf](https://protobuf.dev) で簡単にシリアライズできます。具体的には、{py:func}`jijmodeling.to_protobuf`関数か`Problem.to_protobuf `メソッドを使えばシリアライズできます。 + +```{code-cell} ipython3 +import jijmodeling as jm + +problem = jm.Problem("my problem") +N = problem.Placeholder("N", dtype=jm.DataType.NATURAL) +x = problem.BinaryVar("x", shape=(N,)) +problem += x.sum() + +serialized = problem.to_protobuf() +``` + +デシリアライズは、{py:func}`jijmodeling.from_protobuf` か{py:meth}`Problem.from_protobuf `で行えます。 + +```{code-cell} ipython3 +deserialized = jm.from_protobuf(serialized) +```