ZOSAPI.Tools.Optimization.IGlobalOptimization Interface Reference
Last update: 16.07.2025Interfaces and methods for running a Global Optimization. This interface can be accessed via the IOpticalSystemTools interface. More...
Inheritance diagram for ZOSAPI.Tools.Optimization.IGlobalOptimization:

Public Member Functions | |
| double | CurrentMeritFunction (int N) |
| bool | EstimateHPCTime () |
Public Member Functions inherited from ZOSAPI.Tools.ISystemTool | |
| bool | Run () |
| Start the tool. Note that for synchronous tools (see IsAsynchronous), this call will block until completion. If it is asynchronous it will start running but return immediately. | |
| bool | RunAndWaitForCompletion () |
| Sames as calling Run followed by WaitForCompletion. | |
| bool | WaitForCompletion () |
| Waits for the asynchronous tool to complete. | |
| bool | Cancel () |
| Cancels the currently running asynchronous tool. | |
| bool | Close () |
| Closes this tool and frees up and associated resources. | |
| RunStatus | WaitWithTimeout (double timeOutSeconds) |
| Waits for the currently running tool to complete, with a specified time out value. Note that if the timeout is exceeded this method will return, however the tool will continue to run. Also note that this method will not start the tool running if it is not already. | |
| RunStatus | RunAndWaitWithTimeout (double timeOutSeconds) |
| Starts the tool running, and waits for it to complete with the specified timeout value. Note that if the timeout is exceeded this method will return, however the tool will continue to run. | |
Properties | |
| OptimizationAlgorithm | Algorithm [get, set] |
| int | NumberOfCores [get, set] |
| int | MaxCores [get] |
| OptimizationSaveCount | NumberToSave [get, set] |
| int | Targets [get] |
| int | Variables [get] |
| double | InitialMeritFunction [get] |
| long | Systems [get] |
| int | Cycles [get] |
| double | CurrentMeritFunction01 [get] |
| double | CurrentMeritFunction02 [get] |
| double | CurrentMeritFunction03 [get] |
| double | CurrentMeritFunction04 [get] |
| double | CurrentMeritFunction05 [get] |
| double | CurrentMeritFunction06 [get] |
| double | CurrentMeritFunction07 [get] |
| double | CurrentMeritFunction08 [get] |
| double | CurrentMeritFunction09 [get] |
| double | CurrentMeritFunction10 [get] |
| bool | IsHPCEnabled [get] |
| double | HPCEstimatedTimeS [get] |
| double | HPCRemainingTimeS [get] |
| double | HPCTimeToStartS [get] |
| int | HPCQueuePosition [get] |
| HPCRunState | HPCState [get] |
| bool | HPCHasTimeEstimate [get] |
| double | TargetRunTimeM [get, set] |
Properties inherited from ZOSAPI.Tools.ISystemTool | |
| int | Progress [get] |
| Gets the progress of the current tool, if supported. | |
| string | Status [get] |
| Gets the status of the current tool, if supporoted. | |
| bool | IsRunning [get] |
| Gets a value indicating whether the tool is currently running asynchronously. | |
| bool | CanCancel [get] |
| Gets a value indicating whether the tool can be cancelled. | |
| bool | IsAsynchronous [get] |
| Gets a value indicating whether the tool runs asynchronously (i.e. on a thread). | |
| bool | IsFiniteDuration [get] |
| Gets a value indicating whether this tool will complete on its own. | |
| bool | IsValid [get] |
| Gets a value indicating whether the input settings are valid. | |
| bool | Succeeded [get] |
| Gets a value indicating whether the tool execution succeeded. | |
| string | ErrorMessage [get] |
If Succeeded is false, get the error messages; otherwise, null. | |
Detailed Description
Interfaces and methods for running a Global Optimization. This interface can be accessed via the IOpticalSystemTools interface.
Usage (see Example 15 for a full sample)
C#
// run global search
double GlobalOptimTimeInSeconds = 15;
IGlobalOptimization GlobalOpt = TheSystem.Tools.OpenGlobalOptimization();
if (GlobalOpt != null)
{
GlobalOpt.NumberOfCores = 8;
Console.WriteLine("Global Optimization for " + GlobalOptimTimeInSeconds.ToString() + " seconds...");
Console.WriteLine(String.Format("Initial Merit Function {0}", GlobalOpt.InitialMeritFunction));
GlobalOpt.RunAndWaitWithTimeout(GlobalOptimTimeInSeconds);
for (int j = 1; j <= 10; j++)
{
Console.Write(String.Format("{0}: {1}\n", j, GlobalOpt.CurrentMeritFunction(j)));
}
GlobalOpt.Cancel();
GlobalOpt.WaitForCompletion();
GlobalOpt.Close();
}
bool WaitForCompletion()
Waits for the asynchronous tool to complete.
RunStatus RunAndWaitWithTimeout(double timeOutSeconds)
Starts the tool running, and waits for it to complete with the specified timeout value....
Interfaces and methods for running a Global Optimization. This interface can be accessed via the IOpt...
Definition: Optimization.cs:109
double InitialMeritFunction
Definition: Optimization.cs:117
double CurrentMeritFunction(int N)
Definition: Optimization.cs:9
Definition: FileSource.cs:4
The ZOSAPI namespace contains classes for initially connecting to zemax. See also ZOSAPI_Connection,...
Definition: IAS_FieldCurvatureAndDistortion.cs:5
C++
// run global search
int GlobalOptimTimeInSeconds = 15;
IGlobalOptimizationPtr GlobalOpt = TheSystem->Tools->OpenGlobalOptimization();
if (GlobalOpt != nullptr) {
GlobalOpt->Algorithm = OptimizationAlgorithm::OptimizationAlgorithm_DampedLeastSquares;
GlobalOpt->NumberOfCores = 8;
cout << "Global Optimization for " << GlobalOptimTimeInSeconds << " seconds..." << endl;
cout << "Initial Merit Function " + _bstr_t(GlobalOpt->InitialMeritFunction) << endl;
GlobalOpt->NumberToSave = OptimizationSaveCount::OptimizationSaveCount_Save_10;
ISystemToolPtr baseToolGlobal = GlobalOpt;
baseToolGlobal->RunAndWaitWithTimeout(GlobalOptimTimeInSeconds);
for (int j = 1; j <= 10; j++) {
cout << _bstr_t(int(j)) + ": " + _bstr_t(GlobalOpt->CurrentMeritFunction(j)) << endl;
}
baseToolGlobal->Cancel();
// wait for tool to stop running before closing
//bool stillRunning = baseToolGlobal->IsRunning;
//while (stillRunning) {
// stillRunning = baseToolGlobal->IsRunning;
//}
baseToolGlobal->WaitForCompletion();
baseToolGlobal->Close();
}
Matlab
% run global search
GlobalOptimTimeInSeconds = 15;
GlobalOpt = TheSystem.Tools.OpenGlobalOptimization();
if ~isempty(GlobalOpt)
GlobalOpt.NumberOfCores = 8;
fprintf('Global Optimization for %i seconds...\n', GlobalOptimTimeInSeconds);
fprintf('Initial Merit Function %6.3%\n', GlobalOpt.InitialMeritFunction);
GlobalOpt.RunAndWaitWithTimeout(GlobalOptimTimeInSeconds);
for j =1:10
fprintf('%i: %6.3f\n', j, GlobalOpt.CurrentMeritFunction(j));
end
GlobalOpt.Cancel();
GlobalOpt.WaitForCompletion();
GlobalOpt.Close();
end
Python
# run global search
GlobalOptimTimeInSeconds = 5
GlobalOpt = TheSystem.Tools.OpenGlobalOptimization()
if (GlobalOpt != None):
GlobalOpt.Algorithm = ZOSAPI.Tools.Optimization.OptimizationAlgorithm.DampedLeastSquares
GlobalOpt.NumberOfCores = 8
print('Global Optimization for ' + str(GlobalOptimTimeInSeconds) + ' seconds...')
print('Initial Merit Function ', GlobalOpt.InitialMeritFunction)
GlobalOpt.NumberToSave = ZOSAPI.Tools.Optimization.OptimizationSaveCount.Save_10
GlobalOpt.RunAndWaitWithTimeout(1 * GlobalOptimTimeInSeconds)
for j in range(1, 11):
print(str(int(j)) + ': ' + str(GlobalOpt.CurrentMeritFunction(j)))
GlobalOpt.Cancel()
GlobalOpt.WaitForCompletion()
GlobalOpt.Close()
Member Function Documentation
◆ CurrentMeritFunction()
| double ZOSAPI.Tools.Optimization.IGlobalOptimization.CurrentMeritFunction | ( | int | N | ) |
◆ EstimateHPCTime()
| bool ZOSAPI.Tools.Optimization.IGlobalOptimization.EstimateHPCTime | ( | ) |
Property Documentation
◆ Algorithm
|
getset |
◆ CurrentMeritFunction01
|
get |
◆ CurrentMeritFunction02
|
get |
◆ CurrentMeritFunction03
|
get |
◆ CurrentMeritFunction04
|
get |
◆ CurrentMeritFunction05
|
get |
◆ CurrentMeritFunction06
|
get |
◆ CurrentMeritFunction07
|
get |
◆ CurrentMeritFunction08
|
get |
◆ CurrentMeritFunction09
|
get |
◆ CurrentMeritFunction10
|
get |
◆ Cycles
|
get |
◆ HPCEstimatedTimeS
|
get |
◆ HPCHasTimeEstimate
|
get |
◆ HPCQueuePosition
|
get |
◆ HPCRemainingTimeS
|
get |
◆ HPCState
|
get |
◆ HPCTimeToStartS
|
get |
◆ InitialMeritFunction
|
get |
◆ IsHPCEnabled
|
get |
◆ MaxCores
|
get |
◆ NumberOfCores
|
getset |
◆ NumberToSave
|
getset |
◆ Systems
|
get |
◆ TargetRunTimeM
|
getset |
◆ Targets
|
get |
◆ Variables
|
get |
Public Member Functions inherited from