(My questions are towards the end of this posting.)
I have been doing tests on the Strategy Analyzer's optimization feature. I notice that when it runs, it effectively launches multiple threads that each process a combination of properties.
Example: I created a basic strategy that does nothing but output its current configuration in a separate text file based on the thread's managed identifier. Here is the important portion of the settings:
I am simply going through the cross-product of the values 1 and 2 for both test properties A and B.
After running the optimization, I notice that I have 8 files, which implies that 8 threads were launched during the optimization process. (The filenames start with the letter T, followed by the thread identifier.)
The text files contain a timestamp followed by the current state each time that OnStateChange() is called, followed by the current values of A and B.
I also log each call to OnBarUpdate() to indicate when it is called during the chain of events.
I do see files for each pairing of values.
File: T0075_DEBUG.txt
Pair:(1, 1)
18:19:00.7966 | State: SetDefaults | A: 0 | B: 0 18:19:00.7986 | State: Configure | A: 1 | B: 1 18:19:00.8006 | State: DataLoaded | A: 1 | B: 1 18:19:00.8216 | State: Historical | A: 1 | B: 1 18:19:00.8226 | 2023-03-30 12:00 18:19:00.8226 | 2023-03-30 12:15 18:19:00.8236 | 2023-03-30 12:30 18:19:00.8236 | 2023-03-30 12:45 18:19:00.8246 | 2023-03-30 13:00 18:19:00.8246 | 2023-03-30 13:15 18:19:00.8256 | 2023-03-30 13:30 18:19:00.8256 | 2023-03-30 13:45 18:19:00.8266 | 2023-03-30 14:00 18:19:00.8266 | 2023-03-30 14:15 18:19:00.8276 | 2023-03-30 14:30 18:19:00.8276 | 2023-03-30 14:45 18:19:00.8286 | 2023-03-30 15:00 18:19:00.8365 | State: Terminated | A: 1 | B: 1
File: T0033_DEBUG.txt
Pair:(1, 2)
18:19:00.7966 | State: SetDefaults | A: 0 | B: 0 18:19:00.7986 | State: Configure | A: 1 | B: 2 18:19:00.8006 | State: DataLoaded | A: 1 | B: 2 18:19:00.8216 | State: Historical | A: 1 | B: 2 18:19:00.8226 | 2023-03-30 12:00 18:19:00.8226 | 2023-03-30 12:15 18:19:00.8236 | 2023-03-30 12:30 18:19:00.8236 | 2023-03-30 12:45 18:19:00.8246 | 2023-03-30 13:00 18:19:00.8246 | 2023-03-30 13:15 18:19:00.8256 | 2023-03-30 13:30 18:19:00.8256 | 2023-03-30 13:45 18:19:00.8266 | 2023-03-30 14:00 18:19:00.8266 | 2023-03-30 14:15 18:19:00.8276 | 2023-03-30 14:30 18:19:00.8276 | 2023-03-30 14:45 18:19:00.8286 | 2023-03-30 15:00 18:19:00.8375 | State: Terminated | A: 1 | B: 2
File: T0036_DEBUG.txt
Pair:(2, 1)
18:19:00.7966 | State: SetDefaults | A: 0 | B: 0 18:19:00.7986 | State: Configure | A: 2 | B: 1 18:19:00.8006 | State: DataLoaded | A: 2 | B: 1 18:19:00.8216 | State: Historical | A: 2 | B: 1 18:19:00.8226 | 2023-03-30 12:00 18:19:00.8226 | 2023-03-30 12:15 18:19:00.8236 | 2023-03-30 12:30 18:19:00.8236 | 2023-03-30 12:45 18:19:00.8246 | 2023-03-30 13:00 18:19:00.8246 | 2023-03-30 13:15 18:19:00.8256 | 2023-03-30 13:30 18:19:00.8256 | 2023-03-30 13:45 18:19:00.8266 | 2023-03-30 14:00 18:19:00.8266 | 2023-03-30 14:15 18:19:00.8276 | 2023-03-30 14:30 18:19:00.8276 | 2023-03-30 14:45 18:19:00.8286 | 2023-03-30 15:00 18:19:00.8385 | State: Terminated | A: 2 | B: 1
File: T0087_DEBUG.txt
Pair:(2, 2)
18:19:00.7966 | State: SetDefaults | A: 0 | B: 0 18:19:00.7986 | State: Configure | A: 2 | B: 2 18:19:00.8006 | State: DataLoaded | A: 2 | B: 2 18:19:00.8216 | State: Historical | A: 2 | B: 2 18:19:00.8226 | 2023-03-30 12:00 18:19:00.8226 | 2023-03-30 12:15 18:19:00.8226 | 2023-03-30 12:30 18:19:00.8236 | 2023-03-30 12:45 18:19:00.8236 | 2023-03-30 13:00 18:19:00.8246 | 2023-03-30 13:15 18:19:00.8246 | 2023-03-30 13:30 18:19:00.8256 | 2023-03-30 13:45 18:19:00.8256 | 2023-03-30 14:00 18:19:00.8266 | 2023-03-30 14:15 18:19:00.8266 | 2023-03-30 14:30 18:19:00.8276 | 2023-03-30 14:45 18:19:00.8276 | 2023-03-30 15:00 18:19:00.8385 | State: Terminated | A: 2 | B: 2
The preceding files are all as expected! They pass through all states up until the Terminated state.
However, the remaining 4 files contain unusual information.
File: T0012_DEBUG.txt
This file seems to repeat the pair 2,1, but doesn't make it to the Terminated state. This seems like an anomaly. Why repeat a pair that was already processed on a different thread?
[18:19:01.0290 | State: Configure | A: 2 | B: 1 18:19:01.0300 | State: DataLoaded | A: 2 | B: 1 18:19:01.0320 | State: Historical | A: 2 | B: 1 18:19:01.0320 | 2023-03-30 12:00 18:19:01.0320 | 2023-03-30 12:15 18:19:01.0330 | 2023-03-30 12:30 18:19:01.0330 | 2023-03-30 12:45 18:19:01.0340 | 2023-03-30 13:00 18:19:01.0340 | 2023-03-30 13:15 18:19:01.0340 | 2023-03-30 13:30 18:19:01.0350 | 2023-03-30 13:45 18:19:01.0350 | 2023-03-30 14:00 18:19:01.0360 | 2023-03-30 14:15 18:19:01.0360 | 2023-03-30 14:30 18:19:01.0360 | 2023-03-30 14:45 18:19:01.0370 | 2023-03-30 15:00
File: T0021_DEBUG.txt
I don't know what is going on in this thread. I see values that are completely outside the range of the pairs.
18:19:00.0920 | State: SetDefaults | A: 0 | B: 0 18:19:00.8415 | State: SetDefaults | A: 0 | B: 0 18:19:00.8934 | State: Terminated | A: 20 | B: 14 18:19:01.0111 | State: Terminated | A: 2 | B: 1 18:19:01.0121 | State: Terminated | A: 20 | B: 14 18:19:01.0121 | State: SetDefaults | A: 0 | B: 0 18:19:01.0280 | State: SetDefaults | A: 0 | B: 0 18:19:01.0500 | State: Terminated | A: 2 | B: 1 18:19:01.5537 | State: SetDefaults | A: 0 | B: 0 18:19:01.5547 | State: Terminated | A: 20 | B: 14
File: T0002_DEBUG.txt
Another unusual thread with invalid values.
I have no idea how this thread managed to output a line without the prefix timestamp.
18:19:00.357 | State: Terminated | A: 20 | B: 14 State: Terminated | A: 20 | B: 14 18:19:00.364 | State: Terminated | A: 20 | B: 14 18:19:00.797 | State: Terminated | A: 20 | B: 14
File: T0004_DEBUG.txt
Only one line in this thread, but with invalid values.
18:19:00.0970 | State: Configure | A: 20 | B: 14
Question 1: Aren't these last 4 threads unusual?
Question 2: What are they trying to do?
I can see how they might confuse coding logic and potentially cause unexpected results.
Attached are relevant files. I could not attach more than 5 files, so the actual debug files are not included..
Thanks for your reply.
Ray
[P.S. I am not able to edit my typo in the posting title.]
Comment