Skip to content

Commit

Permalink
Cleanup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wbernoudy committed Dec 13, 2024
1 parent 567a784 commit 22a7764
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dwave/optimization/_model.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _Graph:
def is_locked(self) -> bool: ...
def iter_constraints(self) -> collections.abc.Iterator[ArraySymbol]: ...
def iter_decisions(self) -> collections.abc.Iterator[Symbol]: ...
def iter_inputs(self) -> collections.abc.Iterator[Symbol]: ...
def iter_inputs(self) -> collections.abc.Iterator[ArraySymbol]: ...
def iter_symbols(self) -> collections.abc.Iterator[Symbol]: ...
def lock(self): ...
def minimize(self, value: ArraySymbol): ...
Expand Down
3 changes: 1 addition & 2 deletions dwave/optimization/_model.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ from libcpp.utility cimport move
from libcpp.vector cimport vector

from dwave.optimization.libcpp.array cimport Array as cppArray
from dwave.optimization.libcpp.graph cimport DecisionNode as cppDecisionNode, Graph as cppGraph
from dwave.optimization.libcpp.nodes cimport InputNode as cppInputNode
from dwave.optimization.libcpp.graph cimport DecisionNode as cppDecisionNode
from dwave.optimization.states cimport States
from dwave.optimization.states import StateView
from dwave.optimization.symbols cimport symbol_from_ptr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#pragma once

#include <vector>

#include "dwave-optimization/array.hpp"
#include "dwave-optimization/graph.hpp"

Expand Down Expand Up @@ -49,7 +47,7 @@ class InputNode : public ArrayOutputMixin<ArrayNode> {

bool integral() const override { return integral_; };

void initialize_state(State& state) const override {
[[noreturn]] void initialize_state(State& state) const override {
throw std::logic_error(
"InputNode must have state explicity initialized (with `initialize_state(state, "
"data)`)");
Expand Down
2 changes: 1 addition & 1 deletion dwave/optimization/libcpp/nodes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from libcpp.vector cimport vector

from dwave.optimization.libcpp cimport span, variant
from dwave.optimization.libcpp.array cimport Array, Slice
from dwave.optimization.libcpp.graph cimport ArrayNode, Graph, Node
from dwave.optimization.libcpp.graph cimport ArrayNode, Node
from dwave.optimization.libcpp.state cimport State


Expand Down
6 changes: 3 additions & 3 deletions dwave/optimization/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def input(
):
r"""Create an "input" symbol. This functions similarly to a decision variable,
in that it takes no predecessors, but its state will always be set manually
(not by any solver). Used as a placeholder for input to the expression.
(not by any solver). Used as a placeholder for input to an expression or model.
The output of the symbol is always a scalar (0-dimensional) array.
Expand All @@ -126,7 +126,7 @@ def input(
validate the state when set manually.
Note that the order in which inputs are added to the expression matters and is
used by other nodes (see :class:`~dwave.optimization.symbols.NaryReduce`) to
used by other symbols (see :class:`~dwave.optimization.symbols.NaryReduce`) to
infer how arguments are supplied to the expression during evaluation.
Args:
Expand Down Expand Up @@ -660,7 +660,7 @@ def unlock(self):
self.states._reset_intermediate_states()


class UnsupportedExpression(Exception):
class UnsupportedExpressionError(Exception):
"""An exception for when an expression is unsupported in a certain
use-case, e.g. an expression which has non-scalar symbols is used to
create a :class:`~dwave.optimization.symbols.NaryReduce` symbol.
Expand Down
7 changes: 3 additions & 4 deletions dwave/optimization/symbols.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import collections.abc
import json
import numbers
import tempfile

cimport cpython.object
import cython
Expand Down Expand Up @@ -101,7 +100,7 @@ from dwave.optimization.libcpp.nodes cimport (
XorNode as cppXorNode,
)
from dwave.optimization.model cimport ArraySymbol, _Graph, Symbol
from dwave.optimization.model import Expression, UnsupportedExpression
from dwave.optimization.model import Expression, UnsupportedExpressionError
from dwave.optimization.states cimport States

__all__ = [
Expand Down Expand Up @@ -2496,13 +2495,13 @@ cdef class NaryReduce(ArraySymbol):

# some errors may not contain an associated node
if node_ptr_int is None:
return UnsupportedExpression(message)
return UnsupportedExpressionError(message)

# get a symbol from the supplied node pointer (encoded as an int)
cdef uintptr_t node_ptr_val = node_ptr_int
cdef cppNode* node_ptr = reinterpret_cast[cppNodePtr](<void *>node_ptr_val)
cdef Symbol symbol = symbol_from_ptr(expression, node_ptr)
return UnsupportedExpression(message, symbol)
return UnsupportedExpressionError(message, symbol)

@staticmethod
def _from_symbol(Symbol symbol):
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/nodes/test_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "catch2/catch_test_macros.hpp"
#include "dwave-optimization/graph.hpp"
#include "dwave-optimization/nodes/constants.hpp"
#include "dwave-optimization/nodes/testing.hpp"

namespace dwave::optimization {

Expand Down
4 changes: 2 additions & 2 deletions tests/test_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ def test_invalid_expressions(self):
self.assertTrue(False, "should raise exception")
except Exception as e:
self.assertIsInstance(
e, dwave.optimization.model.UnsupportedExpression
e, dwave.optimization.model.UnsupportedExpressionError
)
self.assertRegex(str(e), "scalar")
self.assertTrue(inp5.equals(e.symbol))
Expand All @@ -1937,7 +1937,7 @@ def test_invalid_expressions(self):
self.assertTrue(False, "should raise exception")
except Exception as e:
self.assertIsInstance(
e, dwave.optimization.model.UnsupportedExpression
e, dwave.optimization.model.UnsupportedExpressionError
)
self.assertRegex(str(e), "must not have a higher max than the last input")

Expand Down

0 comments on commit 22a7764

Please sign in to comment.