Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Order Partitioning for A/B Testing

Maintained by the JuliaQUBO organization
SECQUOIA  ·  PSR Energy

Open In Colab

An original Julia case study with a corrected grouped-risk objective and exact checks.

Setup

Local installation

From the repository root, instantiate the shared Julia environment before opening this notebook:

julia --project=notebooks_jl -e 'using Pkg; Pkg.instantiate()'

Run this notebook from a clean kernel with:

make verify-order-partitioning-julia

The default workflow is credential-free, uses no external data, and solves the six-order instance locally.

Google Colab

Open the badge above, select a Julia runtime, and run the setup cells. The bootstrap clones this repository only when Colab does not already have it, then activates the same checked-in notebook project used locally.

Notebook Cell
Notebook Cell

Learning objectives

By the end of this notebook you will be able to:

  1. formulate value and factor-risk balance as a QUBO with explicit weights;

  2. explain why each risk-factor square must enclose the sum over orders;

  3. verify all 64 assignments independently of the optimizer;

  4. decode group values and risk exposures from an exact optimum; and

  5. explain complement symmetry and the trade-off induced by the two weights.

Prerequisites

Prior notebooks: Notebook 2 introduces JuMP and QUBO models; Notebook 7 develops exhaustive checking helpers. This notebook restates the helpers it needs so it remains useful on its own.

Mathematical background: Binary variables, finite sums, squared deviations, and basic A/B testing terminology.

Software: Julia 1.10+ with the shared notebook project instantiated.

Accounts required: None.

Order-partitioning model

Suppose a desk wants to assign indivisible orders to two labeled groups for an educational A/B comparison. Bit xj=0x_j=0 places order jj in group A and xj=1x_j=1 places it in group B. The value term minimizes the signed group-value difference, while each row of pp represents one factor exposure to balance.

The fixture below is independently constructed for this notebook. Order values are in units of USD 100,000; the two risk rows are dimensionless synthetic factor-exposure scores. They are not observed trades, an empirical trading result, or investment advice.

Synthetic fixture: 6 orders, total value = $2.8M, risk factors = ["market beta proxy", "liquidity proxy"]

For explicit positive weights aa and bb, we minimize

Q(x)=a(T−2∑jqjxj)2+b∑i(∑jpij(2xj−1))2.Q(x)=a\left(T-2\sum_j q_jx_j\right)^2 +b\sum_i\left(\sum_j p_{ij}(2x_j-1)\right)^2.

The parentheses are essential. For factor ii, the inner sum is group B exposure minus group A exposure, so its square penalizes imbalance. Moving the square onto each (2xj−1)(2x_j-1) makes that term constant because (2xj−1)2=1(2x_j-1)^2=1 for binary xjx_j. The direct functions below are separate from the JuMP expression and serve as the independent reference calculation.

decoded_metrics (generic function with 1 method)
same_states (generic function with 1 method)
Loading...

Exact verification

Six binary orders give only 26=642^6=64 assignments. We compare the expanded JuMP objective with the direct displayed formula for every one, verify that the correct risk term is nonconstant, and check complement symmetry. The deliberately named incorrect helper exists only as a regression witness for the square-inside-the-sum defect.

All 64 assignments match the direct grouped-square formula.
Correct risk term values: [4, 16, 20, 32, 36, 40, 80, 100, 104, 116, 128, 136, 160, 180, 196, 200, 212, 256, 296, 328, 388, 400]; square-inside regression witness: 26 for every assignment.
Enumerated optimum energy: 28
ExactSampler optimum energy: 28
Global minima: [[1, 1, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1]]

Decoded balances

We select the optimum whose first order is in group A. Values are converted from the fixture’s USD 100,000 units to millions of dollars. Risk exposure is reported factor by factor; the aggregate risk imbalance is the Euclidean norm of the signed factor differences. The raw QUBO energy remains the weighted sum of squared imbalances.

x = [0, 0, 0, 1, 0, 1]
Group A orders: ORD-1, ORD-2, ORD-3, ORD-5
Group B orders: ORD-4, ORD-6
Group A total: $1.5M
Group B total: $1.3M
Signed value imbalance (A-B): $+0.2M; absolute: $0.2M
market beta proxy: A=8, B=10, signed imbalance (B-A)=+2, absolute=2
liquidity proxy: A=2, B=6, signed imbalance (B-A)=+4, absolute=4
Aggregate risk imbalance (L2): 4.472136
Raw QUBO energy: 28

Complement symmetry

Replacing xx by 1−x1-x swaps the two group labels. Every signed imbalance changes sign, while every squared term and the raw energy remain unchanged.

Complement x = [1, 1, 1, 0, 1, 0] swaps A and B.
Complement energy: 28

Weight sensitivity

Weights aa and bb express a modeling priority; they do not reveal one universally best partition. Increasing aa favors value balance, while increasing bb favors factor-risk balance. We enumerate the same fixture under three choices so that the trade-off is transparent rather than inferred from one solver run.

case            a  b  |value A-B|  risk B-A  risk score  energy  representative x
balanced         2  1            2  [2, 4]             20      28  [0, 0, 0, 1, 0, 1]
value priority   8  1            0  [2, -6]            40      40  [0, 1, 0, 1, 1, 0]
risk priority    1  8            6  [0, -2]             4      68  [0, 0, 0, 1, 1, 0]

The value-priority case reaches equal group value but accepts a larger factor-risk score. The risk-priority case reduces the factor-risk score from 20 to 4 but accepts a value difference of six fixture units (USD 600,000). The balanced case lies between those outcomes. Appropriate weights depend on units, risk governance, and the purpose of the experiment; this tutorial does not prescribe them.

Practice checkpoints

  1. Set a=b=1a=b=1. Predict the optimal value and risk imbalances, then confirm them by enumerating all states.

  2. Change the liquidity exposure of ORD-6 from 0 to 2. Before solving, identify which assertions must be recomputed and why hard-coded solver output is not a correctness proof.

  3. Replace the grouped risk expression in a scratch model with the square-inside expression. Confirm that its risk contribution is identical for all 64 assignments, then restore the corrected model.

For every change, rerun the all-state comparison before trusting the decoded result.

Notebook Cell
Equal weights: energy=24, x=[0, 0, 0, 1, 0, 1]
Notebook Cell
Changed exposure: energy=28, degeneracy=4, representative x=[0, 0, 1, 1, 1, 0]
Notebook Cell
Grouped square has 22 distinct values; square-inside has 1.

Summary

Learning objectives met:

  • Value balance and each factor-risk balance are squared only after summing signed order contributions.

  • The independently constructed six-order fixture has a nonconstant risk term, unlike the square-inside regression witness.

  • The direct formula and expanded JuMP objective agree for every assignment.

  • ExactSampler and independent enumeration return the same two complementary global minima.

  • Decoded group totals, factor exposures, signed and absolute imbalances, aggregate risk imbalance, and raw energy agree with direct calculations.

  • Weight changes expose a real trade-off; no one pair of weights is universally best.

Next steps: Later notebooks may compare local or hardware-oriented solvers, but those comparisons are intentionally outside this modeling case study.

Further reading:

  • The Five Starter Problems paper motivates order partitioning and derives the grouped-square objective.

  • The QUBO.jl documentation explains the JuMP modeling and exact-sampling interfaces used here.

References

  1. A. R. Mazumder and S. Tayur, Five Starter Problems: Solving Quadratic Unconstrained Binary Optimization Models on Quantum Computers, TutORials in Operations Research (2025), pp. 145–183, Mazumder & Tayur (2025).

  2. Companion materials: https://github.com/arulrhikm/Solving-QUBOs-on-Quantum-Computers.

  3. QUBO.jl public API and ExactSampler: https://github.com/JuliaQUBO/QUBO.jl.

This notebook contains original Julia code, prose, and an independently constructed synthetic fixture. The companion repository is cited as context; no source cells, prose, saved output, figures, or other implementation material were copied from it. The example is educational and is not investment advice or an empirical trading result.

References
  1. Mazumder, A. R., & Tayur, S. (2025). Five Starter Problems: Solving Quadratic Unconstrained Binary Optimization Models on Quantum Computers. In Tutorials in Operations Research: Advances in Analytics and Operations Research: Improving Decisions to Secure the Future (pp. 145–183). INFORMS. 10.1287/educ.2025.0288