facebookexperimental / Robyn

Robyn is an experimental, AI/ML-powered and open sourced Marketing Mix Modeling (MMM) package from Meta Marketing Science. Our mission is to democratise modeling knowledge, inspire the industry through innovation, reduce human bias in the modeling process & build a strong open source marketing science community.
https://facebookexperimental.github.io/Robyn/
MIT License
1.07k stars 322 forks source link

Robyn Python API - Internal Server Error 500 | Unable to track the logs #924

Closed apoorvabc closed 4 months ago

apoorvabc commented 4 months ago

Project Robyn

Issue

On a linux machine, I am able to connect to the Robyn API using ! Rscript <path_to_apifile>/robynapi_call.R &. I am able to access the dummy data fine. However I am unable to run InputCollect = robyn_api('robyn_inputs',payload=payload) and it throws an Internal Server Error 500. I am unable to view the logs since there is no Robynlog.txt needed to connect to the API.

This works perfectly fine on windows machine. However I have trouble running it on Linux and unable to find the cause.

Dataset used: dummy dataset

yu-ya-tanaka commented 4 months ago

Hi @apoorvabc, Can you share the demo jupyter you are running? You may not be executing the correct cell. Or can you try MAC option to use subprocess.Popen()?

apoorvabc commented 4 months ago
# Constants
API_IP = '127.0.0.1'
TIMEOUT = 1
WAIT_TIME = 5

# Logger setup
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def is_port_open(port):
    command = "sudo netstat -tulpn | grep :{}".format(port)
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, _ = process.communicate()

    return process.returncode == 0 and (":{}".format(port) in output.decode())

# Example usage:

def terminate_port(port):
    # Find the process using the specified port and terminate it
    try:
        pid = subprocess.check_output(['lsof', '-ti', f':{port}']).decode().strip()
        os.kill(int(pid), signal.SIGTERM)
        print(f"Process using port {port} terminated")
    except subprocess.CalledProcessError:
        print(f"No process found on port {port}")

def linux_run_and_check_port(r_script_path, port):
    # Run R script
    print (os.getcwd())
    rscript_command = f"Rscript {r_script_path}"
    print("rscript_command is", rscript_command)
    subprocess.Popen(rscript_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    time.sleep(WAIT_TIME)

    # Check if the port is open
    if is_port_open(port):
        print(f"R script is running on port {port}")
    else:
        print(f"Failed to start R script on port {port}") 

Just an FYI I am able to run the Allocator function using the same API connection by using the saved payload allocator_response = robyn_api('robyn_allocator', payload=payload)

yu-ya-tanaka commented 4 months ago

Is issue solved? If not, are you using customized notebook? Can you use our sample notebook?

ebyjose commented 4 months ago

@apoorvabc : Could be a API initiaitiation issue on linux. Can you append a message file to end of linux api start command and share that file?

apoorvabc commented 4 months ago

Hello @ebyjose, I was able to extract the logs and figured out there was an issue with the nevergrad installation on the docker container. Managed to fix the installation and I am able to build the model fine. This now stands resolved.