PageSourceSearch

https://ax.dev/assets/js/0da30c1e.6a37b999.js

js ax.dev collected 2026-09-24 10:35:27 UTC 8,983 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[7150],{28453(e,n,t){t.d(n,{R:()=>s,x:()=>l});var i=t(96540);const a={},o=i.createContext(a);function s(e){const n=i.useContext(o);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),i.createElement(o.Provider,{value:n},e.children)}},83600(e,n,t){t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>h,frontMatter:()=>s,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"recipes/experiment-to-json","title":"Saving and Loading an Ax Experiment to JSON","description":"Ax provides a convenient way to save and load experiments in JSON format, making","source":"@site/versioned_docs/version-1.0.0/recipes/experiment-to-json.md","sourceDirName":"recipes","slug":"/recipes/experiment-to-json","permalink":"/docs/1.0.0/recipes/experiment-to-json","draft":false,"unlisted":false,"tags":[],"version":"1.0.0","lastUpdatedBy":"github-actions[bot]","lastUpdatedAt":1746744654000,"frontMatter":{},"sidebar":"tutorials","previous":{"title":"Adding Tracking Metrics to Your Experiment","permalink":"/docs/1.0.0/recipes/tracking-metrics"},"next":{"title":"Saving and Loading an Ax Experiment to Your SQL Database","permalink":"/docs/1.0.0/recipes/experiment-to-sqlite"}}');var a=t(74848),o=t(28453);const s={},l="Saving and Loading an Ax Experiment to JSON",r={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Steps",id:"steps",level:2},{value:"Saving to JSON",id:"saving-to-json",level:3},{value:"1. Initialize a Client and configure it with an experiment",id:"1-initialize-a-client-and-configure-it-with-an-experiment",level:4},{value:"2. View the state of the attached experiment via <code>summarize()</code>",id:"2-view-the-state-of-the-attached-experiment-via-summarize",level:4},{value:"2. Call save_to_json_file to save a snapshot of the Client to JSON",id:"2-call-save_to_json_file-to-save-a-snapshot-of-the-client-to-json",level:4},{value:"Load an Experiment from JSON",id:"load-an-experiment-from-json",level:3},{value:"1. Call load_from_json_file to initialize a new Client",id:"1-call-load_from_json_file-to-initialize-a-new-client",level:4},{value:"2. Validate the state of the attached experiment via <code>summarize()</code>",id:"2-validate-the-state-of-the-attached-experiment-via-summarize",level:4},{value:"Customizing the Serialization Process",id:"customizing-the-serialization-process",level:3},{value:"Learn more",id:"learn-more",level:2}];function c(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.header,{children:(0,a.jsx)(n.h1,{id:"saving-and-loading-an-ax-experiment-to-json",children:"Saving and Loading an Ax Experiment to JSON"})}),"\n",(0,a.jsx)(n.p,{children:"Ax provides a convenient way to save and load experiments in JSON format, making\nit easy to store and transport experiment data. In this recipe, we will walk\nthrough the steps of saving and loading an Ax experiment to JSON using the\nClient."}),"\n",(0,a.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,a.jsx)(n.p,{children:"Saving and loading an experiment to JSON is useful when you want to store the\nexperiment data in a lightweight and transportable format. This can be\nparticularly useful for users who prefer a simple storage solution or need to\nshare experiment data with others."}),"\n",(0,a.jsx)(n.h2,{id:"steps",children:"Steps"}),"\n",(0,a.jsx)(n.p,{children:"In this recipe, we plan to save a a snapshot of an Ax Client to JSON, reload the\nclient from the JSON file, and validate its contents."}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.strong,{children:"Saving to JSON"}),"\n",(0,a.jsxs)(n.ol,{children:["\n",(0,a.jsx)(n.li,{children:"Initialize a Client and configure it with an experiment"}),"\n",(0,a.jsxs)(n.li,{children:["View the state of the attached experiment via ",(0,a.jsx)(n.code,{children:"summarize()"})]}),"\n",(0,a.jsx)(n.li,{children:"Call save_to_json_file to save a snapshot of the Client to JSON"}),"\n"]}),"\n"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.strong,{children:"Loading from JSON"}),"\n",(0,a.jsxs)(n.ol,{children:["\n",(0,a.jsx)(n.li,{children:"Call load_from_json_file to initialize a new Client"}),"\n",(0,a.jsxs)(n.li,{children:["Validate the state of the attached experiment via ",(0,a.jsx)(n.code,{children:"summarize()"})]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(n.h3,{id:"saving-to-json",children:"Saving to JSON"}),"\n",(0,a.jsx)(n.h4,{id:"1-initialize-a-client-and-configure-it-with-an-experiment",children:"1. Initialize a Client and configure it with an experiment"}),"\n",(0,a.jsxs)(n.p,{children:["Instantiate a ",(0,a.jsx)(n.code,{children:"Client"})," and configure it for your experiment."]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-python",children:"client = Client()\n\nclient.configure_experiment(...)\nclient.configure_optimization(...)\n"})}),"\n",(0,a.jsxs)(n.h4,{id:"2-view-the-state-of-the-attached-experiment-via-summarize",children:["2. View the state of the attached experiment via ",(0,a.jsx)(n.code,{children:"summarize()"})]}),"\n",(0,a.jsx)(n.p,{children:"You can inspect the state of a experiment by leveraging the summarize() method,\nwhich returns a DataFrame"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-python",children:"client.summarize()\n"})}),"\n",(0,a.jsx)(n.h4,{id:"2-call-save_to_json_file-to-save-a-snapshot-of-the-client-to-json",children:"2. Call save_to_json_file to save a snapshot of the Client to JSON"}),"\n",(0,a.jsxs)(n.p,{children:["In order to save an experiment to JSON, we need to call the ",(0,a.jsx)(n.code,{children:"save_to_json_file"}),"\nmethod on the Client instance. This method takes a single optional argument\n",(0,a.jsx)(n.code,{children:"filepath"}),', which is the filepath where we want to save the JSON file (argument\ndefaults to "ax_client_snapshot.json").']}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-python",children:"client.save_to_json_file()\n"})}),"\n",(0,a.jsx)(n.p,{children:"On success, this will save a snapshot of the Client's settings and state to the\nspecified file, which includes information about the experiment and generation\nstrategy (if present)."}),"\n",(0,a.jsx)(n.h3,{id:"load-an-experiment-from-json",children:"Load an Experiment from JSON"}),"\n",(0,a.jsx)(n.h4,{id:"1-call-load_from_json_file-to-initialize-a-new-client",children:"1. Call load_from_json_file to initialize a new Client"}),"\n",(0,a.jsxs)(n.p,{children:["We will now load the previously saved Client snapshot into a 
1new one. We will do\nthis by calling ",(0,a.jsx)(n.code,{children:"load_from_json_file"})]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-python",children:'new_client = Client.load_from_json_file(filepath = "ax_client_snapshot.json")\n'})}),"\n",(0,a.jsxs)(n.h4,{id:"2-validate-the-state-of-the-attached-experiment-via-summarize",children:["2. Validate the state of the attached experiment via ",(0,a.jsx)(n.code,{children:"summarize()"})]}),"\n",(0,a.jsxs)(n.p,{children:["We can now view the state of the experiment by calling ",(0,a.jsx)(n.code,{children:"summarize()"}),", and\nvalidate that it is the same as the one we saved in the earlier section"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-python",children:"new_client.summarize()\n"})}),"\n",(0,a.jsx)(n.h3,{id:"customizing-the-serialization-process",children:"Customizing the Serialization Process"}),"\n",(0,a.jsxs)(n.p,{children:["If you have custom metrics or runners that you want to ensure are saved to JSON\nproperly, you can initialize the ",(0,a.jsx)(n.code,{children:"Client"})," with a ",(0,a.jsx)(n.code,{children:"StorageConfig"})," that contains a\n",(0,a.jsx)(n.code,{children:"RegistryBundle"}),", that bundles together encoding and decoding logic for use in\nthe save/load functions."]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-python",children:"storage_config = StorageConfig(\n    registry_bundle = RegistryBundle(\n        runner_clss={MyRunner: None},\n        metric_clss={MyMetric: None},\n    )\n)\n\nclient = Client(storage_config = storage_config)\n"})}),"\n",(0,a.jsx)(n.h2,{id:"learn-more",children:"Learn more"}),"\n",(0,a.jsx)(n.p,{children:"Take a look at these other recipes to continue your learning:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"/docs/1.0.0/recipes/experiment-to-sqlite",children:"Saving, Loading, and Updating an Ax Experiment from SQLite"})}),"\n"]})]})}function h(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.