Skip to content

Commit

Permalink
Remove qubovert requirement (#910)
Browse files Browse the repository at this point in the history
Removes the `qubovert` requirement in `gss` as it was primarily used for
typing purposes. It should be an optional install for users like in the
MIS notebook.
  • Loading branch information
bharat-thotakura authored Feb 24, 2024
1 parent be96674 commit 0733c56
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 24 deletions.
10 changes: 9 additions & 1 deletion cirq-superstaq/cirq_superstaq/daily_integration_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pylint: disable=missing-function-docstring,missing-class-docstring
"""Integration checks that run daily (via Github action) between client and prod server."""
from __future__ import annotations

import os

import cirq
Expand Down Expand Up @@ -323,7 +325,13 @@ def test_submit_to_hilbert_qubit_sorting(service: css.Service) -> None:


def test_submit_qubo(service: css.Service) -> None:
test_qubo = {(0,): -1, (1,): -1, (2,): -1, (0, 1): 2, (1, 2): 2}
test_qubo: dict[tuple[()] | tuple[str | int] | tuple[str | int, str | int], int | float] = {
(0,): -1,
(1,): -1,
(2,): -1,
(0, 1): 2,
(1, 2): 2,
}
serialized_result = service.submit_qubo(
test_qubo, target="toshiba_bifurcation_simulator", method="dry-run"
)
Expand Down
12 changes: 10 additions & 2 deletions docs/source/apps/max_sharpe_ratio_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@
" %pip install --quiet yfinance\n",
" print(\"Installed yfinance.\")\n",
" print(\"You may need to restart the kernel to import newly installed packages.\")\n",
" import yfinance as yf"
" import yfinance as yf\n",
"\n",
"try:\n",
" import qubovert as qv\n",
"except ImportError:\n",
" print(\"Installing qubovert...\")\n",
" %pip install --quiet qubovert\n",
" print(\"Installed qubovert.\")\n",
" print(\"You may need to restart the kernel to import newly installed packages.\")\n",
" import qubovert as qv"
]
},
{
Expand All @@ -74,7 +83,6 @@
"import pandas as pd\n",
"import sympy\n",
"from tqdm import tqdm\n",
"import qubovert as qv\n",
"\n",
"warnings.filterwarnings(\"ignore\", category=DeprecationWarning)"
]
Expand Down
16 changes: 9 additions & 7 deletions general-superstaq/general_superstaq/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from collections.abc import Sequence
from typing import Any

import qubovert as qv

import general_superstaq as gss


Expand Down Expand Up @@ -161,7 +159,7 @@ def get_targets(

def submit_qubo(
self,
qubo: qv.QUBO,
qubo: dict[tuple[()] | tuple[str | int] | tuple[str | int, str | int], int | float],
target: str,
repetitions: int = 1000,
method: str | None = None,
Expand All @@ -173,12 +171,16 @@ def submit_qubo(
the energy landscape from the given objective function known as output solutions.
Args:
qubo: A `qv.QUBO` object.
target: The target to submit the qubo.
qubo: A dictionary representing the QUBO object. The tuple keys represent the
boolean variables of the QUBO and the values represent the coefficients.
As an example, for a QUBO with integer coefficients = 2*a + a*b - 5*b*c - 3
(where a, b, and c are boolean variables), the corresponding dictionary format
would be {('a',): 2, ('a', 'b'): 1, ('b', 'c'): -5, (): -3}.
target: The target to submit the QUBO.
repetitions: Number of times that the execution is repeated before stopping.
method: The parameter specifying method of QUBO solving execution. Currently,
will either be the "dry-run" option which runs on dwave's simulated annealer,
or defaults to none and sends it directly to the specified target.
will either be the "dry-run" option which runs on dwave's simulated annealer,
or defaults to `None` and sends it directly to the specified target.
max_solutions: A parameter that specifies the max number of output solutions.
Returns:
Expand Down
9 changes: 7 additions & 2 deletions general-superstaq/general_superstaq/service_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# pylint: disable=missing-function-docstring,missing-class-docstring
from __future__ import annotations

import os
import secrets
import tempfile
from unittest import mock

import pytest
import qubovert as qv

import general_superstaq as gss
from general_superstaq.testing import RETURNED_TARGETS, TARGET_LIST
Expand Down Expand Up @@ -91,7 +92,11 @@ def test_update_user_role(
def test_submit_qubo(
mock_post_request: mock.MagicMock,
) -> None:
example_qubo = qv.QUBO({(0,): 1.0, (1,): 1.0, (0, 1): -2.0})
example_qubo: dict[tuple[()] | tuple[str | int] | tuple[str | int, str | int], int | float] = {
(0,): 1.0,
(1,): 1.0,
(0, 1): -2.0,
}
target = "toshiba_bifurcation_simulator"
repetitions = 10

Expand Down
17 changes: 10 additions & 7 deletions general-superstaq/general_superstaq/superstaq_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from collections.abc import Callable, Mapping, Sequence
from typing import Any

import qubovert as qv
import requests

import general_superstaq as gss
Expand Down Expand Up @@ -336,7 +335,7 @@ def compile(self, json_dict: dict[str, str]) -> dict[str, str]:

def submit_qubo(
self,
qubo: qv.QUBO,
qubo: dict[tuple[()] | tuple[str | int] | tuple[str | int, str | int], int | float],
target: str,
repetitions: int = 1000,
method: str | None = None,
Expand All @@ -346,12 +345,16 @@ def submit_qubo(
given target.
Args:
qubo: A `qv.QUBO` object.
target: The target to submit the qubo.
qubo: A dictionary representing the QUBO object. The tuple keys represent the
boolean variables of the QUBO and the values represent the coefficients.
As an example, for a QUBO with integer coefficients = 2*a + a*b - 5*b*c - 3
(where a, b, and c are boolean variables), the corresponding dictionary format
would be {('a',): 2, ('a', 'b'): 1, ('b', 'c'): -5, (): -3}.
target: The target to submit the QUBO.
repetitions: Number of times that the execution is repeated before stopping.
method: The parameter specifying method of QUBO solving execution. Currently,
will either be the "dry-run" option which runs on dwave's simulated annealer,
or defauls to none and sends it directly to the specified target.
will either be the "dry-run" option which runs on dwave's simulated annealer,
or defaults to `None` and sends it directly to the specified target.
max_solutions: A parameter that specifies the max number of output solutions.
Returns:
Expand Down Expand Up @@ -384,7 +387,7 @@ def supercheq(
"""Performs a POST request on the `/supercheq` endpoint.
Args:
files: List of files specified as binary using ints.
files: List of files specified as binary using integers.
For example: [[1, 0, 1], [1, 1, 1]].
num_qubits: Number of qubits to run Supercheq on.
depth: The depth of the circuits to run Supercheq on.
Expand Down
12 changes: 9 additions & 3 deletions general-superstaq/general_superstaq/superstaq_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=missing-function-docstring,missing-class-docstring
from __future__ import annotations

import contextlib
import io
import json
import os
from unittest import mock

import pytest
import qubovert as qv
import requests

import general_superstaq as gss
Expand Down Expand Up @@ -645,15 +646,20 @@ def test_superstaq_client_submit_qubo(mock_post: mock.MagicMock) -> None:
api_key="to_my_heart",
)

example_qubo = qv.QUBO({(0,): 1.0, (1,): 1.0, (0, 1): -2.0})
example_qubo: dict[tuple[()] | tuple[str | int] | tuple[str | int, str | int], int | float] = {
("a",): 2.0,
("a", "b"): 1.0,
("b", 0): -5,
(): -3.0,
}
target = "toshiba_bifurcation_simulator"
repetitions = 10
client.submit_qubo(
example_qubo, target, repetitions=repetitions, method="dry-run", max_solutions=1
)

expected_json = {
"qubo": [((0,), 1.0), ((1,), 1.0), ((0, 1), -2.0)],
"qubo": [(("a",), 2.0), (("a", "b"), 1.0), (("b", 0), -5), ((), -3.0)],
"target": target,
"shots": repetitions,
"method": "dry-run",
Expand Down
1 change: 0 additions & 1 deletion general-superstaq/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
numpy>=1.21.0
pydantic>=1.10.7
qubovert>=1.2.3
requests>=2.26.0
10 changes: 9 additions & 1 deletion qiskit-superstaq/qiskit_superstaq/daily_integration_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pylint: disable=missing-function-docstring,missing-class-docstring
"""Integration checks that run daily (via Github action) between client and prod server."""
from __future__ import annotations

import os

import general_superstaq as gss
Expand Down Expand Up @@ -279,7 +281,13 @@ def test_submit_to_hilbert_qubit_sorting(provider: qss.SuperstaqProvider) -> Non


def test_submit_qubo(provider: qss.SuperstaqProvider) -> None:
test_qubo = {(0,): -1, (1,): -1, (2,): -1, (0, 1): 2, (1, 2): 2}
test_qubo: dict[tuple[()] | tuple[str | int] | tuple[str | int, str | int], int | float] = {
(0,): -1,
(1,): -1,
(2,): -1,
(0, 1): 2,
(1, 2): 2,
}
serialized_result = provider.submit_qubo(
test_qubo, target="toshiba_bifurcation_simulator", method="dry-run"
)
Expand Down

0 comments on commit 0733c56

Please sign in to comment.