Meta
Meta-algorithms that coordinate multiple Ansatz instances.
Swarm
The swarm class enables parallel execution of multiple independent Ansatz instances, useful for parameter sweeps or ensemble methods.
- class quop_mpi.meta.swarm(nodes_per_subcomm: int, processes_per_node: int, maxcomm: int, MPI_COMM: COMM_WORLD, alg: type, *args, **kwargs)
Bases:
objectCreate and operate on a swarm of identical
Ansatzinstances.Each
Ansatzinstance is associated with an MPI subcommunicator such that they can carry out QVA simulation independently.The
Ansatzinstance is initialised by theswarminstance as,Ansatz(*args, MPI_COMM, **kwargs)
- Parameters:
- nodes_per_subcommint
number of compute nodes associated with each
Ansatzsubcommunicator, ifnodes_per_subcomm == 1createmaxcommsubcommunicators per available compute node.- processes_per_nodeint
number of MPI processes per compute node, must be the same for all nodes
- maxcommint
target number of
Ansatzsubcommunicators- MPI_COMMIntracomm
MPI communicator from which to create the
Ansatzsubcommunicators- algAnsatz
an
Ansatz,quop_mpi.Ansatzor a predefined algorithm (seequop_mpi.algorithm)
- benchmark(*args, **kwargs)
Test QVA performance as a function of Ansatz Depth.
- Parameters:
- args: list[Ans] or list[list[Any]]
positional arguments for
quop_mpi.Ansatz.benchmark(), or a list of positional arguments specifying unique input forquop_mpi.Ansatz.benchmark()for eachAnsatzinstance.- kwargs: dict
keyword arguments for
quop_mpi.Ansatz.benchmark(), or keywords pointing to a list of positional arguments specifying unique input forquop_mpi.Ansatz.benchmark()for eachAnsatzinstance.
See also
benchmark()
- benchmark_swarm(ansatz_depths: Iterable[int], repeats: int, basename: str, param_persist: bool = True, verbose: bool = True, save_action: str = 'a', time_limit: float | None = None, logging: bool = True, suspend_path: str | None = None)
Test QVA performance with increasing ansatz depth with repeats at each depth computed in parallel over the
swarm.- Parameters:
- ansatz_depthsIterable[int]
simulated ansatz depths
- repeatsint
number of repeats at each ansatz depth
- basenamestr
path to directory in which to write simulation results and logs, by default
None- param_persistbool, optional
if
Truethe optimised variational parameter values which achieved the lowest objective function value for all repeats atansatz_depthwill be used as starting parameters for the firstansatz_depth * total_paramsatansatz_depth += 1, by defaultTrue- verbosebool, optional
if
True, print current the ansatz depth, repeat number and optimisation results, by defaultTrue- save_action{‘a’, ‘w’}
‘a’ to append, ‘w’ to (over)write, by default “a”
- time_limitfloat, optional
time limit in seconds, program will suspend if the time remaining is less than the time taken by the last simulation, by default
None- loggingbool, optional
write simulation results to log files, by default
True- suspend_pathstr, optional
path to directory in which to write suspend data, by default
None
- Returns:
- list[dict]
optimisation results ordered by ansatz depth
- execute_swarm(param_lists: list[np.ndarray[np.float64]], basename: str, log_path: str = None, h5_path: str = None, labels: str | list[str] = None, save_action: str = 'a', time_limit: float = None, verbose: bool = True, suspend_path: str = None)
Parallel simulation of QVAs over a set of initial variational parameters.
- Parameters:
- param_listslist[np.ndarray[np.float64]]
list of 1-D real arrays containing initial variational parameters
- basenamestr
folder in which to store simulation results and suspend data unless otherwise specified, by default
None- log_pathstr, optional
folder in which to write simulation log files, by default
None- h5_pathstr, optional
folder in which to write simulation results, by default
None- labelsstr or list[str], optional
labels(s) for each simulation, by default
None- save_action{“a”, “w”}
“a” to append “w” to (over)write, by default
"a"- time_limitfloat, optional
suspend if the time remaining is less than the time taken by the last QVA simulation, by default
None- verbosebool, optional
print the simulation results and simulation progress, by default
True- suspend_pathstr, optional
folder in which to store suspend data, by default
None
- Returns:
- dict
a dictionary of optimisation results with keys
str(params_list[i])
- get_optimal_result() dict
Retrieve the result with the lowest objective function value out of the last set of simulations executed by the
swarm.- Returns:
- dict
simulation result
- save(*args, **kwargs)
Save simulation results.
- Parameters:
- args:
positional arguments for
quop_mpi.Ansatz.save(), or a list of positional arguments specifying unique input forquop_mpi.Ansatz.save()for eachAnsatzinstance.- kwargs:
keyword arguments for
quop_mpi.Ansatz.save(), or keywords pointing to a list of positional arguments specifying unique input forquop_mpi.Ansatz.save()for eachAnsatzinstance.
See also
save()
- set_log(*args, **kwargs)
Log simulation information.
- Parameters:
- args: list[Any] or list[list[Any]]
positional arguments for
quop_mpi.Ansatz.set_log(), or a list of positional arguments specifying unique input forquop_mpi.Ansatz.set_log()for eachAnsatzinstance.- kwargs: dict
keyword arguments for
quop_mpi.Ansatz.set_log(), or keywords pointing to a list of positional arguments specifying unique input forquop_mpi.Ansatz.set_log()for eachAnsatzinstance.
See also
set_log()
- set_unitaries(unitaries: list[Unitary] | list[list[Unitary]])
Set the unitaries of an
Ansatzswarm.- Parameters:
- unitaries :list[Unitary] or list[list[Unitary]]
a list of
unitaryinstances (broadcast to all swarm instances) or a list ofunitaryinstances for eachAnsatzinstance in theswarm
- Raises:
- RuntimeError
if
unitaries`is a list of lists that is not equal to the :literal:`swarmsize