[2.0.76] Rounding issue with speed modded labs resulting in loss of research

Things that has been reported already before.
BurninSun
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 16, 2018 4:54 am
Contact:

[2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by BurninSun »

Sometimes, research doesn't quite complete based on the number of science packs fed into labs. Save is attached to reproduce.

In the save, 2 researches are queued which take 10 red science each. The lab has a single speed mod in it. The player has 20 red science in their inventory. Place those 20 in the lab, wait for the research to complete, and you'll notice that gun turret research stops at 99%.
Repeat the setup but without the speed mod in the lab. The research will complete.
Place 4 beacons with speed mod 3's in each and no mods in the lab so the lab is at 300% speed bonus. The research will complete.
Same setup but remove one speed mod so the lab is at 263% speed bonus and the research stops at 99% again.
Edit: Original setup but only feed in 10 science until the first research completes, then feed in 10 more and both researches will complete.

This came up because at a certain point in Space Exploration we give players 400 science packs. There was a recent report from a player who wasn't using production mods and expected those 400 science packs to research exactly 400 science worth of tech but was stalling at 99% complete.
Attachments
science test.zip
(1.67 MiB) Downloaded 12 times
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4534
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by boskid »

This looks to be a duplicate of 119070.

Lab and research logic is full of floating point math, including crafting speed, productivity, continuous reporting of research progress, research manager tracking the research progress so there are no easy solution that would make it robust. This would require converting research progress to be rewritten using fixed point math and this would also require tool items to keep track of durability remaining as fixed point numbers, which is not going to happen.

From a number balance point of view (when adding research progress and science pack remaining) the largest amount of science pack is lost at the last tick of first technology research because lab consumes amount of science pack equal to a full tick worth of researching, however the research progress is already close to finished and so it slightly overshoots to finish a technology.

Floating point errors here are quite severe: in your save file, lab crafting with 1 speed module will increase research progress by 0.0020000000794728598 each tick (floating point errors here are due to module effect values computed as float) consuming similar amount of science packs. Due to floating point errors when accumulating research progress, it takes 5001 ticks to reach a required progress (tick 4999: 9.9974226194846043, tick 5000: 9.9994226195640774, tick 5001: 10.001422619643551). This is where the science pack gets consumed a little bit too much which makes it not sufficient to research second technology. By putting only 10 science packs, the lab throttles down in the last tick making the research progress to only go up to 10.000000000000469 which drains last science pack completly.

I am not sure if there are good solutions that would not be making this logic more fragile. Having lab throttle down as the technology approaches its max would require converting remaining progress into science packs which needs to account for productivity and if this logic throttles too much it could happen that lab would be unable to research technology in some weird corner cases where remaining progress is so small that lab stops researching. Only viable option i can see would be to make lab not consume from science packs at the tick technology was researched, but that would leave a partially consumed science packs inside of labs (put 10, research technology worth 10, you get 1 item remaining that has 0.2% durability remaining) which would also cause bug reports.

Overall i am leaning towards a "wont fix" here as other options are fragile (throttling down) or complex to implement (fixed point) and nothing of this matters as soon as productivity is involved or you get automated production of science packs.
BurninSun
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 16, 2018 4:54 am
Contact:

Re: [2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by BurninSun »

One caveat is when only feeding exact amounts per research, it seems to work correctly.
Using that save, put 10 packs in, the first research completes, put 10 more packs in, the 2nd research completes. I'm assuming there is a small fudge factor when finishing the last science pack that isn't there when more science packs are available.
So is it possible to add that fudge factor at the "end" of every research?

Eh, I probably shouldn't post while eating dinner and barely reading.
Last edited by BurninSun on Tue May 05, 2026 7:17 am, edited 1 time in total.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4534
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by boskid »

I already mentioned that in this case lab throttles down, and i do not want to be doing it because it is extra check that needs to happen every single time even if its only relevant once in some super narrow situation and throttling down has risks of making labs unable to progress in some other cases.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16790
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by Rseding91 »

Moving to duplicates. “Just craft more science packs” is the answer.
If you want to get ahold of me I'm almost always on Discord.
Nidan
Filter Inserter
Filter Inserter
Posts: 369
Joined: Sat Nov 21, 2015 1:40 am
Contact:

Re: [2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by Nidan »

boskid wrote: Tue May 05, 2026 6:42 am I am not sure if there are good solutions that would not be making this logic more fragile. Having lab throttle down as the technology approaches its max would require converting remaining progress into science packs which needs to account for productivity and if this logic throttles too much it could happen that lab would be unable to research technology in some weird corner cases where remaining progress is so small that lab stops researching.
Doesn't this boil down to scaling the science pack consumption by the amount the progress overshoots the target, since both speed and productivity affect consumption and progress linearly? I.e., in the tick/lab where (research_progress >= research_remaining), multiply science pack consumption by (research_remaining / research_progress) and consider the research done.
Am I missing something here?
User avatar
Stargateur
Filter Inserter
Filter Inserter
Posts: 425
Joined: Sat Oct 05, 2019 6:17 am
Contact:

Re: [2.0.76] Rounding issue with speed modded labs resulting in loss of research

Post by Stargateur »

Mandatory What Every Computer Scientist Should Know About Floating-Point Arithmetic, the only solution would be to change the way science is consumed using integer but... do we want that ? Honestly, I don't care much generally the round error of science is okay.

Image
Post Reply

Return to “Duplicates”