\section{Introduction}

The prediction of the future development of a running case, given information about past cases and the current state of the case, i.e. predicting trace suffixes from trace prefixes, is a core problem in business process intelligence (BPI). Recently, deep learning \cite{LeCunetal:2015,DBLP:journals/nn/Schmidhuber15} with artificial neural networks has become an import predictive method due to innovations in neural network architectures, the availability of high-performance GPU and cluster-based systems, and the open-sourcing of of multiple software frameworks at a high level of abstraction.

Because of the sequential nature of process traces, recurrent neural networks are a natural fit to the problem of process prediction. An initial application of RNN to BPI \cite{Evermannetal:2016} used the executing activity of each trace event as both predictor and predicted variable. Evaluation on the BPI 2012 and 2013 challenge datasets showed training performance of up to 90\%, but that study did not perform cross-validation. A more systematic study \cite{EvermannRF2017}, including cross validation, showed significant overfitting of the earlier results, i.e. the neural network capitalizes on idiosyncrasies of the training sample that do not generalize. The later work also showed that the size of the neural network has a significant effect on predictive performance. Further, predictive performance can be improved when organizational data is included as predictor. Both \cite{EvermannRF2017} and \cite{Evermannetal:2016} use approaches in which each ``word'' (e.g. the name of the executing activity of each event) is embedded in a k-dimensional vector space (details in Sec.~\ref{sec:inputs} below), which forms the input to the neural network. In contrast, an independent, parallel effort \cite{DBLP:journals/corr/TaxVRD16} eschews the use of embeddings, encoding event information as numbered categories in one-hot form. That approach also adds time-of-day and day-of-week as additional predictors. Both approaches compare the predicted suffix to the target suffix by means of a string edit distance, showing similar performance. Additionally, \cite{EvermannRF2017} demonstrates that predicted suffixes are similar to targets by showing similar replay fitness on a model mined from the target traces.

The software application described here extends the previous approaches in a number of ways. Primarily, it is more general and flexible with respect to the case and event attributes that can be used as predictor or predicted variables. Whereas \cite{EvermannRF2017,DBLP:journals/corr/TaxVRD16} use only the activity name and lifecycle transition of an event, and \cite{EvermannRF2017} also includes resource information of an event as predictor, our application can use any case- or event-level attribute as predictor. We can also predict any and multiple event attributes of subsequent events. These advantages are due to differences in input encoding. Whereas \cite{EvermannRF2017} concatenates activity name, lifecycle transition and resource information into an input string, which is then assigned a category number and embedded in a vector space for input to the neural network, our approach assigns category numbers to each input attribute separately, then embeds them into their own vector spaces and concatenates the embedding vectors to form the input vector. Details are presented in Sec.~\ref{sec:inputs}. The advantage is much smaller input ``vocabularies'' (sets of unique inputs) which can be adequately represented by much smaller input vectors. It also allows easy mixing of categorical predictors with embedding inputs and numerical predictors which are directly passed to the neural net, simply by concatenating these inputs.

Additionally, our approach can predict multiple variables, for example the activity as well as the resource information of the next event. We use either shared or separate RNN layers for each predicted attribute.

Finally, the software tool presented in this demo paper includes a graphical user interface that guides novice users and avoids the need for specialized coding, it provides integration with a graphical dashboard, and a stand-alone prediction application with an easy-to-use prediction API.

As a demo paper, this paper focuses on the software implementation, architecture and user interface with only a short exposition of the neural network background. In particular, we describe the input and output handling of the neural network (Sections~\ref{sec:inputs}, \ref{sec:outputs}), as this is where our approach differs from \cite{EvermannRF2017,DBLP:journals/corr/TaxVRD16}.  More details on neural networks in general can be found in \cite{LeCunetal:2015,DBLP:journals/nn/Schmidhuber15}, and, applied to process prediction, in \cite{EvermannRF2017,DBLP:journals/corr/TaxVRD16}. Our software is open-source and available from the authors\footnote{\url{http://joerg.evermann.ca/software.html}}.

\section{Recurrent Neural Networks Overview}

A recurrent neural network (RNN) is one in which network cells can maintain state information by feeding the state output back to themselves, often using a form of long short term memory (LSTM) cells \cite{DBLP:journals/neco/HochreiterS97}. To make this feedback tractable within the context of backpropagation, network cells are copied, or ``unrolled'', for a number of steps. Fig.~\ref{fig:rnn} shows an example RNN with LSTM cells; detailed descriptions can be found in \cite{EvermannRF2017,DBLP:journals/corr/TaxVRD16}.

\begin{figure}
\centering
\includegraphics[width=\linewidth]{rnn}
\caption{An RNN with 5 unrolled steps, 2 layers, batch size $b$ and input length $k$}
\label{fig:rnn}
\end{figure}

\section{Tensorflow}

Our software implementation is based on the open-source Tensorflow deep learning framework\footnote{\url{https://www.tensorflow.org}}. Tensors are generalizations of matrices to more than two dimensions, i.e. n-dimensional arrays. A Tensorflow application builds a computational graph using tensor operations. A loss function is a graph node that is to be minimized. It compares computed outputs to target outputs in some way, for example as cross-entropy for categorical variables, or root mean squared error for numeric variables. Tensorflow computes gradients of all tensors in the graph with respect to the loss function and provides various gradient descent optimizers. Training proceeds by iteratively feeding the Tensorflor computational graph with inputs and targets and optimizing the loss function using back-propagated errors.

\section{Training}

Our software system consists of two separate applications, one for training a deep-learning model, and another one for predicting from a trained model. This section describes the training application.

\subsection{XES Parser}

Training data is read from XES log files \cite{xes}, beginning with global attribute and event classifier definitions. Using these, the traces and their events are read. While the XES standard allows traces and events to omit globally declared attributes, it does not allow specification of default values for missing attributes. Hence, the XES parser omits any incomplete or empty traces. String-typed attributes are treated as categorical variables. Their unique values (categories) are numbered consecutively, encoding each as an integer in $0 \ldots l_i$, where $l_i$ is the number of unique values for attribute $i$. Datetime-typed attributes are converted to relative time differences from the previous event. The user can choose whether to standardize or to scale them to days, hours, minutes or seconds for meaningful loss functions. Numerical attributes are standardized. For multi-attribute event classifiers, the parser constructs joint attributes by concatenating the string-typed attributes or by multiplying the numerically-typed attributes specified in the classifier definition. End-of-case markers are inserted after each trace.

\subsection{Inputs}
\label{sec:inputs}

RNN training proceeds in ``epochs''. In each epoch, the entire training dataset is used. Before each epoch, the state of the RNN is reset to zero while trained network parameter values are retained. Within each epoch, training proceeds in batches of size $b$ with averaged gradients to avoid overly large fluctuations of gradients. The batch size $b$ can be freely chosen by the user.

For each unrolled step $s$, the RNN accepts a floating point input tensor $I_s \in \R^{b \times p}$, where $b$ is the batch size and $p$ can be freely chosen. Numerical and datetime predictors are encoded directly, each yielding a floating point tensor $I_{s, i} \in \R^{b \times 1}$ for predictor attribute $i$. Categorical attributes, encoded as integer category numbers, are transformed using an embedding matrix $E_i \in \R^{l_i \times k_i}$. This is a lookup matrix of size $l_i \times k_i$, where $l_i$ is the number of categories for predictor attribute $i$ and $k_i$ can be freely chosen. Embedding lookup transforms an integer category number $j_{s,i}$ to a floating point vector of size $k_i$. The larger the value of $k_i$, the better the attribute values are separated in the $k_i$-dimensional space. At the same time, larger $k_i$ lead to increased computational demands. The output of the embedding lookup $E(.)$ is a tensor $I_{s, i} \in \R^{b \times k_i} = E(j_{s, i})$. The tensors for all predictor attributes are concatenated, yielding a tensor $C_s \in \R^{b \times m}$ where $m$ is the sum of the second dimensions of the concatenated tensors. An input projection $P^I_s \in \R^{m \times p}$ can be applied so that the input to each unrolled step of the RNN is $I_s = C_s \times P^I_s$.

\subsection{Model}

In our approach, the user can train a model on multiple predicted event attributes (``target variables'') concurrently, for example predicting the activity as well as the resource of the next event. For this, the user can choose to share the RNN layers across the different target variables, or to construct a separate RNN for each target variable. The input embeddings are shared in all cases.

\subsection{Outputs}
\label{sec:outputs}

The output of the RNN for each unrolled step is a tensor $O_{s} \in \R^{b \times p}$. For a categorical predicted variable $i$, this is multiplied by an output projection $P^O_{s, i} \in \R^{p \times l_i}$ to yield $O_{s, i} \in \R^{b \times l_i} = O_s \times P^O_{s, i}$. A softmax function is applied to generate probabilities over the $l_i$ different categories $S_{s, i} \in \R^{b \times l_i} = \text{softmax}_{l_i}(O_{s, i})$. A cross-entropy loss function $L_i = H_{S_{s, i}}(T_{s, i})$ is then applied, comparing the output probabilities against ``one-hot'' encoded targets $T$. One-hot encoding is a vector with the element indicating the target category number equal to one and the remainder set to zero. For numerical attributes, the output $O_s$ is multiplied by a $P^O_{s, i} \in \R^{p \times 1}$ output projection, yielding $O_{s, i} \in \R^{b \times 1} = O_s \times P^O_{s, i}$. This is compared to target values $T_{s, i}$ using the mean square error (MSE) $L_i = \overline{(O_{s, i} - T_{s, i})^2}$, the root mean square error (RMSE) $L_i = \sqrt{\overline{(O_{s, i} - T_{s, i})^2}}$, or the mean absolute error (MAE) loss function $L_i = \overline{|O_{s, i} - T_{s, i}|^2}$.

\subsection{Logging and TensorBoard Integration}

\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{Tensorboard}
\caption{Tensorboard dashboard showing training performance for 10 folds}
\label{fig:tensorboard}
\end{figure}

Our software logs summary information about the proportion of correct predictions and the loss function value for each training step. The embedding matrices for all categorical predictor variables are saved at the end of training, together with the computational graph. This information can be read by the Tensorboard tool (Fig.~\ref{fig:tensorboard}) to visualize the training performance, the graph structure, and to analyze the embedding matrices using t-SNE or principal components projection into two or three dimensions. Finally, the entire trained network is saved in a ``frozen'', compacted form to be loaded into the prediction application.

\section{Prediction}

The prediction application loads a trained model, saved by the training application, as well as the corresponding training configuration, and predicts trace suffixes from trace prefixes. Trace prefixes are read from XES files. Because the trained model expects batches of size $b$, at most $b$ trace prefixes are loaded at a time. The network state is initialized to zero and the trace prefixes are input to the trained network, encoded as described in Sec.~\ref{sec:inputs}. The network outputs for the last element of a trace prefix are the predictions for the attributes of the next event. For categorical attributes, the integer output indicating the category number is translated back to the character string value. For datetime-typed attributes, the attribute value is computed by adding the predicted value to the attribute value of the prior event. The predicted event is then added to the trace prefix and the prediction process can be repeated. In this way, suffixes of arbitrary length can be predicted. The user can stop prediction when an end-of-case marker has been predicted, or after a specified number of events have been predicted. The predicted suffixes are written back to an XES file.

\section{Software Implementation}

Our software is implemented in Python 2.7 and uses Tensorflow 0.12 and Tkinter for the user interface. Figure~\ref{fig:main} shows the main screen that guides the user through the selection of an XES file, the configuration of the RNN and training parameters, to the training of the model.

\begin{figure}
\centering
\includegraphics[scale=0.4]{MainScreen}
\caption{Main screen of the training application}
\label{fig:main}
\end{figure}

Figure~\ref{fig:config} shows the main configuration screen with sections for multi-attribute classifiers, global event and case attributes, RNN and training parameters and a choice of optimizer. Any classifier, global event and case attribute may be included as predictor, and classifiers and global event attributes may be chosen as predicted attributes (targets). The user can specify embedding dimensions for categorical attributes; the default values are the square root of the number of categories. The RNN configuration allows the user to specify batch size, number of unrolled steps, number of RNN layers, number of training epochs, etc. Users can specify an optional input mapping and the desired size of the RNN input vector. Finally, users have a choice of different gradient descent optimizers offered by Tensorflow and can adjust their hyperparameters. Configurations are automatically saved and the user can load saved configurations.

\begin{figure}
\centering
\includegraphics[width=\textwidth]{ConfigScreen}
\caption{Configuration screen. User can choose multiple predictors and targets, set general training parameters, and choose an optimizer.}
\label{fig:config}
\end{figure}

Figure~\ref{fig:train} shows the dialog indicating training progress. The current operation is shown, as well as the training rate (events/second) and the global learning rate for the gradient descent optimizer. For each predicted attribute, the latest training performance (proportion of correct prediction and loss function value) is shown.

\begin{figure}
\centering
\includegraphics[scale=0.4]{TrainScreen}
\caption{Progress screen of the training process}
\label{fig:train}
\end{figure}

Our focus is on providing a research tool for experimentation, rather than a production tool. Therefore, we have not made use of distributed Tensorflow and Tensorflow Serving. Tensorflow automatically allocates the compute operations to available CPUs and GPUs on a single machine. This provides adequate performance for the small size of typical event logs (megabyte rather than terabyte). We use our own prediction application with a simple API.

\section{Conclusion}

We presented a flexible deep-learning software application to predict business processes from industry-standard XES event logs. The software provides an easy-to-use graphical user interface for configuring predictors, targets, and parameters of the deep-learning prediction method.

We have performed initial validation of the software to verify the correct operation of the software tool. Using the BPIC 2012 and 2013 datasets with the model and training parameters reported in \cite{EvermannRF2017}, this software tool replicates their training results in \cite{EvermannRF2017}. Current work with this software tool is ongoing, and focuses on using different combinations of predictors and targets, made possible by our flexible approach to handling predictors and constructing RNN inputs, to improve upon the state-of-the-art prediction performance.

\bibliographystyle{splncs03}


\section{Introduction}

The deployment of Distributed Energy Resources (DERs) in the residential low voltage (LV) microgrids (MGs) aims to improve their self-sustainability and reduce the transmission losses \cite{ref1m}.
DERs based on renewable resources, such as solar photovoltaic (PV), are traditionally operated at capacity to inject all available power in the grid and thus maximize the efficiency, regardless of the grid state.
However, the variability of the capacity may cause erratic voltage behavior on the distribution feeders.
In particular, grids with high penetration of PVs may experience voltage increase over the recommended levels, e.g., during afternoons, when the production is high and the household consumption is low \cite{pedersen2015disc}.
An approach to prevent grid instability due to dramatic voltage increases is to control the power output of DERs, e.g., via active power curtailment or reactive power adjustment \cite{tonkoski2011coordinated}.
In this respect, \cite{pedersen2016fairness} proposes a control strategy based on the principle of proportional fairness, where all DERs equally contribute to voltage regulation all the time; the strategy is executed by the remote central authority such as the distribution system operator (DSO).
However, enforcing that all DERs participate in voltage control and curtail their output power all the time is characterized with a control complexity that increases with the number of DERs and a reduced possibility for the owners to operate an economic strategy.
Moreover, existence of the centralized authority involves the issue of Single Point of Failure (SPoF).

In this paper, we propose a novel control scheme based on the proportional fairness in which (i) only a subset of DERs act as voltage regulators and curtail their individual power outputs over control periods, and (ii) ensures that, in the long term, DERs participation in voltage regulation is balanced.
To give the DERs the incentive to fairly participate in voltage regulation, we introduce a principle based on exchange of \emph{credits}.
Specifically, in order to join the regulating subset, DER asks for a credit, which will be paid by the DERs that are not in the regulating subset and therefore operate at their full capacity.
In turn, the decrease of credit status of the DERs that have not participated in voltage regulation ultimately forces them to participate in the voltage regulation in future.

In order to avoid existence of a central authority and, thus, a SPoF, the proposed protocol runs in a distributed manner.
The credit statuses of all DERs are tracked by the use of a blockchain protocol, initially introduced with Bitcoin cryptocurrency \cite{nakamoto2008bitcoin}.
Its major advantage is the capability to implement a distributed database that serves as record of the system's state and of its history, trusted by all agents, in this case DERs.
All agents store identical copies of the database.
The database is hard to tamper with, since an agent can add new record to it \emph{only} if a proof-of-work (POW) is obtained, where POW is the solution of a computational puzzle that requires an investment of electrical energy to run the computation.
In particular, the blockchain is used to memorize (i) the state of \emph{smart contracts} \cite{wood2014ethereum}, which are computer programs that can receive, store and pay credit, i.e., cryptocurrency, and (ii) the credit history of agents.
In the proposed framework, a smart contract acts as a trustworthy \emph{distrubuted} control authority, realized via a custom-designed blockchain mechanism operated by all DERs.
Specifically, DERs that are installed on the same distribution feeder stipulate a smart contract among them, determining which units will act as voltage regulator over control periods, based on their available credit statuses and the economic strategy that they individually adopt.
In the long term, this ensures a fair rotation in the participation of the DERs to the MG regulation.

The rest of the paper is organized as follows.
Section~\ref{sec:problem_formulation} introduces the system model and the proportional-fairness control strategy assuming a centralized setup.
Section~\ref{sec:blockchain} introduces the main concepts of a blockchain protocol.
Section~\ref{sec:solution} presents the distributed, blockchain-based architecture fostering the proportional-fairness control.
Section~\ref{sec:case_study} contains a case study based on a simulation of a power system and an instance of blockchain protocol, verifying the proposed framework.
Section~\ref{sec:conclusion} concludes this paper.

\section{System Model}
\label{sec:problem_formulation}

\begin{figure}[!tb]
\centering
  \includegraphics[width=\columnwidth]{Grid.pdf}
    \caption{The system model.}
    \label{fig:grid}
\end{figure}

We consider a LV distribution grid (LVDG) composed of $N_{\text{MG}}$ alternate-current MGs.
A MG~$f$ hosts $U_f$ DERs, $U_f \geq 0$, which are PV generators that supply residential loads, see Fig.~\ref{fig:grid}.
The total number of DERs in the LVDG is $U_{\text{total}} = \sum_{f=1}^{N_{\text{MG}}} U_f$.
All MGs jointly strive to maintain the LVDG grid voltage amplitude within acceptable limits \cite{rocabert2012control}.
To do so, in each MG there is a dedicated \emph{voltage regulator} elected from the local DERs.
In the rest of this section, we first describe the voltage regulation mechanism.
Afterwards, we introduce the regulator election strategy that each MG employs.

\subsection{Voltage regulation}

Assume MG~$f$ with $U_f$ DERs indexed in the set $\mathcal{U} = \{1,2,...,U_f\}$.
Each DER is connected to the MG via a power electronic converter (PEC) that controls its output and that supports dual mode capability \cite{ref12}, i.e., a PEC can operate in current source converter (CSC) or voltage source converter (VSC) mode.
In CSC mode, DER~$u$ is operated at capacity, outputting all available power $g_u$ using maximum power point tracking algorithm, and is \emph{not} capable of regulating the voltage \cite{rocabert2012control}.
In VSC mode, DER~$u$ acts as the voltage regulator at the expense of the reduced active output power $p_u$, $p_u \leq g_u$.
The voltage is regulated via the active output power using the following droop control law \cite{guerrero2011hierarchical}:
\begin{equation}\label{droop}
 v_u = v_{ref} - \gamma(g_u - p_{u}),
\end{equation}
where $v_u$ and $v_{ref}$ are the voltage at the output of the DER and the reference voltage of the MG, respectively, while $\gamma$ is the droop parameter, chosen such that (i) $v_u$ is maintained within tolerable limits $v_{\min}$ and $v_{\max}$, and (ii) all VSCs in the LVDG achieve proportional power sharing.
The output reactive power $q_u$ is determined via the active output power, subject to a constraint on the apparent power, as follows:
\begin{equation}
q_u = \sqrt{s_{\max}^2 - p_u^2},
\end{equation}
where $s_{\max}^2$ is the maximum tolerable apparent power.\footnote{We note that more sophisticated control schemes, based on both active and reactive power adjustments, can be adopted for the voltage regulation. However, they are beyond the scope of the paper.}
The droop control law \eqref{droop} clearly shows that, in VSC mode, the active power of DER $u$ is below capacity, leading to revenue loss of the DER owner.
Nevertheless, the presence of VSC units is an imperative for voltage regulation of the MG.

\subsection{VSC election per MG based on proportional fairness}
\label{sec:VSC}

\begin{figure}[!tb]
\centering
  \includegraphics[width=0.85\columnwidth]{Architecture.pdf}
    \caption{Message exchanges between the DERs and the control authority.}
    \label{fig:architecture}
\end{figure}

We first formulate the centralized version of the VSC election strategy, employed in each MG, and enabled by an external control authority, e.g., the DSO, see Fig.~\ref{fig:architecture}.
The strategy runs periodically every $T^{tc}$ seconds, where the interval between two consecutive VSC assignments is referred to as \emph{control period}, and is sufficiently long to allow reliable exchange of messages among DERs and the authority.
Let $\mu_u (k)$ denote the operating mode of DER $u$ in arbitrary control period $k$.
Hence, $\mu_u (k)$ is a binary variable:
\begin{equation}
\mu_{u}(k) =
\begin{cases}
0 \quad \text{if DER }u \text{ operates as CSC in period }k, \\
1 \quad \text{if DER }u \text{ operates as VSC in period }k.
\end{cases}
\end{equation}

Denote by $\boldsymbol{\mu}_u$ the sequence of operating modes of DER $u$ in all periods up to interval $K$, i.e., $\boldsymbol{\mu}_{u} = [ \mu_{u}(0), \hdots, \mu_{u} (K-1)]$.
Stacking $\boldsymbol{\mu}_u,~\forall u\in\mathcal{U}$, vertically, we form the $U_f\times K$ matrix of control mode histories of all DERs in the MG up to period $K$, denoted by $\mathbf{M}$, where $[\mathbf{M}]_{u,k} = \mu_{u}(k)$.
The $k$-th column of $\mathbf{M}$ represents the operating modes of all DERs in the MG in control period $k$, and is denoted by {$\boldsymbol{\mu}^{(k)}$}.
The objective of the VSC election strategy is to ensure fairness among DERs in the MG, i.e., all DERs should equally participate in voltage control over time.
This can be expressed as follows:
\begin{equation}\label{eq:objective}
\mathbf{M} \, \mathbf{1}_{K} = \frac{K}{U_f} \mathbf{1}_{U_f},
\end{equation}
where $\mathbf{1}_{U_f}$ is the all-ones vector of length $U_f$.
In addition, the strategy should also ensure that only one DER per MG acts as VSC in each control period, i.e.:
\begin{equation}
\mathbf{1}_{U_f}^{\mathsf{T}} \, \boldsymbol{\mu}^{(k)} = 1,
\end{equation}
with $(\cdot)^{\mathsf{T}}$ denoting the transpose operator.

\begin{figure*}[!tb]
\centering
\subfloat[]{\includegraphics[width=0.45\columnwidth]{blockchain_a.pdf}}
\hfill
\subfloat[]{\includegraphics[width=0.45\columnwidth]{blockchain_b.pdf}}
\hfill
\subfloat[]{\includegraphics[width=0.45\columnwidth]{blockchain_c.pdf}}
\hfill
\subfloat[]{\includegraphics[width=0.45\columnwidth]{blockchain_d.pdf}}
\caption{Different phases of blockchain protocol: (a) contract updates are propagated in the network, (b) contract updates are accumulated in the miners' buffers, (c) a new block (red packet) that includes the updates is generated and propagated and (d) the new block is accepted by the entire network.}
\label{fig:blockchain}
\end{figure*}

DERs are given incentive to participate in voltage regulation through acquisition of \emph{credit} when they operate in VSC mode.
Denote by $c_u(k)$ the credit status of DER $u$ in the control period $k$ and let $\mathbf{c}^{(k)} = [c_1(k),\hdots,c_{U_f}(k)]$.
In the proposed scheme, the total available credit is constant, i.e., $\sum_{u=1}^{U_f} c_u (k) = C$, $\forall k$, and the credit is only redistributed among DERs, ultimately forcing them to act as VSCs.

The redistribution of the credit is performed in the following way.
In period $k$, DER $u$ sends to the control authority the credit demand $w_u(k)$ asked for performing the role of VSC for the MG in the next period $k+1$.
The credit demand is chosen in the interval $[0,c_u(k)]$, according to the individual strategy adopted by DER $u$.
For the sake of simplicity, in the rest of the paper we assume that DER $u \in \mathcal{U} $ chooses $w_u(k)$, $\forall k$, randomly using uniform distribution:
\begin{equation}\label{eq:constrain}
w_u(k) \sim \text{unif} \left( 0,c_u(k) \right).
\end{equation}
The control authority stores the information sent by all DERs in the MG in the vector $\mathbf{w}^{(k)} = [w_1(k),\hdots,w_{U_f}(k)]$, and chooses the DER with the \emph{lowest} credit demand to operate as VSC in the next control period:
\begin{equation}\label{eq:decision}
\hat{u} = \text{argmin}_{u} \mathbf{w}^{(k)}.
\end{equation}
Then, the control authority sends the messages about (i) the control modes of all the DERs in the MG in the next control period $\boldsymbol{\mu}^{(k+1)} = \mathbf{e}_{\hat{u}}$, where $\mathbf{e}_{\hat{u}}$ is a vector with $1$ at position $\hat{u}$ and $0$ elsewhere, and (ii) the update of the total credit
\begin{equation}\label{eq:credit}
\mathbf{c}^{(k+1)} = \mathbf{c}^{(k)} - \mathbf{w}^{(k)} + \left( \mathbf{1}_{U_f}^{\mathsf{T}}\mathbf{w}^{(k)} \right) \mathbf{e}_{\hat{u}},
\end{equation}
see Fig.~\ref{fig:architecture}.
A careful inspection of \eqref{eq:decision} shows that the total credit is redistributed by (i) taking from the DERs their respective credit demands and (ii) giving the total demanded credit to the DER $\hat{u}$ that had the lowest demand and that will take the VSC role in the next period.

The rule for choosing the credit demand \eqref{eq:constrain} and the VSC election rule \eqref{eq:decision} show that DERs with lower credit status have higher chances of operating as VSC.
On the other hand, low credit status implies that the DER has previously infrequently operated as VSC.
In this way, the proportional fairness is promoted among DERs in the MG.
We also note that the results provided in Section~\ref{sec:case_study} verify that the objective \eqref{eq:objective} becomes satisfied as the number of control period increases.

To run the VSC election strategy, the LVDG requires a communication network to interconnect the DERs with the central authority to support the message exchange depicted in Fig.~\ref{fig:architecture}.
This can be implemented using wireless (e.g., cellular) network, or wired network (e.g., power line communications).

Finally, the election strategy \eqref{eq:decision} and the credit update rule \eqref{eq:credit} require presence of the central authority's database that records the current credit status $\mathbf{c}^{(k)}$ and that is trusted by all agents.
This need for the establishment of a trustful relation among agents prevents the implementation of simple decentralized control systems, such as token rings, in which DERs hold the control in turns.
Motivated by this insight, we develop a decentralized control solution based on blockchain protocol, which establishes a trustful distributed record both of the credit status of all DERs and of the control history.

\section{Blockchain Protocol}\label{sec:blockchain}

In this section, we describe a version of the blockchain protocol that realizes only the functionalities required to support the proposed control strategy.
An introduction to the general variant of the blockchain can be found in \cite{narayanan2016bitcoin}.

A blockchain is a distributed database consisting of identical copies that are stored in the memory of each agent.
It is organized as a concatenated list of blocks that can be expanded by any agent with new blocks.
Each block stores a set of smart contracts updates.
A smart contract is a computer program that can be executed by an agent that has the blockchain software.
As the agent executes the program locally, whenever it modifies the contract internal state, e.g., by exchanging credit with it, the rest of the agents should be informed in order to run the new version of the contract.
The new state is communicated through a smart contract update.
To avoid proliferation of different states of the contract, the blockchain in parallel executes the update verification process via \emph{block generation}, ensuring that only verified updates are included in the blockchain.
We proceed by providing the details.

Fig.~\ref{fig:blockchain} illustrates the blockchain operation via an example of a peer-to-peer network of interconnected agents.
Every agent is provided with a local copy of the blockchain, and a buffer, named ``mempool''.
When smart contract updates are produced, they are sent to the neighbors, Fig.~\ref{fig:blockchain}(a).
The updates are temporary stored in mempools, Fig.~\ref{fig:blockchain}(b), being not considered valid yet.
In parallel, agents are also generating blocks, i.e., working to solve the computational puzzle (by the blockchain protocol) and obtain POW.
When an agent obtains POW and generates a new block, it fills it with the smart contract updates present in its mempool and transmits the new block to its peers, see Fig.~\ref{fig:blockchain}(c).
Upon the reception of the block, a neighbouring agent verifies that it contains a valid POW, by checking the provided solution of the puzzle.
If the verification succeeds, the agent adds the block to its blockchain, Fig.~\ref{fig:blockchain}(d), and propagates it further to its neighbors.
The verification and propagation of successfully verified block continues until all agents in the network are reached.
Finally, when all agents have received and verified the block, they have the same updated version of the blockchain, see Fig.~\ref{fig:blockchain}(d), and thus, their copies of the smart contract have the same internal state.
The agents also remove from their mempools the smart contract updates included in the received and verified blocks.

The smart contract can be abstracted as a \emph{virtual agent} that interacts with the actual agents according to the logic defined in its program, and in this way regulating credit redistribution among the actual agents through the contract updates.
In the context of the proposed framework, the smart contract updates are produced by the MG control application, while the block creation process is intrinsic to the blockchain and in charge of keeping it consistent.
These two process run independently, where the latter ensures that the smart contract updates are eventually stored in the blockchain.

\subsection{Blockchain consistency}

As depicted in Fig.~\ref{fig:blockchain}(c)--(d), the blockchain consistency is guaranteed through propagation of newly generated blocks to all other agents.
In order to avoid the generation of uncontrolled amounts of blocks, a block generation requires an investment of resources.
In the seminal paper \cite{nakamoto2008bitcoin}, the investment is the consumption of electrical power required to solve a computational puzzle, known as POW.
This process of obtaining POW is named \emph{mining}; the agent that first solves the POW decides the content of the next block.
The probability $p_b$ to generate a new block before the other agents depends on the computational resources allocated to solve the puzzle.
The difficulty of the puzzle is tuned to keep the block generation rate constant over time, see \cite{nakamoto2008bitcoin} for details.

It may happen that two or more new valid blocks are created concurrently by different agents, propagating in different subgraphs of the network.
In this case, the network is split over different, but valid versions of the blockchain.
The contention rule adopted by Bitcoin is ``the longest chain wins", i.e., the split is solved when some ``newer'' valid block is generated, received and accepted by all agents, updating the blockchain and making it consistent again \cite{narayanan2016bitcoin}.

\subsection{The cost of mining}\label{sec:fees}

In standard blockchain realizations, the resource investment in mining operation is compensated by attributing some credit, i.e., cryptocurrency, to the miners, either by (i) increasing the credit of the miner that generates the block, incrementing the total amount of credit in the system, or (ii) letting the miner demand a credit fee for each smart contract update that it includes in a block.
This stimulates miners to consume electrical power to obtain POW, and thus reduces the risk that a malicious miner may impose his version of the blockchain.

In this work, the miners are the DERs in the MG, i.e., the blockchain is \emph{private}, but they are not rewarded with credit for mining.
Nevertheless, a DER is stimulated to mine, in order to ensure that the blockchain is consistent with its view of the credit status and control history.
Also, not providing credit for mining eliminates the possibility of DERs being more motivated in mining than in voltage regulation.

\subsection{Peer-to-peer network and protocol messages}

The blockchain is based on peer-to-peer networking, where each agent connects to a set of randomly selected neighbors.\footnote{It is required that the communication graph formed in this way is connected, but the related details are beyond the scope of the paper.}
The communication protocol adopts TCP connections to exchange two types of information, as shown in Fig.~\ref{fig:blockchain}.
\begin{enumerate}
\item The smart contract updates, Fig.~\ref{fig:blockchain}(a).
\item The blocks, Fig.~\ref{fig:blockchain}(c).
\end{enumerate}

\subsection{Security issues of blockchain protocol}\label{sec:sec_issue}

The blockchain protocol is founded on the assumption that the resources required to generate blocks are well distributed among agents, making it hard for a single agent to consecutively generate blocks and and impose its view of the blockchain that may potentially include false data \cite{narayanan2016bitcoin}.
This assumption can be adopted in the scenario considered in the paper, as it is expected that microcontrollers of the DERs have similar hardware characteristics.

Security threats to blockchain may also come from peer-to-peer networking.
A prominent example is the eclipse attack \cite{heilman2015eclipse}, in which all neighbors of an agent are under the control of a malicious agent.
In this case, the copy of the blockchain of the attacked agent may be compromised.
To avoid such scenario, the communication peers are selected randomly.

\section{The Proposed Distributed Control Framework}\label{sec:solution}

The proposed solution is enabled by a blockchain protocol (i.e., software) implemented by the agents, i.e., DERs of the distribution grid.
The mining process is done by agents themselves, where the agents do not cooperate and the POW is of low difficulty determined by their limited computational capabilities.
The agents have access to a peer-to-peer network, where the access is granted only to legitimate agents.
We assume that the rate at which POWs are obtained and new blocks propagated through the network is sufficiently high to prevent overflow of the mempools.
Finally, the message propagation delay is assumed negligible compared to the control period duration $T^{tc}$.

A smart contract is deployed for each grid feeder, playing the role of the central authority (i.e., DSO), resulting in a unique blockchain that stores $N_{MG}$ contracts.
The relationship of DERs in a feeder and their smart contract is depicted in Fig.~\ref{fig:relationship}.
During a control period, each DERs chooses its credit demand for the next period via \eqref{eq:constrain}, and updates its local copy of the smart contract by \emph{sending}, i.e., transferring, the demanded amount to it, see Fig.~\ref{fig:relationship}(a).
These updates are propagated to peers, Fig.~\ref{fig:blockchain}(a)--(b), and the block generation process, Fig.~\ref{fig:blockchain}(c), ensures that all the copies of the smart contract have the consistent knowledge of them, Fig.~\ref{fig:blockchain}(d).
The credit sending is disabled during the final part of the period via the contract locking, to ensure the consistency of local copies at the control actuation instant, i.e., at the beginning of the new period.
At this point, based on its internal state, the smart contract (i.e., each its copy) elects the (same) VSC for the next control period using \eqref{eq:decision}, and DERs are locally notified (e.g., via reading the state of the smart contract) about their operating mode for the next control period.
In the next round, the elected VSC updates its local smart contract to receive the total demanded credit, see Fig.~\ref{fig:relationship}(b).
This triggers a new round of the update propagation, Fig.~\ref{fig:blockchain}(a)--(b), which is eventually stored in the blockchain after a block embedding it becomes generated and propagated through the network, Fig.~\ref{fig:blockchain}(c)--(d).

\begin{figure}[!tb]

\centering
\subfloat[Credit sending.]{\includegraphics[width=0.39\columnwidth]{Sc_a_new.pdf}}
\hspace{2pt}
\subfloat[Credit receiving.]{\includegraphics[width=0.39\columnwidth]{Sc_b_new.pdf}}
    \caption{Relationship among DERs in one feeder and their smart contract.}
    \label{fig:relationship}
\end{figure}

For the sake of completeness, in Fig.~\ref{fig:comparison}(a) we expose the operating sequence of the framework related to a single control period, i.e., period $k$, assuming that the contract updates related to period $k$ start in period $k-1$:\footnote{In general, the framework can be operated such that the contract updates for period $k$ are started in a period $k_1$, where $k_1 \leq k - 1$, allowing to solve the eventual blockchain inconsistencies due to propagation and mining delays. The related analysis is beyond the paper scope.}
\begin{enumerate}
\item \emph{Credit sending:} During period $k-1$, each DER transfers to the smart contract the credit demanded to operate as VSC in the next period (represented by green arrows). These updates are propagated through the network and stored in the mempools, and gradually included in the blockchain when new blocks are generated.
\item \emph{Contract lock and VSC election:}
At a predefined instant before the end of period $k-1$, all DERs modify the state of the contract to lock it (purple arrow).\footnote{Note that the contract is effectively locked only by the first contract update that is included in the blockchain, which invalidates the consecutive locks.} The VSC for control period $k$ is elected via \eqref{eq:decision}, uniquely over all copies of the smart contract. All DERs set their control mode accordingly.
\item \emph{Credit receiving:} The VSC DER withdraws the credit obtained for the control period $k$ from the smart contract (represented by the red arrow). To do this, it modifies the state of the contract, communicates the state update to the other agents, and waits for it to be included in a newly mined block. The credit stored by the contract can only be withdrawn by the DER operating as VSC.\footnote{All contract updates are certified with public-key cryptography, cf. \cite{nakamoto2008bitcoin}.}
\end{enumerate}
The figure also depicts the block generation process (represented by blue crosses) that is decoupled from the process of contract updates.
It may happen that some newly generated blocks do not contain any updates and such blocks only verify the consistency of the current state of the blockchain.

In the rest of this section, we outline several important aspects of the framework.

\subsection{Plug-and-play feature}

The blockchain-enabled solution provides a smooth plug-and-play since the joining DER just needs to start interacting with the contract.
Observe that it is likely that the joining DER will be chosen as VSC in the next control periods, as its credit status is zero.

\begin{figure}[!tb]

\centering
\subfloat[Blockchain-based scheme: the messages are exchanged among DERs.]{\includegraphics[width=\columnwidth]{TimeComparison.pdf}}
\vspace{6pt}
\subfloat[Centralized scheme: The messages are sent from DERs to the central authority (uplink) and from the central authority to DERs (downlink).]{\includegraphics[width=\columnwidth]{TimeComparisonB.pdf}}

\caption{Sequence of the communication exchanges (a) in the blockchain-based and (b) in the centralized scheme.}
    \label{fig:comparison}
\end{figure}

\subsection{Control availability and trustworthiness}

The decentralized solution does not suffer from the SPoF, providing an increased control availability with respect to the centralized architecture.
It also avoids reliance on data received by an external authority, which can be tampered without being detected by the MG agents.
On the other hand, the major weakness of the blockchain-based architecture is the modification of the database operated by a subset of agents that are capable to generate new blocks faster, imposing their version of the control history, as discussed in Section~\ref{sec:sec_issue}.

\subsection{Communication cost}

Fig.~\ref{fig:comparison} compares the communication exchanges in the blockchain-based scheme, Fig.~\ref{fig:comparison}(a), with the exchanges in the centralized one, Fig.~\ref{fig:comparison}(b).
We proceed by evaluating and comparing the communication costs of both approaches, where the communication cost is expressed via the average amount of data exchanged per agent during a control period.

In the blockchain-based scheme, data is generated by the processes of smart contract updates and blocks generation.
The number of blocks generated during a control period, denoted by $N_b$, is determined by the protocol.
The communication cost for agent $u$ with $N$ peers is:
\begin{equation}\label{eq:bc_cost}
J^{bc} = N L_{u} + J^{rc} + p_b N_b N L_b + J^{rb},
\end{equation}
i.e., it comprises the costs of propagating its own transaction, expressed through the message length $L_u$, the relaying of other's transactions $J^{rc}$, the transmission of its own blocks and the relaying of other's blocks $J^{rb}$.
For the sake of comparison, we provide a lower bound on $J^{bc}$ for the simplified case where a DER has just a single peer and does not relay data\footnote{We note that the scenario with a single neighbor should be avoided, as in this case a malicious neighbor may corrupt or hide the information \cite{heilman2015eclipse}.}, assuming that the computational power is equally distributed among DERs, i.e., $p_b = 1 / U_{\text{total}}$:
\begin{equation}
J^{bc}_\text{LB} = L_u + \frac{N_b L_b}{U_{\text{total}}}.
\end{equation}

In the centralized architecture, we denote the length of messages $w_u$, $c_u$, $\mu_u$ in bits as $L_{w}$, $L_c$, $L_{\mu}$.
In this case, the communication cost per DER is equal to $J^{c} = L_{w} + L_{c} + L_{\mu}$, i.e., it is a constant.  We compare the communication costs in Fig.~\ref{fig:commcost}, assuming that $L_w$, $L_{\mu}$, $L_c$ are 64 bits long, $L_u$ is 800 bits and $L_b$ is 8000 bits.
The block period is set to $10 \, \text{s}$, which together with $T^{tc} = 15 \, \, \text{minute}$  provides $N_b = 90$ blocks for control period.
The communication cost in the blockchain-based scheme is slightly decreasing with the number of DERs, i.e., $U_{\text{total}}$, as this reduces the number of blocks that they individually generate in a control period.
However, the centralized solution is clearly less demanding due to its simpler communication architecture.

\begin{figure}[!tb]
\centering
  \includegraphics[width=0.92\columnwidth]{comm_cost_3.eps}
    \caption{Comparison of communication costs.}
    \label{fig:commcost}
\end{figure}

\begin{figure}[!tb]
\centering

\subfloat[Without control.]{\includegraphics[width=0.88\columnwidth]{without_ctrl_2.eps}}

\subfloat[With the control.]{\includegraphics[width=0.88\columnwidth]{voltages_controlled.eps}}
\caption{The voltage measured on the LV feeders on the dataset corresponding to 9th of June, indicated in the Per-Unit (PU) base.}\label{fig:voltage_day}
\end{figure}

\section{Case Study}\label{sec:case_study}

Inspired by the MG LV scenario in \cite{pedersen2015disc}, we adopt the power system composed by LV and MV MGs depicted in Fig.~\ref{fig:grid} as a case study.
The LV MG is connected to a medium voltage (MV) microgrid in which a $6 \, \text{MW}$ solar PV power plant is installed.
The power exchange between the LV and MV MGs takes place via a on-load tap changing transformer (OLTC), that constitutes the point of common coupling (PCC).
The LV MG is composed by $N_{MG}=7$ feeders, each supporting the consumption of 10 households.
On each feeder, except feeder $f_1$, there are installed 4 PV systems (i.e., DERs) with the rated power of $4 \, \text{kW}$, resulting with a total of $U_{\text{total}} =24$ PVs.
For the modeling of PVs, OLTC, households consumption, and the other grid components, we adopt Disc framework \cite{pedersen2015disc}.

We simulated the system in the Disc framework both for the case without control and the case in which the proposed control scheme is applied.
When no control is adopted for the PVs, in the afternoon hours we observe an overvoltage on the feeders, which increases with their distance from the transformer, see Fig.~\ref{fig:voltage_day}(a).
Fig.~\ref{fig:voltage_day}(b) shows the proposed control strategy\footnote{We used the optimized value of the droop parameter $\gamma = 0.005$, obtained via simulations.} provides a reduction of the over-voltages with respect to the scenario without control.
One can also observe that the slope of the voltage profile in afternoon/morning hours is reduced, which is another benefit of the control strategy.
Specifically, smoothing the voltage profile curve in systems dominated by PV power gives more time and flexibility to the bulk generation, which is characterized with high inertia and slow transient ramp-up/ramp-down response, to respond to the the power supply variations.
The proposed control strategy was also simulated over a period of one month and the reduction of over voltages was also verified, see Fig.~\ref{fig:month}.
Observe that the under-voltages are not reduced, as their control is not included in the proposed strategy.
Nevertheless, we note that a similar credit system can be employed for the load prioritization during low production periods.

\begin{figure}[!tb]
\centering
  \includegraphics[width=\columnwidth]{boxplotmonth_2.eps}
    \caption{The voltage measured on the LV feeders over the month of June of Disc simulator (i) without control, depicted with purple boxes, and (ii) with proposed control, blue boxes. The plot shows minimum, quartile and maximum values.}
    \label{fig:month}
\end{figure}

The verification of the proportional fairness objective \eqref{eq:objective} in a centralized setting was performed via MATLAB simulations, where the initial credit was randomly distributed among DERs, i.e., the credit status vector $\mathbf{c}$ was randomly initialized, and the control period duration was set $T^{tc}=15$ minutes.
We performed 1000 simulation runs, corresponding to 250 hours of LVDG operation, and obtained that the DERs spend the equal fraction of time operating as VSCs (the detailed presentation of these results is omitted due to space constraints).

Finally, we turn to the blockchain-related aspects of the proposed framework.
The blockchain software installed in the DERs controller supported a private Ethereum blockchain \cite{wood2014ethereum}, which provides the possibility of writing complex smart contracts, and is simulated using EthereumJS testrpc \cite{testrpc}.
We deployed $N_{MG}$ contracts on the blockchain, where DERs interacted with the one corresponding to their feeder, and the initial credit was randomly distributed among DERs.
The scripts that interface DERs with the blockchain implemented the functionalities described in Section~\ref{sec:solution}.
We monitored the output of the scripts and observed that the contract was effectively reproducing the fairness objective, see Fig.~\ref{fig:testrpc}.
Clearly, after a transient period caused by the initial credit distribution, DERs operate as VSCs for equal fractions of time.

\section{Conclusions}\label{sec:conclusion}

The current research efforts in MG control are oriented towards distributed schemes, requiring development of novel protocols to enforce the security and the information trustworthiness among control agents.
The blockchain protocol has interesting properties that can be used to this end, resulting in a novel design of multi-agent control systems.
In this paper, we developed proportional fairness MG control and established a comparison between the standard centralized architecture and blockchain-based one, verifying that the blokchain-based solution can reproduce the control objectives of the centralized architecture.
We note that further investigation should be conducted with respect to more complex control schemes.

We also outline two potential limits of the private blockchain architecture in the context of MG control: the mining cost and the communication cost.
Specifically, alternatives to the energy inefficient POW have to be found in order to enable private blockchains for systems with limited hardware capabilities, such as MG components.
Secondly, the communication cost of the blockchain protocol is significantly higher than the cost of the centralized one.
The design of blockchain protocol tailored for MG applications is part of our ongoing research.

\begin{figure}[!tb]
\centering
  \includegraphics[width=\columnwidth]{sc_output.eps}
    \caption{Evolution of the fraction of time spent by each DER as VSC in a feeder with 4 DERs.}
    \label{fig:testrpc}
\end{figure}

\section*{Acknowledgment}

The work presented in this paper was supported in part by the EU, under grant agreement no. 607774 ``ADVANTAGE".

\nocite{*}
\bibliographystyle{IEEEtran}


\section{\label{sec:helicity_relaxation} derivation of the helicity relaxation rate}

In this appendix we evaluate the helicity relaxation rate due to elastic scattering of electrons from impurities.
We are interested in the  regime where the energy of the electrons significantly exceeds the band gap, $\varepsilon \gg E_g$.
 In this case the helicity relaxation rate is parametrically smaller that the momentum relaxation rate and may be evaluated under the assumption of full momentum relaxation of the electron distribution with a given helicity.

The helicity relaxation rate due to elastic scattering of electrons from impurities is independent of the sign of the energy. Therefore, below we assume the energy to be positive. The electron states with momentum $\mathbf{p}$, positive energy $\epsilon_p= \sqrt{E_g^2 + u^2 p^2}$, and given helicity, $\alpha = \pm 1$ are described by the following wavefunctions
\begin{widetext}
\begin{equation}\label{eq:psi_+}
\Psi_+(\mathbf{p}) =
\left(
\begin{array}{c}
\frac{\epsilon_p + u p }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}}\,  \cos (\theta/2)\\
\frac{\epsilon_p + u p }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}}\, \sin (\theta/2) e^{i\phi}\\
\frac{E_g }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}} \, \cos (\theta/2)\\
\frac{E_g }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}} \,  \sin (\theta/2)  e^{i\phi}
\end{array}
\right) ,
\quad
\Psi_-(\mathbf{p}) =
\left(
\begin{array}{c}
- \frac{E_g }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}} \, \sin (\theta/2)\\
\frac{E_g }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}} \,  \cos (\theta/2)  e^{i\phi}\\
- \frac{\epsilon_p + u p }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}} \,  \sin (\theta/2)\\
\frac{\epsilon_p + u p }{\sqrt{2 \epsilon_p (\epsilon_p + u p )}} \, \cos (\theta/2) e^{i\phi}
\end{array}
\right).
\end{equation}
\end{widetext}
Here we introduced the spherical angles $\theta$ and $\phi$ to define the direction of the electron momentum $\mathbf{p}$.

In the Born approximation the collision integral due to impurity scattering may be written in the form
\begin{eqnarray}
\label{eq:collision_integral}
I_\alpha\{n_\alpha (\mathbf{p}) \} & = &  \int d \mathbf{p}'  w (\mathbf{p}; \mathbf{p}') \left[  \frac{(\epsilon_p + u p)^2}{(2 \epsilon_p )^2}  \left( 1 + \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right) n_\alpha (\mathbf{p}') \right. \nonumber \\
&&\left. + \frac{E_g^2}{(2 \epsilon_p)^2}  \left( 1 - \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right) n_{- \alpha} (\mathbf{p}')  \right]  - \frac{n_\alpha (\mathbf{p})}{\tau}.
\end{eqnarray}
Here $n_{\pm \alpha} (\mathbf{p}') $ is the distribution function  of electrons with momentum $\mathbf{p}'$ and helicity $\pm \alpha $, $w (\mathbf{p}; \mathbf{p}') \propto \delta (p - p') \left|
\int d \mathbf{r} V(\mathbf{r}) e^{i (\mathbf{p} - \mathbf{p}')\cdot \mathbf{r}}
\right|^2 $,  and the expression in the square brackets describes the square of the overlap of spinor amplitudes \eqref{eq:psi_+} in states $\mathbf{p}$ and $\mathbf{p}'$  with the same (first term) and opposite (second term) helicities. Finally,
 the ``out" relaxation rate is given by
\begin{eqnarray}
\label{eq:tau}
\frac{1}{\tau} & = &  \int d \mathbf{p}'  w (\mathbf{p}; \mathbf{p}') \left[ \frac{(\epsilon_p + u p)^2}{(2 \epsilon_p )^2} \left( 1 + \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right) \right. \nonumber \\
&&\left.    +\frac{E_g^2}{(2 \epsilon_p)^2}  \left( 1 - \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right)   \right].
\end{eqnarray}

In the approximation of full momentum relaxation the distribution function depends only the the energy $\varepsilon$ and helicity $\alpha$ of the electrons, and the collision integral simplifies to
\begin{equation}
\label{eq:collision_integral_helicity}
I_\alpha \{ n(\varepsilon)\} = - \frac{n_\alpha (\varepsilon)  - n_{-\alpha} (\varepsilon)}{\tau_h (\varepsilon)},
\end{equation}
where $\tau_h$ is the helicity relaxation time given by
\begin{equation}
\label{eq:tau_h}
\frac{1}{\tau_h (\varepsilon)}=   \frac{E_g^2}{4 \varepsilon^2} \,  \int d \mathbf{p}'  w (\mathbf{p}; \mathbf{p}')   \left( 1 - \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right)  .
\end{equation}

Note that in the limit $E_g/\epsilon_p \to 0$ the transport scattering rate is given by
\begin{equation}
\label{eq:tau_tr}
\frac{1}{\tau_{tr} (\varepsilon)} =   \int d \mathbf{p}'  w (\mathbf{p}; \mathbf{p}') \left( 1 + \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right)  \left( 1 - \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right).
\end{equation}

Therefore the helicity relaxation rate may be expressed in terms of the transport relaxation rate in the form of Eq.~\eqref{timehierarchi}, where $\xi$ is a factor of order unity given by
\begin{equation}
\label{eq:Upsilon}
\xi = \frac{   \int d \mathbf{p}'  w (\mathbf{p}; \mathbf{p}') \left( 1 + \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right)  \left( 1 - \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right)}{\int d \mathbf{p}'  w (\mathbf{p}; \mathbf{p}')   \left( 1 - \frac{\mathbf{p} \cdot \mathbf{p}'}{p^2}\right) }.
\end{equation}
In the limiting case of small angle scattering $\xi =2$, while in for  point-like impurities $\xi=2/3$.

\end{document}


\section{\label{sec:intro}Introduction}
Nano systems are associated with unique physico-chemical properties because of their finite size, shape, quantum confinement as well as surface effects, and have potential applications in diverse fields from catalysis to medical diagnosis.\cite{alloy_rev1,alloy_rev2,book,another1,another2,nanodiag} During the last few decades, bimetallic nano-clusters have received special interest in the research of nano science and nano technology because of the additional degrees of freedom achievable by changing the chemical composition and ordering of its constituent atoms. Recently, several bimetallic multifunctional nano systems consisting of magnetic transition metal (M) and nonmagnetic noble metal (NM) atoms such as Fe-Pt,\cite{fept} Fe-Pd,\cite{fepd} Fe-Au,\cite{feau1,feau2} Fe-Ag,\cite{feag} Co-Pt,\cite{copt,copt2} Co-Pd,\cite{copd} Co-Au,\cite{coau} Ni-Pt,\cite{nipt} Ni-Pd,\cite{nipd} Ni-Au\cite{niau}, have been studied both experimentally as well as theoretically. Besides their catalytic properties, the M-NM bimetallic nano-systems have also great importance in the fields of fuel cells, magnetic storage as well as in spintronics applications.\cite{alloy_rev1,book,nm-fm} These M-NM nano alloys have also been  shown to possess enhanced  magneto-crystalline anisotropy constant and thermal stability of their magnetization compared to those of an equivalent pure cluster of the M elements.\cite{mae}

 In the present study, we will focus on Ni-Ag bimetallic nano clusters, which have attracted considerable research interest in recent time because of their emerging functionalities. Among the two constituents, the Ni atoms are characterized by the localized 3$d$-electrons, while the behavior of Ag atoms having a closed 4$d$-shell, are primarily governed by the {\sl itinerant} 5$s$ electron. Note that silver is of particular interest for its unique optical and electrical properties due to prominent surface plasmonic effects in the visible and ultraviolet light, which induce a  number of potential applications in sensing,\cite{sensors} surface enhanced Raman spectroscopy,\cite{serp} biomedical field\cite{bio} and so on\cite{else}. The magnetic constituent, nickel, on the other hand, has been widely used in different spintronics devices\cite{applications} and catalysis\cite{ni-cat}. Likewise, several novel applications such as sensors, electrical contacts and switches, catalysis and enhancement of photo-catalytic activity have been reported in recent time for the Ni-Ag binary systems.\cite{sensor,switch,cat2,photo} Enhanced catalytic performance of Ni-Ag bimetallic nano-systems has also been used for the reduction of nitroarenes and construction of highly efficient direct borohydride fuel cells.\cite{arene,fuel} Small Ni-Ag nanoalloys have also been predicted to exhibit high spin states and could be a promising candidate for single-molecule magnetism.\cite{highspin} However, to the best of our knowledge and contrary to expectation, in-depth electronic structure calculations correlating structure and property for the entire composition range of this interesting binary nano system, is lacking.

 An important issue in the study of alloy system, for bulk as well as nano phases, is the issue of mixing. Bulk Ni and Ag systems are reported to be immiscible for all compositions showing no tendency towards formation of solid solution.\cite{immiscible_niag} It is a pertinent question how this scenario changes at nano-scale. In case of a bimetallic nano cluster, the degree of mixing/segregation between the two species of atoms depends on a complex interplay of various parameters, such as atomic radii of the constituent species, strength of homo-nuclear {\sl versus} hetero-nuclear bonds, charge transfer, surface energies of the elements in their bulk phases and so on.\cite{alloy_rev1,factors} Depending on the mixing tendency between the two species of atoms, the atomic arrangement of a bimetallic nano system, can adopt several different patterns which can be broadly classified into three distinct types - ($i$) ordered or randomly intermixed nano-alloy, ($ii$) core-shell or onion-like multishell architectures and ($iii$) fully phase-segregated pattern, known as the {\sl janus} nanoalloys.\cite{alloy_rev1} The existing experimental as well as theoretical works on the M-NM binary nano-clusters in general, bring out an interesting common feature which suggests that when the components of the binary nano clusters have a miscibility gap in their bulk phases, a core-shell like chemical ordering is more likely to form in order to minimize the internal strain.\cite{nm-fm,mismatch,mismatch2,screening} The situation for the Ni-Ag nano-clusters is unfortunately confusing both from the point of view of experimental as well as theoretical studies, with some reports supporting core-shell like configuration following the general trend of M-NM binary clusters,\cite{agni1,agni2,agni3,agni4} while others report formation of homogeneous alloy structure.\cite{new1,homogeneous1,homogeneous2,homogeneous3,homogeneous4}For example, global optimization of the NiAg nano clusters using some semi-empirical potentials with the tight-binding second moment approximation indicated {\sl poly-icosahedral} structure of core-shell type for cluster sizes of 34 and 38 atoms.\cite{theory,agni-melting} On the other hand, the appearance of solid solution structured Ni-Ag nanoparticles, has also been discussed recently.\cite{frozen}

        In the present work, we aim on shedding light to this confusing situation through DFT based electronic structure calculations. In particular, we have studied the equilibrium structures, energetics, alloying {\sl versus} segregation behavior and magnetic properties of the Ni$_{13-n}$Ag$_n$ clusters, with $n$ = 0$-$13. We focus here on 13 atoms cluster size which is of particular interest because nano-clusters with 13 atoms have a high rate of occurrence in the time-of-flight mass spectrometry experiments for cluster production.\cite{13atoms} Such observations are indicative of their high stability. We have considered all possible compositions as we are interested in the trend of the variation for structure and electronic properties with the change of composition. The chosen size of the studied clusters allows us carrying out rigorous ab-initio calculations, which in turn leads to an in-depth understanding of the trend in the structural segregation and electronic properties. Our analysis presented here for the small Ni$_m$Ag$_n$ binary clusters indicates that mixing energy is negative at all compositions {\it i.e.} 13 atoms Ni$_m$Ag$_n$ clusters are lower in energy compared to the energy of $m$Ni$_{13}$ and $n$Ag$_{13}$ for all values of $m$ and $n$. The structural growth patterns indicate a clear trend towards core-shell like morphology with the less cohesive Ag atoms occupying the outer shell position supporting some of the experimental and theoretical studies.\cite{agni1,agni2,agni3,agni4} We find that the structural positioning of the more cohesive as well as smaller sized Ni atoms at the highest coordinated sites together with strong Ni-Ag inter-facial interaction provide the driving force for the core-shell structure. We believe that our analysis of structure-property relationship, presented here for the Ni$_{13-n}$Ag$_n$ alloyed nano-clusters will be helpful for understanding the trend in mixing of the M-NM nano alloy systems in general. We also analyzed the ground state magnetic structures for each composition, which should be useful for further study.

\begin{figure}
\rotatebox{0}{\includegraphics[height=2.0cm,keepaspectratio]{Figure1.pdf}}
\caption{Starting structures used as input to optimization process within
ab-initio molecular dynamics.}
\label{starter}
\end{figure}

\section{\label{methodology} Computational Details}

 The calculations reported in this study, were based on DFT within the framework of pseudo-potential plane wave method, as implemented in the Vienna ab-initio Simulation Package (VASP).\cite{kresse2} We used the Projected Augmented Wave (PAW) pseudo-potential \cite{blochl,kresse} coupled with the generalized gradient approximation (GGA) to the exchange correlation energy functional as formulated by Perdew, Burke and Ernzerhof (PBE).\cite{perdew} The 3$d$ as well as 4$s$ electrons for Ni atoms and 5$s$ as well as 4$d$ electrons for Ag atoms were treated as the valence electrons and the wave functions were expanded in the plane wave basis set with the kinetic energy cut-off of 300 eV. For the cluster calculations, a simple cubic super-cell was used with the periodic boundary conditions, where two neighboring clusters were kept separated by around 12 {\AA} vacuum space. The large cell-size essentially makes the interaction between cluster images negligible. Reciprocal space integrations were carried out at the $\Gamma$ point. The convergence of the energies with respect to the cut-off as well as k-mesh values were checked. Due to the presence of the magnetic Ni atoms, spin-polarized DFT calculations were performed.

The task of structural optimization of a cluster, amounts to finding out the minimum energy structure (MES) on the (3$N$-6) dimensional potential energy surface (PES) of a N atoms cluster. This is a complex task for a cluster of not too small size like 13 atoms as in the present study. The situation becomes further complicated in the present case of nano-alloys due to the presence of in-equivalent permutational isomers, known as homotops.\cite{htop} This demands searching of the configurational space with a good global optimization technique. Several algorithms have been proposed for this purpose.\cite{gopt} In the present study, we have adopted the thermodynamically motivated ab-initio molecular dynamics scheme which solves the Newtonian equation of motion based on quantum mechanical forces to move from one local minima to another. To locate the global minima, we used the so-called simulated annealing approach, in which the clusters were first heated up to a temperature of T$_S$, maintained at this temperature for at least 6 ps and finally allowed to cool down again to 0 K. A time step of 1 fs was used for all calculations. The cooling process has been done for longer period and maintained at a very slow rate, with 0.05 K per iteration throughout the process. Note that such simulated annealing has been used previously for determining optimized structures of bimetallic nano-clusters.\cite{feau2,mismatch2} To speed up the global exploration of the PES, we used a favored structural motif as starting structure in the  simulated annealing process. In order to minimize the influence of starting structure, we have considered five initial morphologies, namely icosahedron (ICO), cub-octahedron (CUBO), cubic-closed packed (CCP), buckled bi-planar (BBP) and hexagonal bi-layer (HBL) structures, as shown in Fig. \ref{starter}. It should be noted that these five morphologies encompass various ordered and disordered structures reported so far for the transition metal mono-atomic clusters of 13 atoms.\cite{ni13-latest,ni13-old,ag13,mn13,fe13,co13,cubo} Importantly, these five configurations have different distribution of coordination number among the 13 constituent atoms which implies their different degrees of compactness.

It is to be noted that the melting temperature of the Ag-rich binary (Ni$_{0.25}$Ag$_{0.75}$)$_N$ clusters with $N=$55, 147, 309 atoms, has been reported previously to be lower than 1000K.\cite{new1} However, a pure Ni$_{13}$ cluster has been predicted to be very resistance to melting with solid to liquid phase transition occurring close to the bulk melting temperature {\it i.e.} 1726 K.\cite{new2} We thus conclude while choice of T$_S$ = 1000 K would be sufficient for melting in cases of the Ag-rich clusters, the Ni-rich clusters may have melting point above 1000 K and thus the choice of T$_S$ = 1000 K may fail to escape the valley of the starting isomers. In order to ensure that, we have considered starting structures above the melting point and further repeated the simulated annealing calculations for the three Ni-rich clusters considering their structure at 2000 K temperature as the initial starting structure. Our analysis of bond length fluctuations\cite{new3,new4} during the simulated annealing runs as presented in the Supplementary Material, indicates that the melting temperature of the Ni-rich nano-alloys to be little above 1000 K. Additionally, we have considered the MES of a given composition to serve as one of the starting structures in the simulated annealing run for the other compositions.
The structures obtained out of the simulated annealing runs, have been re-optimized using the conventional zero temperature relaxation technique. In this process, symmetry unrestricted geometry optimizations were performed using the conjugate gradient and the quasi-Newtonian methods until all the force components were less than a threshold value of 0.001 eV/{\AA}. We considered both the collinear as well as non-collinear spin structures to determine the magnetic moment of the MES. While spin-orbit interaction has been considered in the non-collinear calculations, all the possible spin  multiplicities for each structure have been considered in the collinear calculations for every isomer having a given morphology for each composition.

\begin{figure}
\rotatebox{0}{\includegraphics[height=9.6cm,keepaspectratio]{Figure2.pdf}}
\caption{(Color online) Upper panel : Minimum energy structures for all Ni$_{13-n}$ Ag$_n$ clusters. The blue (darker gray) and light green (light gray) colored balls represent Ni  and Ag atoms, respectively. Bottom panels : Variations of total binding energy (left) as well as bond length (right) for the MESs of the Ni$_{13-n}$Ag$_n$ clusters.}
\label{mes}
\end{figure}

\begin{figure*}
\rotatebox{0}{\includegraphics[height=5.7cm,keepaspectratio]{Figure3.pdf}}
\caption{(Color online) Plot of radial distribution function (left panel) and average coordination number per Ni-sites as well as Ag-sites (right panel) for the MESs of the Ni$_{13-n}$Ag$_n$ clusters. The distance of the atoms in the left panel is given with respect to the center of the respective cluster. }
\label{rdf}
\end{figure*}

\section{\label{results}Results and Discussions}
In this section, we investigate the optimized ground state structures, energetics, trend in mixing, electronic and magnetic properties for the MESs of the Ni$_{13-n}$Ag$_n$ clusters.

\subsection{\label{structure}Structures }

Fig. \ref{mes} shows the minimum energy configurations of all the Ni$_{13-n}$Ag$_n$ clusters. First note that our calculations predict a CCP-like structure for the MES of the pure Ni$_{13}$ cluster and a BBP structure for the pure Ag$_{13}$ cluster in agreement with the report in literature.\cite{ni13-latest} Among the binary clusters, first four Ni-rich clusters, retain the CCP-like morphology. In these cases, the substituting Ag atoms occupy the three and four coordinated sites of the CCP structure. The use of rigorous sampling of potential energy surface of the starting structures above melting point, as explained in the Section \ref{methodology}, gives us confidence in our obtained structures. We thus believe that the preference for the CCP-symmetry based structures as the MES of the four Ni-rich binary clusters is robust and possibly guided by the special structural pattern of that morphology possessing a three-coordinated site and three four-coordinated sites. These low coordinated sites would be the obvious choice for the substituting Ag-atoms.

 For further increase of Ag content {\it i.e.} for the Ni$_8$Ag$_5$ to NiAg$_{12}$ clusters, the MESs have strongly distorted and changed their morphology completely. Interestingly, our calculations reveal a common trend in the optimized structural patterns of the Ni$_8$Ag$_5$ to NiAg$_{12}$ clusters. Each of these structures consists of a pentagonal bi-pyramidal (PBP) core of seven atoms and the rest six atoms position around this PBP core in such a way to form more pentagonal rings with the atoms of the PBP core. As for examples, the PBP core is solely made of seven Ni atoms for the MESs of the Ni$_8$Ag$_5$ and Ni$_7$Ag$_6$ clusters. Then the Ni atoms of this PBP core are getting substituted by Ag atom one by one for the subsequent Ag-rich clusters. Finally, the MES for the NiAg$_{12}$ cluster consists of several coupled PBP sections, each sharing the Ni atom either at its apex position or at the pentagonal ring.  This is a very stable configuration for the NiAg$_{12}$ cluster, where the Ni atom is coordinated by neighboring ten Ag atoms  and the Ni atom is off-centered in the cluster (cf. Fig. \ref{mes}) in order to minimize the strain arising from the size mismatch between Ni and Ag atoms. We find that an optimized ICO structure of NiAg$_{12}$ cluster with the Ni atom at the center of the ICO, is higher in energy by an amount of 0.4 eV with respect to the MES of NiAg$_{12}$ cluster. Note that using empirical potential based DFT calculations, Ferrando {\it et al.} first predicted a five-fold {\it pancake} geometry for the global total-energy minima of the 34-atoms NiAg alloy clusters.\cite{agni-melting}It is also interesting to note from the Fig. \ref{mes} that the Ni-atoms at the core part are not symmetrically positioned around the center of the binary nano-clusters. Rather, they are asymmetrically distributed off the center owing to possible strain relief, as has been suggested.\cite{ferrando}

                To analyze the energetics among the different isomers of each NiAg cluster, we have calculated their binding energy, E$_B$ which has been defined as $E_B = E_{tot}^{free-atoms}-E_{tot}^{MES}$, where E$_{tot}^{MES}$ is the total energy of the MES and E$_{tot}^{free-atoms}$ is the total energy of the constituent atoms in the gas phase ({\it i.e.} isolated form). Obviously, a more positive value of E$_B$ indicates higher binding with respect to the isolated atoms. Besides the equilibrium geometries of the two pure clusters, our calculated binding energies of 3.2 eV/atom and 1.63 eV/atom for the MESs of the Ni$_{13}$ and Ag$_{13}$ clusters respectively, are also in accordance with the recent results by the DFT calculations.\cite{ni13-latest} Our calculated binding energies for the MESs of all the NiAg clusters as shown in the left bottom panel of the Fig. \ref{mes}, decrease almost linearly with the decrease of Ni content, which is readily understandable from the trend in the bulk cohesive energies of Ni and Ag. In order to quantify the different degree of disorder in the MESs, we have calculated average effective coordination numbers ($\langle ECN \rangle$) and bond-lengths, where an exponentially averaging weight function has been employed. The weighted averaging takes into account the different contributions to the measuring quantities for the surrounding atoms at different distances in these optimized low-symmetric configurations as followed in the previous work\cite{ecn}. Among the NiAg clusters, we found that the MES of the NiAg$_{12}$ cluster has the largest value of $\langle ECN \rangle$ $\sim$5.58. Our calculated overall average bond lengths for the Ni$_{13-n}$Ag$_n$ clusters as shown in the right bottom panel of the Fig. \ref{mes}, indicate that the bond lengths increase almost linearly with the increase of Ag content. This monotonic increase of the bond lengths with the increasing Ag-content results mainly from the larger atomic radius of Ag than that of Ni.

\begin{figure}
\rotatebox{0}{\includegraphics[height=5.2cm,keepaspectratio]{Figure4.pdf}}
\caption{(Color online)Variation of mixing energies (left panel) and second differences in energy as well as excess energies (right panels) as a function of Ag-concentration for the MESs of the Ni$_{13-n}$Ag$_n$ clusters.}
\label{mixing}
\end{figure}

Regarding the chemical ordering of the two species of atoms in the MESs, it is seen from the Fig. \ref{mes} that the Ag atoms occupy mostly the less coordinated sites. On the other hand, the Ni atoms tend to occupy the more coordinated sites and they cluster together having no broken Ni$-$Ni bonds. This leads to the stability of a core-shell like structure. In order to quantify the chemical ordering of the Ni and Ag atoms in the MES of the twelve NiAg binary clusters, we have calculated the site preference of Ni and Ag atoms, measured in terms of a radial distribution function, $\eta$(r). $\eta$(r) gives the percentage of the number of Ni or Ag atoms in a spherical cell  of width $\Delta r$ at a distance between r and r$+\Delta r$ from the center of the cluster. Our calculated radial distribution function for the MESs of the twelve binary NiAg clusters, has been shown in Fig \ref{rdf}. It clearly indicates that there is a strong preference of the Ag atoms to be positioned far away from the center of the cluster, while the Ni atoms position mostly near the center of the clusters. We have also calculated the number of the nearest neighbors within a fixed cut-off distance, for every constituting atom in the MES of each Ni$_{13-n}$Ag$_n$ cluster. The variations of the average nearest neighbor coordination number per Ni-site as well as Ag-site are also shown in the Fig. \ref{rdf}. It is clearly seen that the coordination number for the Ni atoms is always higher than that of the Ag-atoms, which again support towards formation of core-shell structure with Ni atoms at the core and Ag atoms at the outer shell position, as reported earlier for the bigger sized Ni-Ag alloy clusters.\cite{theory,agni-melting,agni-coreshell}

\subsection{\label{alloy}Mixing and Electronic Properties}
To estimate the stability of the binary NiAg clusters, we have calculated mixing energy\cite{alloy_rev1,agni-coreshell,mntc} of the MESs for all compositions. The mixing energy for a 13-atoms Ni$_m$Ag$_n$ cluster ({\it i.e.} $m + n $=13) is defined as

\begin{equation}
E_{mix}=\frac{1}{13}\left[E(Ni_mAg_n)-\frac{m}{13}E(Ni_{13})-\frac{n}{13}E(Ag_{13})\right]\nonumber
\label{mee}
\end{equation}

Here E(Ni$_m$Ag$_n$) is the energy for the MES of the binary Ni$_m$Ag$_n$ cluster, while E(Ni$_{13}$) and E(Ag$_{13}$) are the energies of MESs of the pure Ni$_{13}$ and Ag$_{13}$ clusters respectively. It gives a measure of the energy gain for the binary cluster with respect to the segregated phase consisting of two independent clusters of $\frac{m}{13}\times Ni_{13}$ and $\frac{n}{13}\times Ag_{13}$. The above equation implies that the mixing energy is always zero for the pure extremes, while its negative values indicate that the alloy formation is thermodynamically favorable. The largest negative value of the mixing energy corresponds to the most stable alloyed cluster for the given size. On the other hand, a positive value of the mixing energy will characterize a tendency of segregation among the two species of constituent atoms. Fig. \ref{mixing} shows the plot of our calculated mixing energies of all the MESs of the Ni$_{13-n}$Ag$_n$ clusters as a function of Ag atoms in them. {\sl Interestingly, the mixing energies are negative for all compositions, indicating that from the energy consideration alloy formation for the Ni$_{13-n}$Ag$_n$ clusters, is favored for the whole range of compositions.} As seen from the Fig. \ref{mixing}, the mixing energies of the MESs decrease almost monotonically with the increase of Ag-content and finally, reach the minimum value for the NiAg$_{12}$ cluster. This composition, therefore, corresponds to the {\it magic} composition having the highest stability for the 13 atoms sized NiAg alloy clusters. Importantly, most of the NiAg alloy clusters are stable by substantial energy margin, which indicates a clear propensity of mixing for the binary NiAg clusters. It is to be noted that previous study\cite{80percen} also indicates formation of the most stable NiAg alloyed nano-clusters for Ag-rich composition, in accordance with our results. The present study, however, to the best of our knowledge, reports for the first time favorable mixing of the binary NiAg nano-clusters for all possible compositions. In order to understand the trend in stability for the NiAg alloyed clusters, we have further analyzed the HOMO-LUMO gap for the MES of each composition. In accordance with our prediction of the highest stability for the NiAg$_{12}$ cluster, we find that the NiAg$_{12}$ cluster is also associated with the maximum HOMO-LUMO gap $\sim$ 0.5 eV. Combining the trend of mixing together with the trend in the structural patterns of the MESs in Fig. \ref{mes} also gives a relation between mixing and CN. It indicates that positioning of Ag atoms at the lowest coordinated sites for the Ni-rich clusters along the sequence Ni$_{12}$Ag to Ni$_7$Ag$_6$ clusters correlates with high mixing ({\it i.e.} more negative mixing energy), while positioning Ni atoms at the highest coordinated sites for the Ag-rich clusters along the sequence Ni$_6$Ag$_7$ to NiAg$_{12}$ clusters also correlates with high mixing. It implies that CN site rule is clearly playing important role for mixing.

\begin{figure}
\rotatebox{0}{\includegraphics[height=3.5cm,keepaspectratio]{Figure5.pdf}}
\caption{ (Color online) Plot of the charge density difference of the MESs for the Ni$_{12}$Ag, Ni$_7$Ag$_6$ as well as NiAg$_{12}$ clusters. The isovalue for the charge transfer plot, is fixed at 0.003 e$^{-}$/$\AA^3$. The accumulation (depletion) of charge is denoted by blue (red) colored isosurface.}
\label{hybd}
\end{figure}

Second difference in energy, $\Delta_2$ is a quantity to compare the relative stability of a binary system between its various compositions. It is defined as\cite{alloy_rev1} $\Delta_2(13,n)= E(13,n+1)+E(13,n-1)-2E(13,n)$. The variation of $\Delta_2$ with composition for the MESs of the Ni$_{13-n}$Ag$_n$ clusters has been shown in the top right panel of the Fig. \ref{mixing}. Note that the variation of $\Delta_2$ shows the highest and the most prominent peak for $n = 12$, which reconfirms the relatively higher stability for this composition.  We have also analyzed {\sl excess energy} for the MESs of the NiAg alloyed clusters. The {\sl excess energy}\cite{agni-melting} for a binary Ni$_m$Ag$_n$ cluster with respect to $N = m + n$ bulk atoms has been defined as $E_{exc}=\frac{E(m,n)-m\epsilon_{Ni}^{coh}-n\epsilon_{Ag}^{coh}}{N^{2/3}}$; where $E(m,n)$ is the total energy of the MES for each Ni$_m$Ag$_n$ cluster and $\epsilon$'s are the bulk cohesive energies per atom. We use experimental values of the FCC bulk cohesive energies of each species, that is, $\epsilon^{coh}_{Ni}$ = -4.8332 eV/atom and $\epsilon^{coh}_{Ag}$=-2.4904 eV/atom. According to the definition, the excess energy resembles the surface energy per unit area for that cluster shape\cite{se} and the surface area is approximated by the $N^{2/3}$ factor which holds good usually for quite larger cluster size. Therefore, excess energy is a relevant parameter to compare the relative stability of the clusters of different compositions and a dip in the variation of excess energy {\sl versus} composition indicates the most stable cluster structure. The bottom right panel of the Fig. \ref{mixing} shows the plot of our calculated excess energies of the MESs for all the Ni$_m$Ag$_n$ clusters. Note that it decreases almost linearly with the increasing Ag-concentration and reaches the minimum value for the NiAg$_{12}$ cluster. Therefore, the cluster of the highest stability is not only associated with the most negative mixing energy, but also the least excess energy.

From Figs. \ref{mes} and \ref{rdf}, we learnt that a core-shell like structure is adopted for Ni$_m$Ag$_n$ clusters of all compositions, which in turn points towards the role of Ni$-$Ag interaction at the interfaces formed between its Ni-rich and Ag-rich regions. In order to investigate this, we have analyzed charge density difference $\delta\rho = \rho_{Ni_mAg_n} - \rho_{Ni_m}-\rho_{Ag_n}$; where $\rho_{Ni_mAg_n}$ is the total charge density of the Ni$_m$Ag$_n$ alloy cluster and $\rho_{Ni_m}$($\rho_{Ag_n}$) is the charge density of the Ni$_m$ (Ag$_n$) fractional cluster with same morphology as in the alloy cluster. A positive (negative) value of $\delta\rho$ would correspond to accumulated (depleted) charge. Analysis of $\delta\rho$, therefore, gives us information about the overall charge redistribution after alloying. Our calculated $\delta\rho$ values have been plotted in Fig. \ref{hybd} for the MESs of the three selected NiAg alloyed clusters, namely Ni$_{12}$Ag, Ni$_7$Ag$_6$ and NiAg$_{12}$ clusters. The plot of $\delta\rho$ indicates that there is appreciable charge transfer across the inter-atomic bonds and the accumulated charges mostly reside at the Ni-Ag interface. In case of the MES for NiAg$_{12}$ cluster, it is seen that the transferred charge is accumulated solely around the Ni atom, which also play role in destroying its magnetic character as will be discussed later.

\begin{figure*}
\rotatebox{0}{\includegraphics[height=7.9cm,keepaspectratio]{Figure6.pdf}}
\caption{(Color online) Plot of overall as well as Ni projected total magnetic moments (left top panel) and average spin, orbital magnetic moments ({\it i.e.} M$_S$, M$_L$ respectively of the left bottom panel) for the MES of each NiAg system. The right panel shows the orientation and magnitude of the atom-centered magnetic moments for four alloy systems - Ni$_{12}$Ag, Ni$_6$Ag$_7$, Ni$_4$Ag$_9$ and Ni$_2$Ag$_{11}$ clusters. The values of average atom-centered magnetic moment are given in ($\mu_B$/atom). The length of the arrow is proportional to the magnitude of the atom-centered magnetic moment. Absence of arrow for the Ag atoms indicates that the magnitude of Ag-atom centered magnetic moment is very small compared to that of Ni-atom.}
\label{magdel}
\end{figure*}

\subsection{\label{mag}Magnetic Properties}
Mono-atomic nano particles of the conventional magnetic elements usually exhibit an enhancement of magnetic moment compared to their bulk value due to the reduced coordination.\cite{fm-mag} Free-standing Ni clusters also possess magnetic moment which increases towards the atomic limit with the decreasing cluster size.\cite{ni_mag} On the other hand, nano-metric Ni clusters embedded in a metallic Ag matrix, exhibit an exceptional property. The magnetic moments of the embedded Ni clusters not only get quenched like clusters of other 3$d$ transition metal atoms,\cite{quenched} but the Ni cluster also becomes nonmagnetic below a critical size limit.\cite{nonmagnet} The calculated magnetic moments for the MESs of the binary NiAg clusters which possess a core-shell like structural pattern with Ni atoms at the core, also indicate similar type of variation and the NiAg binary cluster indeed becomes nonmagnetic in case of the NiAg$_{12}$ cluster which is incidentally identified here as the magic cluster for the 13 atoms sized binary NiAg clusters. Starting with total magnetic moment of 9.95 $\mu_B$ of pure Ni
cluster, which is in accordance with the previous results,\cite{ni13-latest}
the total magnetic moments of the MESs for the NiAg alloy clusters, decrease almost monotonically with the increase of Ag-content and eventually become zero for the NiAg$_{12}$ cluster, as seen from the left top panel of Fig. \ref{magdel}.
To scrutinize the contribution to the total magnetic moments, we have further analyzed the atom-centered local magnetic moment by integrating the spin density ({\it i.e.} $\rho(\vec{r})=\rho_\uparrow(\vec{r})-\rho_\downarrow(\vec{r})$) within the PAW spheres around the constituting atoms, which have radii r$_0$ = 1.5 $\AA$ for Ag atoms and r$_0$ = 1.3 $\AA$ for Ni atoms. The magnetic moment arises mainly from the localized $d$-electrons of the Ni atoms. In addition, the hybridization of the constituent Ag atoms with the neighboring Ni atoms induces small spin polarization to the Ag atoms, arising from its unpaired $s$-electron. However, the induced magnetic moment of the Ag atoms is found to be very small compared to that of the Ni atoms. Thus, as expected, the total magnetic moments show an overall decreasing trend with the decreasing Ni-atoms.

It is important to note that though the total magnetic moment of the NiAg alloy clusters is mainly contributed by its constituent Ni atoms, its values are relatively lower compared to the magnetic moment of the free-standing pure Ni-clusters having the size same as that of the number of Ni atoms present in the corresponding NiAg alloy cluster. For example, the total magnetic moments of the isolated pure Ni$_2$, Ni$_3$ , Ni$_4$, Ni$_5$ and Ni$_6$ clusters have been predicted previously as 2 $\mu_B$, 2 $\mu_B$, 4 $\mu_B$, 6 $\mu_B$ and 8 $\mu_B$ respectively.\cite{pure_ni1,pure_ni2,pure_ni3,ni_mag} On the other hand, the total magnetic moments of the Ag$_{11}$Ni$_2$, Ag$_{10}$Ni$_3$, Ag$_9$Ni$_4$, Ag$_8$Ni$_5$ and Ag$_7$Ni$_6$ clusters in the present study, are 1 $\mu_B$, 2 $\mu_B$, 3 $\mu_B$, 4 $\mu_B$ and 5 $\mu_B$ respectively. This reduction in case of the NiAg alloy clusters, is due to the appreciable hybridization between the electronic states of Ni and Ag. The zero magnetic moment for the NiAg$_{12}$ cluster is then understandable, as the only Ni atom, in this case is coordinated by ten nearest neighboring Ag atoms and the substantial hybridization effect drives the observed
nonmagnetic state. This observation is also in line with the fact that a magnetic impurity dissolved in a nonmagnetic matrix, can indeed become nonmagnetic.\cite{ascroft} Fig. \ref{magdel} also shows separately the contributions of the spin as well as orbital magnetic moments to the total magnetic moments for the MESs of the Ni$_{13-n}$Ag$_n$ clusters. Note that there is some significant contribution of the orbital magnetic moment to the total magnetic moment. The orbital moment is contributed mainly by the Ni atoms, as seen previously for pure Ni clusters.\cite{orb_mag} The orbital magnetic moment of the NiAg alloy clusters decreases with the decrease of Ni-content, while the spin magnetic moment follows the same trend of variation for the total magnetic moment.  In the MES of the Ni$_{13-n}$Ag$_n$ clusters, it is found that the Ni-atoms centered magnetic moments are always ferromagnetically coupled irrespective of the change of composition as shown in the Fig. \ref{magdel} for some selected NiAg alloy clusters. On the other hand, the tiny Ag-centered magnetic moments (not visible in the plots of Fig. \ref{magdel}) are found to be mostly anti-ferromagnetic with the Ni-centered magnetic moments.

\section{\label{conclu}Summary and Conclusions}
In summary, we have performed first principles based electronic structure calculations for the magnetic/noble metal binary Ni$_{13-n}$Ag$_n$ clusters, which confirms that the mixing is energetically favorable for the binary NiAg clusters of all compositions. The optimal morphologies of the alloy clusters adopt a core-shell like structural patterns with the Ni-atoms positioned at the inner core region, as quantified here in terms of a radial distribution function. The magic composition, characterized with the highest mixing energy, is found for the NiAg$_{12}$ cluster, which adopts a very unusual structural pattern associated with the highest ECN, zero net magnetic moment, largest HOMO-LUMO gap and asymmetric positioning of Ni atom which is off the center of the Ag$_{12}$-cage. The Ni$-$Ag inter-facial interaction plays crucial role in determining structural, electronic and mixing properties of the alloy clusters. The zero net magnetic moment of the NiAg$_{12}$ cluster is in line with the magnetic properties of a Ni nano-cluster embedded in a metallic Ag matrix.

\section*{Supplementary Material}
See supplementary material for analysis of melting behaviour for the Ni-rich clusters in terms of root-mean-square bondlength fluctuation.

\acknowledgments
 S.D. thanks Department of Science and Technology, India for support through INSPIRE Faculty Fellowship, Grant No. IFA12-PH-27. S.D. also acknowledges
helpful discussions with Prof. Julius Jellinek.

\section*{References}