Repository navigation
feat: switchback experiments, matching the Java SDK #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
62cc98e
501c0a9
2b0a6bd
51a6ba2
eb13209
b128d09
77a8b7e
61aa94e
d3ff683
73a17cb
0682eb6
cd16639
e16953d
2bff2b4
e42c21b
c7664ca
249eedf
178d870
029af91
57aefe0
ff390c4
d8dcfcd
36417fa
f0d66ef
d790c4f
b20aeb4
d8ab135
f7dc6c9
4c1005d
a88c4cd
2e17eb2
77c30cd
cb86469
f3a1917
d06fadd
206f482
c747303
64066cc
fd6bfda
bc9eb3b
c7cfd29
586312b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,6 +311,28 @@ Unless an override or a matching assignment rule chose its variant, the held-out | |
|
|
||
| An override (`set_override`) or a matching assignment rule still decides the variant of a held-out unit, and the holdout exposures are still published. Custom assignments, audiences, full-on variants and traffic do not apply to a held-out unit. | ||
|
|
||
| ### Switchback Experiments | ||
|
|
||
| A switchback experiment randomizes clusters over time: every unit in the same cluster (for example the same store or city) gets the same variant within a period, and the cluster's variant changes on a fixed time grid. Switchbacks are configured in the ABsmartly web console, and the SDK serves them automatically. Your code calls `get_treatment`, `get_variable_value` and their `peek_` variants as usual. The SDK follows the rules of the Java SDK ([`SWITCHBACK.md`](https://github.com/absmartly/java-sdk/blob/main/SWITCHBACK.md)) and the ABsmartly Collector. | ||
|
|
||
| The cluster comes from your context's units and attributes. The experiment links one or more unit types to an attribute path, in a fixed order. The first unit (in that order) whose attribute has a value is the serving unit, and the value is the cluster key: | ||
|
|
||
| ```python | ||
| context.set_unit("store_id", "store-42") | ||
| context.set_attribute("store", {"city": "Lisbon"}) # path "store/city" | ||
|
|
||
| treatment = context.get_treatment("exp_switchback") # Lisbon's variant in this period | ||
| ``` | ||
|
|
||
| - Only a non-empty string or a whole-number `int` gives a cluster key (an `int` is keyed as its decimal text, so `42` and `"42"` are the same cluster). Floats (including `3.0`), booleans, `None`, `""`, dicts and lists give no value. Paths separate keys with `/` (`store/city`, `items/0/city`); a quoted segment (`'a/b'`) is a literal key. | ||
| - No value, or two linked units with different values, or a value outside the experiment's allowed cluster values: the unit gets the control variant (0) and no exposure is published. An allowed value given as a JSON integer matches its decimal text, as in Java (`[17]` admits `"17"` and `17`). The SDK never falls back to assigning the unit itself. | ||
| - No unit of a linked type: the experiment does not apply (control, nothing published). | ||
| - Before the schedule starts, or with a schedule the SDK cannot serve, the unit gets the control variant and nothing is published. Overrides, assignment rules, strict audiences and full-on variants still apply. | ||
| - The cluster is read once per period: a `set_attribute` later in the same period does not move the unit to another cluster. The next period reads it again. | ||
| - Each period publishes one exposure, stamped with the time that chose the period. The exposure looks the same as a unit experiment's, under the serving unit's type. Attributes are still published with their timestamps, because the Collector re-resolves the cluster from them. If an attribute changes after a peek pinned the cluster, the exposure uses the original in-period cluster-read time so the Collector reconstructs that cluster. Attributes keep the clock reading as their timestamp, as in the Java SDK, so an attribute change within the same clock tick as the read that pinned the cluster cannot be told apart by the Collector (a limitation shared with the Java SDK). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Distinguish exposure eligibility from deduplication. A peek queues nothing, a silent candidate queues nothing, and an in-period change such as a full-on refresh can replace an exposed slot and allow another exposure. Describe deduplication per retained assignment. In the variable-read bullet, say that Python considers every visited candidate for exposure, subject to the same eligibility and deduplication rules. Also applies to: 324-324
|
||
| - Holdouts never apply to a switchback experiment. | ||
| - Variable reads expose every experiment they visit on the way to the one that defines the key, for switchbacks as for unit experiments (this SDK's behaviour since 0.3.0). The Java SDK exposes only the winning experiment. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README overstates variable-read exposure. Variable reads expose only the winning experiment for a key. This also applies to switchback experiments. If a strict-mismatched switchback loses a shared key to a full-on unit experiment, no exposure is recorded for the switchback. The test at The PR also records a Q1 decision that Python should expose every visited experiment. The implementation does not do that. Choose one behaviour, then make the code, tests and README agree:
Keep the separate holdout rule for visited experiments. The walk still collects and exposes holdouts for each visited candidate.
|
||
|
|
||
| ## Advanced | ||
|
|
||
| ### Context Attributes | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe the scheduled draw, not a guaranteed variant change.
A cluster can draw the same arm in adjacent periods. Units in the same cluster can also receive different treatments if traffic eligibility or assignment rules differ. State that the SDK computes a shared cluster draw for each period when no higher-priority decision applies.