Running the Simulations
Setting up the Simulator object
Documentation for the pycce.Simulator - main class for conducting CCE Simulations.
- class pycce.main.Simulator(spin, position=None, alpha=None, beta=None, gyro=None, magnetic_field=None, D=None, E=0.0, r_dipole=None, order=None, bath=None, pulses=None, as_delay=False, n_clusters=None, **bath_kw)
The main class for CCE calculations.
The typical usage includes:
Read array of the bath spins. This is done with
Simulator.read_bathmethod which accepts either reading from .xyz file or from theBathArrayinstance with defined positions and names of the bath spins. In the process, the subset of the array within the distance ofr_dipolefrom the central spin is taken and for this subset the Hyperfine couplings can be generated.If no
hyperfinekeyword is provided and there are some hyperfine couplings already, then no changes are done to the hyperfine tensors. Ifhyperfine='pd', the hyperfine couplings are computed assuming point dipole approximation. For all accepted arguments, seeSimulator.read_bath.Generate set of clusters with
Simulator.generate_clusters, determined by the maximum connectivity radiusr_dipoleand the maximum size of the clusterorder.Compute the desired property with
Simulator.computemethod.
Note
Directly setting up the attribute values will rerun
Simulator.read_bathand/orSimulator.generate_clustersto reflect updated value of the given attribute.E.g. If
Simulator.r_bathis set to some new value after initialization, thenSimulator.read_bathandSimulator.generate_clustersare called with the increased bath.First two steps are usually done during the initialization of the
Simulatorobject by providing the necessary arguments.Notes:
Depending on the number of provided arguments, in the initialization process will call the following methods to setup the calculation engine.
If
bathis provided,Simulator.read_bathis called with additional keywords in**bath_kw.If both
r_dipoleandorderare provided andbathis not None, theSimulator.generate_clustersis called.
See the corresponding method documentation for details.
Examples:
>>> atoms = random_bath('13C', 100, number=2000, seed=10) >>> calc = Simulator(1, bath=atoms, r_bath=40, r_dipole=6, >>> order=2, D=2.88 * 1e6, >>> magnetic_field=500, pulses=1) >>> print(calc) Simulator for center array of size 1. Parameters of cluster expansion: r_bath: 40 r_dipole: 6 order: 2 Bath consists of 549 spins. Clusters include: 549 clusters of order 1. 457 clusters of order 2.
Args:
- spin (CenterArray or float or array with shape (n,)):
CenterArray containing properties of all central spins.
OR
Total spin of the central spin (Assumes one central spin).
OR
Array of total spins of the central spins (Assumes n central spins).
- position (ndarray):
Cartesian coordinates ar array of coordinates in Angstrom of the central spin(s). Default (0., 0., 0.). If provided, overrides the position in CenterArray.
- alpha (float or ndarray with shape (S, )): \(\ket{0}\) state of the qubit in \(S_z\)
basis or the index of eigenstate to be used as one.
Default: Lowest energy eigenstate of the central spin Hamiltonian.
If provided, overrides the alpha state in the CenterArray.
- beta (float or ndarray with shape (S, )): \(\ket{1}\) state of the qubit in \(S_z\) basis
or the index of the eigenstate to be used as one.
Default: Second lowest energy eigenstate of the central spin Hamiltonian.
If provided, overrides the beta state in the CenterArray.
gyro (float or ndarray with shape (3, 3)): Gyromagnetic ratio of the central spin(s) in rad / ms / G.
OR
Tensor describing central spin interactions with the magnetic field.
Default -17608.597050 kHz * rad / G - gyromagnetic ratio of the free electron spin.
If provided, overrides the gyro value in CenterArray.
- D (float or ndarray with shape (3, 3)): D (longitudinal splitting) parameter of central spin
in ZFS tensor of central spin in kHz.
OR
Total ZFS tensor. Default 0.
If provided, overrides the ZFS value in CenterArray.
- E (float): E (transverse splitting) parameter of central spin in ZFS tensor of central spin in kHz.
Default 0. Ignored if
Dis None or tensor.
bath (ndarray or str): First positional argument of the
Simulator.read_bathmethod.Either:
Instance of BathArray class;
ndarray with
dtype([('N', np.str_, 16), ('xyz', np.float64, (3,))])containing names of bath spins (same ones as stored in self.ntype) and positions of the spins in angstroms;the name of the .xyz text file containing 4 columns: name of the bath spin and xyz coordinates in A.
r_dipole (float): Maximum connectivity distance between two bath spins.
order (int): Maximum size of the cluster to be considered in CCE expansion.
- n_clusters (dict): Dictionary which contain maximum number of clusters of the given size.
Has the form
n_clusters = {order: number}, whereorderis the size of the cluster,numberis the maximum number of clusters with this size.If provided, sort the clusters by the “strength” of cluster. Then the strongest
numberof clusters is taken.We define the strength of the cluster \(s\) as an inverse of the sum over inverse pairwise interaction strengths of the minimal cluster:
\[s = (\sum_{i<j\in C} \frac{r^3}{\gamma_i\gamma_j})^{-1}\]Where \(\gamma_i\) is the gyromagnetic ration of a spin \(i\), \(r\) is the distance between two spins, and the summation of \(i, j\) goes only over the edges of the minimally connected cluster.
We define minimally connected cluster as a cluster with lowest possible number of edges that still forms a connected graph. If multiple choices of the minimally connected cluster for the same cluster are possible, the one with the larger strength \(s\) is chosen.
pulses (list or int or Sequence): Number of pulses in CPMG sequence or list with pulses.
**bath_kw: Additional keyword arguments for the
Simulator.read_bathmethod.- property alpha
ndarray or int: Returns .center.alpha property: \(\ket{0}\) qubit state of the central spin in Sz basis OR index of the energy state to be considered as one.
- as_delay
bool: True if time points are delay between pulses (for equispaced pulses), False if time points are total time. Ignored if
pulsescontains the time delays.
- property bath
BathArray: Array of bath spins used in CCE simulations.
- bath_state
bath_state (ndarray): Array of bath states.
- property beta
ndarray or int: Returns .center.beta property: \(\ket{1}\) qubit state of the central spin in Sz basis OR index of the energy state to be considered as one.
- center
CenterArray: Array of central spins.
- clusters
dict: Dictionary containing information about cluster structure of the bath.
Each keys n correspond to the size of the cluster. Each
Simulator.clusters[n]containsndarrayof shape (m, n), where m is the number of clusters of given size, n is the size of the cluster. Each row of this array contains indexes of the bath spins included in the given cluster. Generated during.generate_clusterscall.
- property error_range
- float: Maximum distance between positions in bath and external
bath to consider two positions the same (default 0.2).
- property ext_r_bath
- float: Maximum distance from the central spins of the bath spins
for which to use the data from
external_bath.
- property external_bath
BathArray: Array with spins read from DFT output (see
pycce.io).
- fixstates
dict: If not None, shows which bath states to fix in random bath states.
Each key is the index of bath spin, value - fixed \(\hat S_z\) projection of the mixed state of nuclear spin.
- fulldm
bool: True if return full density matrix as the result in the gCCE calculations.
- property hyperfine
- str, func, or Cube instance: This argument tells the code how to generate hyperfine couplings.
If (
hyperfine = Noneand all A in provided bath are 0) or (hyperfine = 'pd'), use point dipole approximation. Otherwise can be an instance ofCubeobject, or callable with signature:func(array)where array is the
BathArrayobject.
- interlaced
bool: True if use hybrid CCE approach - for each cluster sample over states of the supercluster.
- level_confidence
float: Maximum fidelity of the qubit state to be considered eigenstate of the central spin Hamiltonian when
second_orderset to True.
- property magnetic_field
ndarray: Array containing external magnetic field as (Bx, By, Bz) or callable with signature
magnetic_field(pos), whereposis an array with shape (3,) with the position of either bath or central spin. Default is (0, 0, 0).
- masked
bool: True if mask numerically unstable points (with coherence > 1) in the averaging over bath states.
Note
It is up to user to check whether the possible instability is due to numerical error or unphysical assumptions of the calculations.
- property n_clusters
dict: Dictionary which contain maximum number of clusters of the given size. Has the form
n_clusters = {order: number}, whereorderis the size of the cluster,numberis the maximum number of clusters with this size.If provided, sorts the clusters by the strength of cluster interaction, equal to the inverse of a sum of inverse pairwise interaction in the minimally connected cluster. Then the strongest
numberof clusters is taken.
- nbstates
int: Number or random bath states to sample over.
- property order
int: Maximum size of the cluster.
- projected_bath_state
ndarray with shape (n,): Array with z-projections of the bath spins states.
- property pulses
Sequence: List-like object, containing the sequence of the instantaneous ideal control pulses.
Each item is
Pulseobject, containing the following attributes:which (array-like): Indexes of the central spins to be rotated by the pulse. Default is all.
x (float): Rotation angle of the central spin about x-axis in radians.
y (float): Rotation angle of the central spin about y-axis in radians.
z (float): Rotation angle of the central spin about z-axis in radians.
delay (float or ndarray): Delay before the pulse or array of delays with the same shape as time points.
Additionally, act as a container object for the pulses, applied to the bath.
The bath pulses can be accessed as items of the
Pulseobject, with name of the item corresponding to the name of the bath spin impacted, and the item corresponding to theBasePulseobject with attributes:x (float): Rotation angle of the central spin about x-axis in radians.
y (float): Rotation angle of the central spin about y-axis in radians.
z (float): Rotation angle of the central spin about z-axis in radians.
Examples:
>>> p = Pulse('x', 'pi') >>> print(p) Pulse((x: 3.14, y: 0.00, z: 0.00)) >>> pb = Pulse('x', 'pi', bath_names=['13C', '14C']) >>> print(pb) Pulse((x: 3.14, y: 0.00, z: 0.00), {13C: (x: 3.14, y: 0.00, z: 0.00), 14C: (x: 3.14, y: 0.00, z: 0.00)}) >>> print(pb['13C']) (x: 3.14, y: 0.00, z: 0.00)
If delay is not provided in all pulses, assumes even delay of CPMG sequence. If only some delays are provided, assumes 0 delay in the pulses without delay provided.
For the full list of properties, see
PulseandSequencedocumentations.
- property r_bath
float or array-like: Cutoff size of the spin bath. If
len(r_bath) > 1, uses different cutoff sizes for each of the central spins. The total bath then is the sum of all bath spins, that are close to at least one of the central spins.
- property r_dipole
float: Maximum connectivity distance.
- second_order
bool: True if add second order perturbation theory correction to the cluster Hamiltonian in conventional CCE. Relevant only for conventional CCE calculations.
- seed
int: Seed for random number generator, used in random bath states sampling.
- set_magnetic_field(magnetic_field=None)
Set magnetic field from either value of the magnetic field along z-direction or full magnetic field vector.
- Args:
magnetic_field (float or array-like): Magnetic field along z-axis.
OR
Array containing external magnetic field as (Bx, By, Bz). Default (0, 0, 0).
- set_zfs(D=None, E=0)
Set Zero Field Splitting of the central spin from longitudinal ZFS D and transverse ZFS E.
- Args:
- D (float or ndarray with shape (3, 3)): D (longitudinal splitting) parameter of central spin
in ZFS tensor of central spin in kHz.
OR
Total ZFS tensor. Default 0.
- E (float): E (transverse splitting) parameter of central spin in ZFS tensor of central spin in kHz.
Default 0. Ignored if
Dis None or tensor.
- timespace
timespace (ndarray with shape (n,)): Time points at which compute the desired property.
Reading the bath
Documentation for the Simulator.read_bath and Simulator.generate_clusters
method. These methods are called automatically on the initialization of the Simulator object
if the necessary keywords are provided. Otherwise they can also be called by themselves
to update the properties of the spin bath in Simulator object.
- Simulator.read_bath(bath=None, r_bath=None, skiprows=1, external_bath=None, hyperfine=None, types=None, error_range=None, ext_r_bath=None, imap=None, func_kw=None)
Read spin bath from the file or from the
BathArray.- Args:
bath (ndarray, BathArray or str): Either:
Instance of BathArray class;
ndarray with
dtype([('N', np.unicode_, 16), ('xyz', np.float64, (3,))])containing names of bath spins (same ones as stored in self.ntype) and positions of the spins in angstroms;the name of the xyz text file containing 4 cols: name of the bath spin and xyz coordinates in A.
- r_bath (float or array-like): Cutoff size of the spin bath. If
len(r_bath) > 1, uses different cutoff sizes for each of the central spins. The total bath then is the sum of all bath spins, that are close to at least one of the central spins.
- skiprows (int, optional): If
bathis name of the file, this argument gives number of rows to skip while reading the .xyz file (default 1).
- external_bath (BathArray, optional):
BathArray containing spins read from DFT output (see
pycce.io).- hyperfine (str, func, or Cube instance, optional):
This argument tells the code how to generate hyperfine couplings.
If (
hyperfine = Noneand all A in provided bath are 0) or (hyperfine = 'pd'), use point dipole approximation.Otherwise can be an instance of
Cubeobject, or callable with signature:func(array, *args, **kwargs)
where
arrayis array of the bath spins,
func_kw (dict): Additional keywords if for generating hyperfine couplings if
hyperfineis callable.- types (SpinDict): SpinDict or input to create one.
Contains either SpinTypes of the bath spins or tuples which will initialize those.
See
pycce.bath.SpinDictdocumentation for details.- error_range (float, optional): Maximum distance between positions in bath and external
bath to consider two positions the same (default 0.2).
- ext_r_bath (float, optional): Maximum distance from the central spins of the bath spins
for which to use the DFT positions.
- imap (InteractionMap): Instance of
InteractionMapclass, containing interaction tensors for bath spins. Each key of the
InteractionMapis a tuple with indexes of two bath spins. The value is the 3x3 tensor describing the interaction between two spins in a format:\[I^iJI^j = I^i_{x}J_{xx}I^j_{x} + I^i_{x}J_{xy}I^j_{y} ...\]
Note
For each bath spin pair without interaction tensor in
imap, coupling is approximated assuming magnetic point dipole–dipole interaction. Ifimap = Noneall interactions between bath spins are approximated in this way. Then interaction tensor between spins i and j is computed as:\[\mathbf{J}_{ij} = -\gamma_{i} \gamma_{j} \frac{\hbar^2}{4\pi \mu_0} \left[ \frac{3 \vec{r}_{ij} \otimes \vec{r}_{ij} - |r_{ij}|^2 I}{|r_{ij}|^5} \right]\]Where \(\gamma_{i}\) is gyromagnetic ratio of i spin, \(I\) is 3x3 identity matrix, and \(\vec{r}_{ij}\) is distance between two spins.
- Returns:
BathArray: The view of
Simulator.bathattribute, generated by the method.
- Simulator.generate_clusters(order=None, r_dipole=None, r_inner=0, strong=False, ignore=None, n_clusters=None)
Generate set of clusters used in CCE calculations.
The clusters are generated from the following procedure:
Each bath spin \(i\) forms a cluster of one.
Bath spins \(i\) and \(j\) form cluster of two if there is an edge between them (distance \(d_{ij} \le\)
r_dipole).Bath spins \(i\), \(j\), and \(j\) form a cluster of three if enough edges connect them (e.g., there are two edges \(ij\) and \(jk\))
And so on.
In general, we assume that spins \(\{i..n\}\) form clusters if they form a connected graph. Only clusters up to the size imposed by the
orderparameter (equal to CCE order) are included.- Args:
order (int): Maximum size of the cluster.
r_dipole (float): Maximum connectivity distance.
r_inner (float): Minimum connectivity distance.
- strong (bool):
True - generate only clusters with “strong” connectivity (all nodes should be interconnected). Default False.
- ignore (list or str, optional): If not None, includes the names of bath spins
which are ignored in the cluster generation.
- n_clusters (dict): Dictionary which contain maximum number of clusters of the given size.
Has the form
n_clusters = {order: number}, whereorderis the size of the cluster,numberis the maximum number of clusters with this size.If provided, sort the clusters by the strength of cluster interaction, Then the strongest
numberof clusters is taken.Strength of the cluster \(s\) is defined as an inverse of a sum of inverse pairwise interactions of the minimal cluster:
\[s = (\sum_{i<j\in C} \frac{r^3}{\gamma_i\gamma_j})^{-1}\]
Returns:
- dict: View of
Simulator.clusters.Simulator.clustersis a dictionary with keys corresponding to size of the cluster.
I.e.
Simulator.clusters[n]containsndarrayof shape (m, n), where m is the number of clusters of given size, n is the size of the cluster. Each row contains indexes of the bath spins included in the given cluster.
Calculate properties with simulator
Documentation for the Simulator.compute method -
the interface to run calculations with PyCCE.
- Simulator.compute(timespace, quantity='coherence', method='cce', **kwargs)
General function for computing properties with CCE.
The dynamics are simulated using the Hamiltonian:
\[\begin{split}&\hat H_S = \mathbf{SDS} + \mathbf{B\gamma}_{S}\mathbf{S} \\ &\hat H_{SB} = \sum_i \mathbf{S}\mathbf{A}_i\mathbf{I}_i \\ &\hat H_{B} = \sum_i{\mathbf{I}_i\mathbf{P}_i \mathbf{I}_i + \mathbf{B}\mathbf{\gamma}_i\mathbf{I}_i} + \sum_{i>j} \mathbf{I}_i\mathbf{J}_{ij}\mathbf{I}_j\end{split}\]Here \(\hat H_S\) is the central spin Hamiltonian with Zero Field splitting tensor \(\mathbf{D}\) and gyromagnetic ratio tensor \(\mathbf{\gamma_S} = \mu_S \mathbf{g}\) are read from
Simulator.zfsandSimulator.gyrorespectively.The \(\hat H_{SB}\) is the Hamiltonian describing interactions between central spin and the bath. The hyperfine coupling tensors \(\mathbf{A}_i\) are read from the
BathArraystored inSimulator.bath['A']. They can be generated using point dipole approximation or provided by the user (seeSimulator.read_bathfor details).The \(\hat H_{B}\) is the Hamiltonian describing interactions between the bath spins. The self interaction tensors \(\mathbf{P}_i\) are read from the
BathArraystored inSimulator.bath['Q']and have to be provided by the user.The gyromagnetic ratios \(\mathbf{\gamma}_i\) are read from the
BathArray.gyrosattribuite, which is generated from the properties of the types of bath spins, stored inBathArray.types. They can either be provided by user or read from thepycce.common_isotopesobject.The interaction tensors \(\mathbf{J}_{ij}\) are assumed from point dipole approximation or can be provided in
BathArray.imapattrubite.Note
The
computemethod takes two keyword arguments to determine which quantity to compute and how:method can take ‘cce’ or ‘gcce’ values, and determines which method to use - conventional or generalized CCE.
quantity can take ‘coherence’ or ‘noise’ values, and determines which quantity to compute - coherence function or autocorrelation function of the noise.
Each of the methods can be performed with monte carlo bath state sampling (if
nbstateskeyword is non zero) and with interlaced averaging (Ifinterlacedkeyword is set toTrue).Examples:
First set up Simulator object using random bath of 1000 13C nuclear spins.
>>> import pycce as pc >>> import numpy as np >>> atoms = pc.random_bath('13C', 100, number=2000, seed=10) # Random spin bath >>> calc = pc.Simulator(1, bath=atoms, r_bath=40, r_dipole=6, >>> order=2, D=2.88 * 1e6, # D of NV in GHz -> kHz >>> magnetic_field=500, pulses=1) >>> ts = np.linspace(0, 2, 101) # timesteps
We set magnetic field to 500 G along z-axis and chose 1 decoupling pulse (Hahn-echo) in this example. The zero field splitting is set to the one of NV center in diamond.
Run conventional CCE calculation at time points
timespaceto obtain coherence without second order effects:>>> calc.compute(ts)
This will call
Simulator.cce_coherencemethod with default keyword values.Compute the coherence conventional CCE coherence with second order interactions between bath spins:
>>> calc.compute(ts, second_order=True)
Compute the coherence with conventional CCE with bath state sampling (over 10 states):
>>> calc.compute(ts, nbstates=10)
Compute the coherence with generalized CCE:
>>> calc.compute(ts, method='gcce')
This will call
Simulator.gcce_dmmethod with default keyword values and obtain off diagonal element as \(\bra{0} \hat \rho_{C} \ket{1}\), where \(\hat \rho_{C}\) is the density matrix of the qubit.Compute the coherence with generalized CCE with bath state sampling (over 10 states):
>>> calc.compute(ts, method='gcce', nbstates=10)
Args:
timespace (ndarray with shape (n,)): Time points at which compute the desired property.
quantity (str): Which quantity to compute. Case insensitive.
Possible values:
‘coherence’: compute coherence function.
‘noise’: compute noise autocorrelation function.
method (str): Which implementation of CCE to use. Case insensitive.
Possible values:
‘cce’: conventional CCE, where interactions are mapped on 2 level pseudospin.
‘gcce’: Generalized CCE where central spin is included in each cluster.
- magnetic_field (ndarray with shape (3,) or callable): Magnetic field vector of form (Bx, By, Bz)
or callable with signature
magnetic_field(pos), whereposis an array with shape (3,) with the position of the spin.Default is None. Overrides
Simulator.magnetic_fieldif provided.
pulses (list or int or Sequence): Number of pulses in CPMG sequence.
OR
Sequence of the instantaneous ideal control pulses. It can be provided as an instance of
Sequenceclass or a list withPulseobjects. (See documentation for pycce.Sequence).pulsescan be provided as a list with tuples or dictionaries, each tuple or dictionary is used to initializePulseclass instance.For example, for only central spin pulses the
pulsesargument can be provided as a list of tuples, containing:axis the rotation is about;
angle of rotation;
(optional) Time before the pulse. Can be as fixed, as well as varied. If varied, it should be provided as an array with the same length as
timespace.
E.g. for Hahn-Echo the
pulsescan be defined as[('x', np.pi)]or[('x', np.pi, timespace / 2)].Note
If delay is not provided in all pulses, assumes even delay of CPMG sequence. If only some delays are provided, assumes
delay = 0in the pulses without delay.Then total experiment is assumed to be:
tau – pulse – 2tau – pulse – … – 2tau – pulse – tau
Where tau is the delay between pulses.
The sum of delays at each time point should be less or equal to the total time of the experiment at the same time point, provided in
timespaceargument.Warning
In conventional CCE calculations, only \(pi\) pulses on the central spin are allowed.
In the calculations of noise autocorrelation this parameter is ignored.
Default is None. Overrides``Simulator.pulses`` if provided.
- i (int or ndarray with shape (2s+1, ) or callable): Used in gCCE calculations.
Along with
jparameter indicates which density matrix element to compute with gCCE as:\[L=\bra{i}\hat \rho \ket{j}\]By default is equal to \(R\ket{0}\) state of the
.centerwhere \(R\) is a product of all rotations applied in the pulse sequence. Can be set as a vector in \(S_z\) basis, the index of the central spin Hamiltonian eigenstate, or as a callable with call signaturei(dm), wheredmis a density matrix of the central spin. If callable,jparameter is ignored.- j (int or ndarray with shape (2s+1, ) or callable): Used in gCCE calculations.
Along with
iparameter indicates which density matrix element to compute.By default is equal to \(R\ket{1}\) state of the
.centerwhere \(R\) is a product of all rotations applied in the pulse sequence. Can be set as a vector in \(S_z\) basis, the index of the central spin Hamiltonian eigenstate, or as a callable with call signaturej(dm), wheredmis a density matrix of the central spin. If callable,iparameter is ignored.- as_delay (bool): True if time points are delay between pulses (for equispaced pulses),
False if time points are total time. Ignored in gCCE if
pulsescontains the time fractions. Conventional CCE calculations do not support custom time fractions.Default is False.
- interlaced (bool): True if use hybrid CCE approach - for each cluster
sample over states of the supercluster.
Default is False.
- state (ndarray with shape (2s+1,)):
Initial state of the central spin, used in gCCE and noise autocorrelation calculations.
Defaults to \(\frac{1}{N}(\ket{0} + \ket{1})\) if not set.
- bath_state (array-like):
List of bath spin states. If
len(shape) == 1, contains \(I_z\) projections of \(I_z\) eigenstates. Otherwise, contains array of initial density matrices of bath spins.Default is None. If not set, the code assumes completely random spin bath (density matrix of each nuclear spin is proportional to identity, \(\hat {\mathbb{1}}/N\)).
nbstates (int): Number or random bath states to sample over.
If provided, sampling of random states is carried and
bath_statesvalues are ignored.Default is 0.
seed (int): Seed for random number generator, used in random bath states sampling.
Default is None.
- masked (bool):
True if mask numerically unstable points (with coherence > 1) in the averaging over bath states.
Note
It is up to user to check whether the possible instability is due to numerical error or unphysical assumptions of the calculations.
Default is True for coherence calculations, False for noise calculations.
- parallel_states (bool):
True if to use MPI to parallelize the calculations of density matrix equally over present mpi processes for random bath state sampling calculations.
Compared to
parallelkeyword, when this argument is True each process is given a fraction of random bath states. This makes the implementation faster. Works best when the number of bath states is divisible by the number of processes,nbstates % size == 0.Default is False.
- second_order (bool):
True if add second order perturbation theory correction to the cluster Hamiltonian in conventional CCE. Relevant only for conventional CCE calculations.
If set to True sets the qubit states as eigenstates of central spin Hamiltonian from the following procedure. If qubit states are provided as vectors in \(S_z\) basis, for each qubit state compute the fidelity of the qubit state and all eigenstates of the central spin and chose the one with fidelity higher than
level_confidence. If such state is not found, raises an error.Warning
Second order corrections are not implemented as mean field.
I.e., setting
second_order=Trueandnbstates != 0leads to the calculation, when mean field effect is accounted only from dipolar interactions within the bath.Default is False.
- level_confidence (float): Maximum fidelity of the qubit state to be considered eigenstate of the
central spin Hamiltonian.
Default is 0.95.
- direct (bool):
True if use direct approach (requires way more memory but might be more numerically stable). False if use memory efficient approach.
Default is False.
- parallel (bool):
True if parallelize calculation of cluster contributions over different mpi processes.
Default is False.
- fulldm (bool):
Used in gCCE. True if return full density matrix of the central spin. False if only return the computed property.
Default is False.
Returns:
ndarray: Computed property.
Pulse sequences
Documentation of the Pulse and Sequence classes, used in definition of the complicated
pulse sequences.
- class pycce.run.pulses.BasePulse(x=None, y=None, z=None)
Base class for Pulse.
- Args:
x (float): Rotation angle about x-axis in radians. y (float): Rotation angle about y-axis in radians. z (float): Rotation angle about z-axis in radians.
- check_flip()
Check if the rotation is about single cartesian axis by an angle \(\pi\).
- property flip
bool: True if the angle == pi.
- generate_rotation(spinvec, spin_half=False)
Generate rotation matrix given spin vector.
- Args:
spinvec (ndarray with shape (3, n, n)): Spin vector. spin_half (bool): True if spin vector is for a spin-1/2. Default is False.
- Returns:
ndarray with shape (n, n): Rotation operator.
- indices = array([0, 1, 2])
- property naxes
int: Number of axes the rotation is defined for.
- set_angle(axis, angle)
Set rotation angle
angleabout axisaxis.- Args:
axis (str): Axis of the rotation. angle (float): Rotation angle in radians.
Returns:
- property x
float: Angle of rotation of the spin about x axis in rad.
- property y
float: Angle of rotation of the spin about y axis in rad.
- property z
float: Angle of rotation of the spin about z axis in rad.
- class pycce.run.pulses.Pulse(axis=None, angle=None, delay=None, which=None, bath_names=None, bath_axes=None, bath_angles=None, **kwargs)
Class containing properties of each control pulse, applied to the system.
The properties of the pulse, applied on the central spin(s) can be accessed as attributes, while bath spin pulses can be acessed as elements of the
Pulseinstance.Args:
axis (str): Axis of rotation of the central spin. Can be ‘x’, ‘y’, or ‘z’. Default is None.
- angle (float or str): Angle of rotation of central spin. Can be provided in rad, or as a string, containing
fraction of pi:
'pi','pi/2','2*pi'etc. Default is None.- delay (float or ndarray): Delay before the pulse or array of delays with the same shape as time points.
Default is None.
- which (array-like): Indexes of the central spins to be rotated by the pulse. Default is all.
Separated indexes are supported only if qubit states are provided separately for all center spins.
- bath_names (str or array-like of str): Name or array of names of bath spin types, impacted by the bath pulse.
Default is None.
- bath_axes (str or array-like of str): Axis of rotation or array of axes of the bath spins.
Default is None. If
bath_namesis provided, butbath_axesandbath_anglesare not, assumes the same axis and angle as the one of the central spin
bath_angles (float or str or array-like): Angle of rotation or array of axes of rotations of the bath spins.
x (float): Rotation angle of the central spin about x-axis in radians.
y (float): Rotation angle of the central spin about y-axis in radians.
z (float): Rotation angle of the central spin about z-axis in radians.
Examples:
>>> Pulse('x', 'pi') Pulse((x: 3.14, y: 0.00, z: 0.00)) >>> Pulse('x', 'pi', bath_names=['13C', '14C']) Pulse((x: 3.14, y: 0.00, z: 0.00), {13C: (x: 3.14, y: 0.00, z: 0.00), 14C: (x: 3.14, y: 0.00, z: 0.00)}) >>> import numpy as np >>> p = Pulse('x', 'pi', delay=np.linspace(0, 1, 5), bath_names=['13C', '14C'], >>> bath_axes='x', bath_angles='pi/2') >>> print(p) Pulse((x: 3.14, y: 0.00, z: 0.00), {13C: (x: 1.57, y: 0.00, z: 0.00), 14C: (x: 1.57, y: 0.00, z: 0.00)}, t = [0. 0.25 0.5 0.75 1. ]) >>> print(p['13C']) (x: 1.57, y: 0.00, z: 0.00)
- bath_angles
ndarray: Array of angles of rotation of the bath spins.
- bath_axes
ndarray: Array of axes of rotation of the bath spins.
- bath_names
ndarray: Array of names of bath spin types, impacted by the bath pulse.
- property delay
ndarray or float: Delay or array of delays before the pulse.
- rotation
ndarray: Matrix representation of the pulse for the given cluster. Generated by
Runobject.
- which
iterable: Indexes of the central spins to be rotated by the pulse.
- class pycce.run.pulses.Sequence(t=None)
List-like object, which contains the sequence of the pulses.
Each element is a
Pulseinstance, which can be generated from either the tuple with positional arguments or from the dictionary, or set manually.If delay is not provided in all pulses in the sequence, assume equispaced pulse sequence:
t - pulse - 2t - pulse - 2t - … - pulse - t
If only some delays are provided, assumes 0 delay in the pulses without delay provided.
- Examples:
>>> import numpy as np >>> Sequence([('x', np.pi, 0), >>> {'axis': 'y', 'angle': 'pi', 'delay': np.linspace(0, 1, 3), 'bath_names': '13C'}, >>> Pulse('x', 'pi', 1)]) [Pulse((x, 3.14), t = 0), Pulse((y, 3.14), {13C: (y, 3.14)}, t = [0. 0.5 1. ]), Pulse((x, 3.14), t = 1)]
- append(item)
S.append(value) – append value to the end of the sequence