From 2b9c39931d4bd47183b50abcbb56fb64b1052e3f Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Karnad <46030335+iamashwin99@users.noreply.github.com> Date: Mon, 23 Feb 2026 08:50:14 +0100 Subject: [PATCH 1/6] Add example output for make_quadratic function --- dimod/higherorder/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dimod/higherorder/utils.py b/dimod/higherorder/utils.py index 242a0ad78..740fe458b 100644 --- a/dimod/higherorder/utils.py +++ b/dimod/higherorder/utils.py @@ -301,6 +301,8 @@ def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, >>> poly = {(0,): -1, (1,): 1, (2,): 1.5, (0, 1): -1, (0, 1, 2): -2} >>> bqm = dimod.make_quadratic(poly, 5.0, dimod.SPIN) + >>> bqm + BinaryQuadraticModel({0: -3.5, 1: -1.5, '0*1': -2.5, 'aux0,1': -5.0, 2: 1.5}, {(1, 0): 1.5, ('0*1', 0): 2.5, ('0*1', 1): 2.5, ('aux0,1', 0): 5.0, ('aux0,1', 1): 5.0, ('aux0,1', '0*1'): 5.0, (2, '0*1'): -2.0}, 10.0, 'SPIN') """ from dimod.generators import and_gate From 548b3851b837074f3384e59998a9460f91b630dc Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Karnad <46030335+iamashwin99@users.noreply.github.com> Date: Mon, 23 Feb 2026 08:56:38 +0100 Subject: [PATCH 2/6] Enhance docstring for make_quadratic function Added notes on variable types in make_quadratic function. --- dimod/higherorder/utils.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dimod/higherorder/utils.py b/dimod/higherorder/utils.py index 740fe458b..6a56222d7 100644 --- a/dimod/higherorder/utils.py +++ b/dimod/higherorder/utils.py @@ -272,7 +272,7 @@ def var(x): def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, vartype: Optional[Vartype] = None, bqm: Optional[BinaryQuadraticModel] = None) -> BinaryQuadraticModel: - """Create a binary quadratic model from a higher order polynomial. +"""Create a binary quadratic model from a higher order polynomial. Args: poly: @@ -297,6 +297,21 @@ def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, Terms of the reduced polynomial are added to this binary quadratic model. If not provided, a new binary quadratic model is created. + Notes: + When reducing higher-order polynomials to degree 2, the resulting model + will contain three types of variables: + + * **Original Variables**: Variables mapped directly from the input + polynomial (e.g., `0`, `1`, `12`). + * **Product Variables**: Intermediate variables introduced to reduce + higher-order terms, representing the product of two variables. They + are typically named by joining the original variables (e.g., `'0*1'` + represents the product of `0` and `1`). + * **Auxiliary Variables**: Variables introduced to enforce the penalty + constraints that ensure the mathematical relationship of the product + variables holds true at the ground state (e.g., `'aux0,1'` enforces + the constraint for `'0*1'`). + Examples: >>> poly = {(0,): -1, (1,): 1, (2,): 1.5, (0, 1): -1, (0, 1, 2): -2} From 3103d0faee58d274af4bfa83c2185d6bec64dbe5 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Karnad <46030335+iamashwin99@users.noreply.github.com> Date: Mon, 23 Feb 2026 17:47:17 +0100 Subject: [PATCH 3/6] Update dimod/higherorder/utils.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- dimod/higherorder/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dimod/higherorder/utils.py b/dimod/higherorder/utils.py index 6a56222d7..54387af1d 100644 --- a/dimod/higherorder/utils.py +++ b/dimod/higherorder/utils.py @@ -272,7 +272,7 @@ def var(x): def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, vartype: Optional[Vartype] = None, bqm: Optional[BinaryQuadraticModel] = None) -> BinaryQuadraticModel: -"""Create a binary quadratic model from a higher order polynomial. + """Create a binary quadratic model from a higher order polynomial. Args: poly: From 708c4f1d09f10e5295959c57e6a623e2330dfc96 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Karnad <46030335+iamashwin99@users.noreply.github.com> Date: Mon, 23 Feb 2026 17:47:32 +0100 Subject: [PATCH 4/6] Update dimod/higherorder/utils.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- dimod/higherorder/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dimod/higherorder/utils.py b/dimod/higherorder/utils.py index 54387af1d..5185eccc4 100644 --- a/dimod/higherorder/utils.py +++ b/dimod/higherorder/utils.py @@ -298,7 +298,7 @@ def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, If not provided, a new binary quadratic model is created. Notes: - When reducing higher-order polynomials to degree 2, the resulting model + When reducing higher-order polynomials to degree 2, the resulting model will contain three types of variables: * **Original Variables**: Variables mapped directly from the input From bb4f9bb5cf1c0ad5d03ab4c2e32e42abe29f8ac3 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Karnad <46030335+iamashwin99@users.noreply.github.com> Date: Thu, 26 Feb 2026 01:21:43 +0200 Subject: [PATCH 5/6] Update dimod/higherorder/utils.py based on JoelPasvolsky suggestion Co-authored-by: Joel Pasvolsky <34041130+JoelPasvolsky@users.noreply.github.com> --- dimod/higherorder/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dimod/higherorder/utils.py b/dimod/higherorder/utils.py index 5185eccc4..d7c4b988e 100644 --- a/dimod/higherorder/utils.py +++ b/dimod/higherorder/utils.py @@ -297,9 +297,9 @@ def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, Terms of the reduced polynomial are added to this binary quadratic model. If not provided, a new binary quadratic model is created. - Notes: - When reducing higher-order polynomials to degree 2, the resulting model - will contain three types of variables: + Returns: + :class:`~dimod.binary.BinaryQuadraticModel`: A binary quadratic model + with three types of variables: * **Original Variables**: Variables mapped directly from the input polynomial (e.g., `0`, `1`, `12`). From fb8aae96df8e101925cbf440b7039dd28217bc64 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Karnad <46030335+iamashwin99@users.noreply.github.com> Date: Thu, 26 Feb 2026 01:28:05 +0200 Subject: [PATCH 6/6] Update dimod/higherorder/utils.py based on JoelPasvolsky suggestion Co-authored-by: Joel Pasvolsky <34041130+JoelPasvolsky@users.noreply.github.com> --- dimod/higherorder/utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dimod/higherorder/utils.py b/dimod/higherorder/utils.py index d7c4b988e..33535a49d 100644 --- a/dimod/higherorder/utils.py +++ b/dimod/higherorder/utils.py @@ -301,16 +301,16 @@ def make_quadratic(poly: Union[Polynomial, BinaryPolynomial], strength: float, :class:`~dimod.binary.BinaryQuadraticModel`: A binary quadratic model with three types of variables: - * **Original Variables**: Variables mapped directly from the input - polynomial (e.g., `0`, `1`, `12`). - * **Product Variables**: Intermediate variables introduced to reduce - higher-order terms, representing the product of two variables. They - are typically named by joining the original variables (e.g., `'0*1'` - represents the product of `0` and `1`). - * **Auxiliary Variables**: Variables introduced to enforce the penalty - constraints that ensure the mathematical relationship of the product - variables holds true at the ground state (e.g., `'aux0,1'` enforces - the constraint for `'0*1'`). + * Original variables: Variables mapped directly from the input + polynomial (e.g., ``0``, ``1``, ``12``). + * Product variables: Intermediate variables introduced to reduce + higher-order terms, representing the product of two variables. These + are typically named by joining the original variables (e.g., ``0*1`` + represents the product of ``0`` and ``1``). + * Auxiliary variables: Variables introduced to enforce the penalty + constraints that ensure the mathematical relationship of the product + variables holds true at the ground state (e.g., ``aux0,1`` enforces + the constraint for ``0*1``). Examples: