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

Feat/Inbuilt optimizer #91

Closed

Conversation

Luc-Mcgrady
Copy link
Contributor

@Luc-Mcgrady Luc-Mcgrady commented May 6, 2023

This allows you to quickly optimize your decks in anki without having to worry about exporting them or google colab and whatnot.
The intended flow is:

1.Fsrs -> Install local optimizer

image
image
This installs the fsrs4anki_optimizer module to the lib folder in anki or just to python on linux.
This uses pip as per the warning and for now also uses git.
Look at The install function.
If any part of this code is not going to work for whatever reason its going to be this function.
I have tested it once on both linux and windows. The install on windows seems really slow and lacks a good progress bar but but after like 10 minuites it works so thats a problem for another day.

As a note I personally get a load of error popups when doing this on windows that look like this.
image
If you just keep hitting the ok button it works in the end. You might not have this issue as I suspect that this is to do with my pip version and ankis python version not being compatilble.
So uhh good luck!

2.Cog Button -> Optimize

image
I've found that windows reports non responsiveness here sometimes because the torch library just takes that long to load

3.Prompt for optimal retention.

image
Defaults to no.
No meaning that it wont calculate optimal retention as opposed to cancel which exits without optimizing anything. might be a bit ambiguous and confusing if your not already familliar with the scheduler?

4.Loading tooltip

image
(The total value for the optimal retention is broken for some reason but it works so I left it)

5.Copyable results

image
This is the screen that lets the user copy what the results are. This screen can also be accessed in Tools -> fsrs4anki -> show saved optimized settings
You could potentially include the optimization code itself here making it easier to ctrl-a ctrl-v into the custom scheduling options but that would lead to a massive popup and mean somehow fetching fsrs4anki_scheduler.js or maybe adding the main repo as a submodule of the helper?

6.Manual edit

You can optionally then go to the addons config and edit the values manually
image

Testing Advice

I do think however that the install part of the program using pip and git is a bit unreliable. Maybe take a backup of the lib folder in your anki installation if you're testing it on windows so you can easily reset and if your on linux or mac or whatever make sure the fsrs4anki_optimizer module isnt pre-installed.

As a side note I really despise the code I wrote here to get the progress bar tooltip working as I essensially just replaced tqdm's functions with my own. I feel like theres a better way that would mean changing the code in the Optimizer class but as long as it works I guess.

@khonkhortisan
Copy link

There was no module named 'numpy.core._multiarray_umath', so I downgraded windows store python 3.11 to windows store python 3.9, upgraded pip, reinstalled Anki because I didn't backup lib, deleted/replaced markupsafe, now it 👍 worksforme
Also, if you spam the optimize button you can get the previous deck's tooltip on the next deck's pop-up
imagen
Is there no button to optimize global config from the addon?
Show saved optimized settings needs a scrollbar, it can go off the bottom of the screen
Could it be sorted alphabetically by deckName?

@Luc-Mcgrady
Copy link
Contributor Author

Thanks for the feedback!

As for the Python problems, Sherlock plans to re-write the optimizer in rust so it can be included without worrying about messing up the lib folder.
I'd always just assumed that people used the global config as a fallback for when they haven't optimized their decks yet and hence didn't change it. I don't know where a good place to put the button to optimize the global settings would be? Below to the show saved button?
I could have sworn I patched out being able to do multiple decks at once at some point but I guess I'll do it again.
I don't think sorting alphabetically is needed because you could just copy the results around in the add-on config.
Also yes that screen does need a scrollbar.

@Xemorr
Copy link

Xemorr commented Sep 7, 2023

ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 825, in move
    os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\samue\\AppData\\Local\\Temp\\pip-target-2o7oefh6\\lib\\python\\colorama' -> 'C:\\Program Files\\Anki\\lib\\colorama'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_internal\cli\req_command.py", line 248, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_internal\commands\install.py", line 510, in run
    self._handle_target_dir(
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_internal\commands\install.py", line 569, in _handle_target_dir
    shutil.move(os.path.join(lib_dir, item), target_item_dir)
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 841, in move
    copytree(src, real_dst, copy_function=copy_function,
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 561, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\samue\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 459, in _copytree
    os.makedirs(dst, exist_ok=dirs_exist_ok)
  File "<frozen os>", line 225, in makedirs
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\Anki\\lib\\colorama'

I got this error while attempting to install the local optimizer, probably a pip thing, but thought I'd report it anyway

EDIT: running anki in administrator mode appeared to fix it

@Luc-Mcgrady Luc-Mcgrady changed the title Inbuilt optimizer Feat/Inbuilt optimizer Sep 11, 2023
@khonkhortisan
Copy link

I tried to optimize a deck with a single new card in it [for testing color fonts] and it gets stuck in an optimizing state so I can't optimize a different deck. anki-console.bat says it's stopped, the gui says it's still going. Also happens with a completely empty deck.

Deck file extracted successfully!
INFO 2023-09-21 07:31:14,613 errors 2188 14568 This addon is mentioned in traceback: False
INFO 2023-09-21 07:31:14,615 errors 2188 14568 From _try_handle_exception:
Traceback (most recent call last):
  File "C:\Users\Khonkhortisan\AppData\Roaming\Anki2\addons21\fsrs4anki-helper\optimizer.py", line 167, in run
    optimizer.create_time_series(timezone, revlog_start_date, rollover)
  File "C:\Users\Khonkhortisan\AppData\Local\Programs\Anki\lib\fsrs4anki_optimizer\fsrs4anki_optimizer.py", line 347, in create_time_series
    raise Exception("No review log found!")
Exception: No review log found!

imagen
Anki 2.1.66beta1, Python 3.9.15, system Python 3.9.13, Win10, fsrs4anki-helper commit 616fc2e, fsrs4anki_optimizer 4.4.1, markupsafe replaced

@Luc-Mcgrady
Copy link
Contributor Author

I'm afraid you cant optimize a deck which doesnt have a reasonably substantial review history. 1 new card doesnt give it any reviews to work with hence the "No review log found!" error.

It shouldn't block you from optimizing after an error though so i'll have a look at that.

@peter-moran
Copy link

Does this work for Mac now? If not, I might try to figure it out.

@Luc-Mcgrady
Copy link
Contributor Author

It should I think.

@Luc-Mcgrady
Copy link
Contributor Author

I'm closing this pull request because of the new, native FSRS support with Anki version 23.10 .

@Luc-Mcgrady Luc-Mcgrady closed this Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants