Skip to content
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

[Python API] robyn_refresh endpoint not yet develop? #993

Open
rupatrawut opened this issue Jun 12, 2024 · 4 comments
Open

[Python API] robyn_refresh endpoint not yet develop? #993

rupatrawut opened this issue Jun 12, 2024 · 4 comments

Comments

@rupatrawut
Copy link

Project Robyn

Describe issue

I would like to do robyn_refresh to builds on top of an selected initial model with new coming data. However, I can't find the Python API endpoint for this function.

Is there any plan to develop this function? Or is it possible to run R function for model_refresh from Python outcome?

Environment & Robyn version

  • Check and share Robyn version: 3.10.7.9000
@rupatrawut rupatrawut changed the title [Python API] robyn_refresh endpoint not develop? [Python API] robyn_refresh endpoint not yet develop? Jun 12, 2024
@rupatrawut
Copy link
Author

rupatrawut commented Jun 12, 2024

FYI, I try to save the model.json which is an input for robyn_refresh in Python using following code:

output_folder = Path(OutputCollect['plot_folder'][0])
for i in OutputCollect['clusters']['models']:
    print(i['solID'])
    write_robynmodel(sol=i['solID'], path=str(output_folder), InputJson=InputCollect, OutputJson=OutputCollect, OutputModels=OutputModels)

But got the MemoryError issue as below:


MemoryError Traceback (most recent call last)
Cell In[34], line 6
4 for i in OutputCollect['clusters']['models']:
5 print(i['solID'])
----> 6 write_robynmodel(sol=i['solID'], path=str(output_folder), InputJson=InputCollect, OutputJson=OutputCollect, OutputModels=OutputModels)
8 # OutputCollect['allSolutions']

File ~\workspace\ml-marketing-mix-modeling\ml_mmm_robyn\robyn_api\python_helper.py:301, in write_robynmodel(sol, path, InputJson, OutputJson, OutputModels)
293 payload = {
294 'InputCollect' : json.dumps(InputJson),
295 'OutputCollect' : json.dumps(OutputJson),
296 'OutputModels' : json.dumps(OutputModels),
297 "jsonWriteArgs": json.dumps(writeArgs)
298 }
300 # Get response
--> 301 respJson = robyn_api('robyn_write',payload=payload)
302 print('File written to path: ',updatedPath)

File ~\workspace\ml-marketing-mix-modeling\ml_mmm_robyn\robyn_api\python_helper.py:96, in robyn_api(argument, payload, api)
94 return respJson
95 else:
---> 96 response = requests.post(api.format(argument),data=payload)
97 respJson = json.loads(response.content.decode('utf-8'))
98 return respJson

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\api.py:115, in post(url, data, json, **kwargs)
103 def post(url, data=None, json=None, **kwargs):
104 r"""Sends a POST request.
105
106 :param url: URL for the new :class:Request object.
(...)
112 :rtype: requests.Response
113 """
--> 115 return request("post", url, data=data, json=json, **kwargs)

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\api.py:59, in request(method, url, **kwargs)
55 # By using the 'with' statement we are sure the session is closed, thus we
56 # avoid leaving sockets open which can trigger a ResourceWarning in some
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\sessions.py:575, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
562 # Create the Request.
563 req = Request(
564 method=method.upper(),
565 url=url,
(...)
573 hooks=hooks,
574 )
--> 575 prep = self.prepare_request(req)
577 proxies = proxies or {}
579 settings = self.merge_environment_settings(
580 prep.url, proxies, stream, verify, cert
581 )

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\sessions.py:486, in Session.prepare_request(self, request)
483 auth = get_netrc_auth(request.url)
485 p = PreparedRequest()
--> 486 p.prepare(
487 method=request.method.upper(),
488 url=request.url,
489 files=request.files,
490 data=request.data,
491 json=request.json,
492 headers=merge_setting(
493 request.headers, self.headers, dict_class=CaseInsensitiveDict
494 ),
495 params=merge_setting(request.params, self.params),
496 auth=merge_setting(auth, self.auth),
497 cookies=merged_cookies,
498 hooks=merge_hooks(request.hooks, self.hooks),
499 )
500 return p

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\models.py:371, in PreparedRequest.prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
369 self.prepare_headers(headers)
370 self.prepare_cookies(cookies)
--> 371 self.prepare_body(data, files, json)
372 self.prepare_auth(auth, url)
374 # Note that prepare_auth must be last to enable authentication schemes
375 # such as OAuth to work on a fully prepared request.
376
377 # This MUST go after prepare_auth. Authenticators could add a hook

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\models.py:559, in PreparedRequest.prepare_body(self, data, files, json)
557 else:
558 if data:
--> 559 body = self._encode_params(data)
560 if isinstance(data, basestring) or hasattr(data, "read"):
561 content_type = None

File c:\Users\rupatrawut\workspace\ml-marketing-mix-modeling\conda-env\Lib\site-packages\requests\models.py:129, in RequestEncodingMixin._encode_params(data)
124 for v in vs:
125 if v is not None:
126 result.append(
127 (
128 k.encode("utf-8") if isinstance(k, str) else k,
--> 129 v.encode("utf-8") if isinstance(v, str) else v,
130 )
131 )
132 return urlencode(result, doseq=True)
133 else:

MemoryError:

Which is wired because the model.json size when I ran the R code is just 20-30kb.

Environment:

  • Windows 11
  • RAM 32GB

@gufengzhou
Copy link
Contributor

The refresh API endpoint is indeed not shipped yet. @yu-ya-tanaka do you want to have a look and talk to @ebyjose if you have time for this?

@rupatrawut
Copy link
Author

Hi @gufengzhou, @yu-ya-tanaka thank you very much for all the support.
Is this feature in your developing plan?

By the way, the out-of-memory problem is solved, please ignore it.

@ebyjose
Copy link
Contributor

ebyjose commented Jul 8, 2024

Hi @rupatrawut : Currently we are still focusing on having the current python-api to be a safe and prioritizing support over development of new endpoints.
Thanks for confirming on the out-of memory solve. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants