Unitary
The Unitary class is the base class for all unitary operators in QuOp_MPI. Custom propagators should inherit from this class.
Class Reference
- class quop_mpi.Unitary(operator_function: Callable, operator_n_params: int = 0, operator_dict: dict | None = None, parameter_function: Callable | None = None, param_dict: dict | None = None, unitary_n_params: int = 1)
Bases:
BindableBase class for a
unitary.A
unitaryis derived from theUnitaryclass and implements simulation of a specfic unitary through definition of the following methods:A list of
unitaryinstances passed toquop_mpi.Ansatz.set_unitaries()defines the ansatz unitary of a QVA. After initialisation,unitaryinstances are managed by thequop_mpi.Ansatzclass and calls tounitarymethods are not made explicitly.See
quop_mpi.propagatorfor predefinedunitarysubclasses.Associated QuOp Functions:
The following attributes are common to all
unitaryinstances.- Attributes:
- final_state
The system state after the action of the unitary.
- initial_parameters
Initial variational parameters returned from the user-defined Parameter Function.
- initial_state
The initial state of the quantum system.
- n_params
The total number of unitary and operator parameterising the unitary.
- operator_function
The user-defined Operator Function.
- operator_dict
A FunctionDict of additional position and keyword arguments for the Operator Function.
- operator
The operator object returned by the Operator Function.
- operator_n_params
Number of variational operator parameters.
- parameter_function
The user-defined Parameter Function.
- param_dict
A FunctionDict of additional position and keyword arguments for the Parameter Function.
- planner
If
True, the parallel partitioning scheme returned byplan()takes precedence over non-plannerunitariesandunitariesthat appear later in the ansatz unitary list supplied toquop_mpi.Ansatz.set_unitaries().- seed
Integer for seeding random number generation, shared with
quop_mpi.Ansatz.- system_size
The size of the simulated quantum system, shared with
quop_mpi.Ansatz.- unitary_n_params
The number of unitary parameters.
- unitary_type
A string labeling the
unitarytype (e.g. “diagonal” or “sparse”).- variational_parameters
Operator variational parameters. If present as an argument of the Operator Function, a real array of size
operator_n_paramsis passed to the Operator Function.- MPI_COMM
MPI Intracommunicator, shared with
quop_mpi.Ansatz.- alloc_local
The size of the array storing the :term`operator` if the operator is an array (equal to
local_iotherwise). The second return value ofplan().- lb
The lower global index of the local system state partition.
- ub
The upper global index of the local system state partition.
- local_i
The size of the local system state partition. The first return value of
plan()- local_i_offset
The global index offset of the local system state partition.
- partition_table
1-D integer array describing the global partitioning scheme such that for a given MPI rank
partition_table[rank + 1] - partition_table[rank] = local_i
- comm_size_constraints
Constraints on valid MPI communicator sizes for this unitary. A list of 1-D integer arrays specifying divisibility requirements. Used by
quop_mpi.Ansatz()to determine compatible parallelization.
- copy_plan(ex_unitary: Unitary)
Perform any setup required by the propagation method called in
propagate().When implemented,
copy_planperforms the same internal operations asplan()using thelocal_iandalloc_localattributes ofex_unitary. Does not return[local_i, alloc_local].Warning
Not implemented by the base
Unitaryclass.- Parameters:
- ex_unitaryunitary
a
unitaryinstance with computedlocal_iandalloc_localattributes
- destroy()
Free memory allocated by Python extension modules in
plan()orcopy_plan(). collector.Memory allocated by compiled Python extension modules is typically not managed by the Python garbage collector. These allocations must be freed via relevant methods in the extension module to prevent the occurrence of memory leaks.
Warning
Not implemented by the base
Unitaryclass.
- plan(system_size: int, MPI_COMM: mpi4py.MPI.Intracomm)
Plan the partitioning scheme used by an
quop_mpi.Ansatzinstance and performs any other tasks required bypropagate().An implemented
planreturns (local_i,alloc_local). Data structures and allocation required by the propagation method called inpropagate()are assigned to attributes of theUnitaryinstance.The
alloc_localreturn value specifies the size of the local system state arraysinitial_stateandfinal_state. In most casesalloc_local == local_i, howeveralloc_local > local_imay be required by particular external propagation methods (e.g. the parallel FFTW).Warning
Not implemented by the base
Unitaryclass.- Parameters:
- system_sizeint
size of the simulated quantum system.
- MPI_COMMIntracomm
MPI communicator over which the
Ansatzobservables, initial state and final state are partitioned.
- Returns:
- (int, int)
number of elements in a row-wise partitioning of the system state and size to allocate for the
initial_stateandfinal_statearrays
Examples
def plan(self, system_size, MPI_COMM): local_i = system_size // MPI_COMM.size local_i = ( system_size - local_i * MPI_COMM.rank if MPI_COMM.rank == 0 else local_i ) alloc_local = local_i return local_i, alloc_local
- propagate(x: np.ndarray[np.float64])
Simulation of the action of a :term`unitary`.
When implemented,
propagatecontains a call to a method (typically a contained in a complied Python extension module) that takes the class attributesinitial_state,final_stateandMPI_COMM, together with attributes describing the parallel partitioning scheme and variational parametersx, as input. The action of the unitary is computed in MPI parallel, with the computed result written tofinal_state.Warning
Not implemented by the base
Unitaryclass.- Parameters:
- xndarray[float64]
a 1-D real array of
n_paramsvariational parameters
Examples
def propagate(self, x): external_propagator( x, self.partition_table, self.initial_state, self.final_state, self.MPI_COMM )