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

RuntimeError: Squad is incomplete #683

Open
RajeshTailor1 opened this issue Aug 9, 2024 · 14 comments
Open

RuntimeError: Squad is incomplete #683

RajeshTailor1 opened this issue Aug 9, 2024 · 14 comments

Comments

@RajeshTailor1
Copy link

I have just set this up for the new season I have already setup a squad for my FPL team however I did setup my FPL Team ID in the env prior to running the make squad routine.

I think this error has come up a few times in the past but for some reason I can't remember how I resolved it the last time.

@jack89roberts
Copy link
Contributor

A few comments/ideas:

  • You can set your new team ID with airsenal_env set -k FPL_TEAM_ID -v 123456 (and similarly for FPL_PASSWORD and FPL_LOGIN if those have changed).
  • If you've not already you'll need to pull the latest changes in the repo and then reinstall AIrsenal
  • It's maybe worth running airsenal_run_pipeline --clean, which will delete and recreate the database for you.

If none of these fix it, what command are you running and could you post more of the error message you're getting?

@jack89roberts
Copy link
Contributor

Also, if you're running individual commands separately, before the season starts only airsenal_make_squad will work, not airsenal_run_optimization (but airsenal_run_pipeline will do that automatically).

@AbdullaMashaly
Copy link

Traceback (most recent call last):
File "/Users/abdullamashaly/anaconda3/envs/airsenalenv/bin/airsenal_make_squad", line 8, in
sys.exit(main())
File "/Users/abdullamashaly/anaconda3/envs/airsenalenv/lib/python3.9/site-packages/airsenal/scripts/squad_builder.py", line 208, in main
fill_initial_squad(
File "/Users/abdullamashaly/anaconda3/envs/airsenalenv/lib/python3.9/site-packages/airsenal/scripts/squad_builder.py", line 73, in fill_initial_squad
optimised_score = get_discounted_squad_score(
File "/Users/abdullamashaly/anaconda3/envs/airsenalenv/lib/python3.9/site-packages/airsenal/framework/optimization_utils.py", line 214, in get_discounted_squad_score
total_points += squad.get_expected_points(gw, tag) * gw_weight
File "/Users/abdullamashaly/anaconda3/envs/airsenalenv/lib/python3.9/site-packages/airsenal/framework/squad.py", line 398, in get_expected_points
self.optimize_lineup(gameweek, tag)
File "/Users/abdullamashaly/anaconda3/envs/airsenalenv/lib/python3.9/site-packages/airsenal/framework/squad.py", line 385, in optimize_lineup
raise RuntimeError("Squad is incomplete")
RuntimeError: Squad is incomplete

Same thing Happens here !

@AbdullaMashaly
Copy link

This Happens When I try to run airsenal_make_squad --num_gameweeks 3

@jack89roberts
Copy link
Contributor

Hi @AbdullaMashaly , have you tried all the steps in my comment above, particularly airsenal_run_pipeline --clean?

@AbdullaMashaly
Copy link

Yes I tried all the stuff from above but still have the same problem

@jack89roberts
Copy link
Contributor

Hmm not sure what's going on then, could you check you get version 1.8.0 from python -c "import airsenal; print(airsenal.__version__)"? And are you able to test in a more recent version of Python in case that makes a difference (the conda environment in the readme currently sets up Python 3.12).

@nbarlowATI
Copy link
Member

Hi @AbdullaMashaly , also not sure what is going on, but here are a few debugging tips/sanity checks:

  • If you run all the steps individually, do they all work? i.e. airsenal_setup_initial_db --clean, airsenal_update_db, airsenal_run_predictions --weeks_ahead 10, airsenal_make_squad, is it just the last one that doesn't work? (At the end of the airsenal_run_predictions step there should be a printout of the top 5 players in each position - does that look sensible?
  • If it's just the airsenal_make_squad command that fails, you could try running it with the argument --algorithm normal - this will use an iterative rather than the genetic algorithm. (Not sure why this would work if the other doesn't, but worth a try!)
  • If you open a python session, can try printing some things out as sanity checks...
python
>>> from airsenal.framework.utils import *
>>> print(CURRENT_SEASON)
>>> print(get_next_gameweek())
>>> print(fetcher.FPL_TEAM_ID)

and see if these all have the expected values?
* If all that is as expected, then it's still a mystery, depending on your appetite for debugging, could put some print statements into `airsenal/scripts/squad_builder.py` or `airsenal/framework/optimization_squad.py` (then need to redo `pip install .`).

Sorry I don't have any more specific ideas on what might be going wrong, but hopefully something here might help a bit.....

@AbdullaMashaly
Copy link

airsenal_make_squad --algorithm normal worked but then ran into another problem when making transfers not sure what is wrong ... anyways thanks for your help

@jack89roberts
Copy link
Contributor

If it was just airsenal_make_transfers that failed it might be something to do with setting your username/password/team ID, or occasionally we see captcha issues. Does airsenal_run_pipeline work for you now the season has started?

@RajeshTailor1
Copy link
Author

RajeshTailor1 commented Sep 2, 2024

Providing some additional context as I am still receiving the error. However I haven't tried changing the algorithm yet. I updated the DB using the commands and I am running the individual commands not the pipeline. I have attached a screenshot of the error. I also want to run a wildcard for gw4 so I am assuming I am running the right switches.

Screenshot 2024-09-02 at 12 14 42

@RajeshTailor1
Copy link
Author

I also ran the print statements as suggested above, with the following output and looks good.

[ec2-user@ip-172-31-0-130 ~]$ python3.9
Python 3.9.16 (main, Jul 5 2024, 00:00:00)
[GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.

from airsenal.framework.utils import *
print(CURRENT_SEASON)
2425
print(get_next_gameweek())
4
print(fetcher.FPL_TEAM_ID)
2738283

@nbarlowATI
Copy link
Member

Hi @RajeshTailor1! I don't think the choice of algorithm is relevant here - this is just for the initial squad selection via airsenal_make_squad, which would be used before Gameweek 1. For the week-to-week airsenal_run_optimization, it just tries to find the best strategy over the next few gameweeks, where it can make 0, 1, or 2 transfers per week, and in each part of the determination (each node of the tree) it does an exhaustive search of e.g. what would be the best 2 transfers.

Another thing to check then would be that after doing airsenal_setup_initial_db --clean and airsenal_update_db, you have the correct squad - agreeing with what the FPL website thinks you have:

python
>>> from airsenal.framework.utils import NEXT_GAMEWEEK
>>> from airsenal.framework.optimization_utils import get_starting_squad
>>> print get_starting_squad(NEXT_GAMEWEEK)

If that looks ok, then, somewhere in the optimization itself it is failing to do the transfers its trying to do... I think the only way to debug this would be to put some print statements into the make_best_transfers function in airsenal/framework/optimization_transfers.py - e.g. above line 395 you could do
print(f"trying {num_transfers} transfers, squad is {new_squad}") ?

@RajeshTailor1
Copy link
Author

RajeshTailor1 commented Sep 23, 2024

Just wanted to add - this is now working. Nothing was done differently or changed but seems to be working ok now. Could be something peculiar with the 1st or 2nd game week and the team changes. Actually I lie I did do something differently this time I decided to not add the switch for num_thread. I'll try to add that back in next time see what happens.

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

4 participants