Skip to content

Operators

Davide Candoli edited this page Oct 1, 2020 · 50 revisions

Operators is the package which provides the classes for the representation of operators in finite-dimensional Hilbert spaces (as is the case of spin systems). Currently, these classes are:

  • Operator
  • Density_Matrix(Operator)
  • Observable(Operator)

Operator is to be intended as the mathematical object without any physical meaning, while the instances of its subclasses Density_Matrix and Observable embody the physical objects indicated by their names: respectively, the state of the system and its measurable properties. All of them possess an attribute called matrix which expresses the matrix representation of the operator in the assumed basis set.

Class Operator

Operators are linear applications which transform vectors inside a given linear space. For the purposes of our simulation, where the systems under study are nuclear spins, we consider operators acting in finite-dimensional Hilbert spaces. The main advantage of finite-dimensional operators is that they admit a matrix representation, which depends on the chosen basis set of vectors.

Attributes

  • matrix: numpy.ndarray

    Square array of complex numbers providing the matrix representation of the operator in the desired basis set.

Methods

  • Operator(x)

    Constructs an instance of Operator.

    Parameters

    • x: either int or numpy.ndarray

      When x is a positive integer, the constructor initialises matrix as an x-dimensional identity array.

      When x is an array, it is assigned directly to matrix. In this case, the constructor checks that the given object is a square array, and raises an appropriate error if it is not.

    Returns

    The initialised Operator object.

    Raises

    IndexError, when the passed array x is not a 2D square array.

  • dimension()

    Returns the dimension of the matrix, i.e. the dimensionality of the Hilbert space where the operator acts.

  • (o_left)+(o_right)

    Returns the sum of two Operator objects.

    Parameters

    • o_left,o_right: Operator

      Addends of the sum.

    Returns

    A new Operator object initialised with the sum of the addends' matrices.

  • (o_left)-(o_right)

    Returns the difference of two Operator objects.

    Parameters

    • o_left,o_right: Operator

      Minuend and subtrahend in the difference, respectively.

    Returns

    A new Operator object initialised with the difference of the arguments' matrices.

  • (o)*(a) or (a)*(o)

    Returns the Operator resulting either from: (1) the product of two Operator objects; (2) the multiplication of an Operator by a scalar.

    Parameters

    • o: Operator
    • a: (1) Operator; (2) complex number.

    Returns

    A new Operator object initialised either with: (1) the product between the matrices of o and a, in reading order; (2) the matrix of o multiplied by the scalar a.

  • (o)/(c)

    Returns the operator divided by a complex number.

    Parameters

    • o: Operator
    • c: complex number.

    Returns

    A new Operator object initialised with the division of the matrix of o by the quantity c.

    Raises

    ZeroDivisionError, when c is cast to 0.

  • (o)**(exponent)

    Returns the operator raised to the power of exponent.

    Parameters

    • exponent: int

    Returns

    A new Operator object initialised with the matrix of o raised to the power of exponent.

  • exp()

    Returns a new Operator object representing the exponential of the operator.

    The program exploits the Padè approximation for the calculation of matrix exponentials.

  • diagonalisation()

    Diagonalises the operator, returning its eigenvalues and eigenvectors.

    Returns

    • [0]: An array listing the eigenvalues of the Operator's matrix;

    • [1]: An Operator object whose matrix columns are the eigenvectors of the considered operator, appearing in the same order as the corresponding eigenvalues in the first output.

  • sim_trans(change_of_basis_operator, exp=False)

    Returns the Operator resulting from the application of the similarity transformation P-1MP to the Operator M which owns the method.

    Parameters

    • change_of_basis_operator: Operator

      Operator which enters expression P-1MP as P.

    • exp: bool

      Specifies whether the change of basis is performed using as P the change_of_basis_operator by itself (exp=False) or its exponential change_of_basis_operator.exp() (exp=True).

      Default value is set to False.

    Returns

    A new Operator object representing the outcome of the similarity transformation.

  • trace()

    Returns the trace of the operator (which is a complex number).

  • dagger()

    Returns a new Operator object initialised with the adjoint (complex conjugate transposed) of the matrix of the owner object.

  • changed_picture(h_change_of_picture, time, invert=False)

    Casts the operator either in a new picture generated by the Operator h_change_of_picture or back to the Schroedinger picture, according to the parameter invert.

    Parameters

    • h_change_of_picture: Operator

      Operator which generates the change to the new picture. Typically, this operator is a term of the Hamiltonian (measured in MHz).

    • time: float

      Instant of evaluation of the operator in the new picture, expressed in microseconds.

    • invert: bool

      When it is False, the owner Operator object is assumed to be expressed in the Schroedinger picture and is converted into the new one.

      When it is True, the owner object is thought in the new picture and the opposite operation is performed.

    Returns

    A new Operator object equivalent to the owner object but expressed in a different picture.

  • hermitianity()

    Returns a boolean which expresses whether the operator is equal to its adjoint, comparing their matrices element-wise with a relative error tolerance of 10-10.

    Returns

    True, when hermitianity is verified.

    False, when hermitianity is not verified.

  • unit_trace()

    Returns a boolean which expresses whether the trace of the operator is equal to 1, within a relative error tolerance of 10-10.

    Returns

    True, when unit trace is verified.

    False, when unit trace is not verified.

  • positivity()

    Returns a boolean which expresses whether the operator is a positive operator, i.e. its matrix has only non-negative eigenvalues (taking the 0 with an error margin of 10-10).

    Returns

    True, when positivity is verified.

    False, when positivity is not verified.

  • cast_to_density_matrix()

    Returns an object of the class Density_Matrix initialised with the matrix of the owner Operator object, if all the properties of a density matrix are satisfied.

    Raises

    ValueError, when any of the three properties of density matrices is missing in the matrix of the owner object. Also, an error message explaining which properties are not satisfied is shown.

  • cast_to_observable()

    Returns an object of the class Observable initialised with the matrix of the owner Operator object, if it is hermitian.

    Raises

    ValueError, when the owner Operator object is not hermitian.

  • free_evolution(stat_hamiltonian, time)

    Tries to cast the operator into the type Density_Matrix (using method cast_to_density_matrix), and in case of success returns this object evolved through the time time under the effect of stat_hamiltonian, calling the method of Density_Matrix with the same name.

    See the description of Density_Matrix.free_evolution below for details.

  • expectation_value(density_matrix)

    Tries to cast the Operator into the type Observable (using method cast_to_observable), and in case of success returns its expectation value in the state represented by density_matrix, calling the method of Observable with the same name.

    See the description of Observable.expectation_value below for details.

Class Density_Matrix(Operator)

A density matrix is a formal representation of the state of a quantum system which assigns a unique operator to each state.

Density matrices associated to a well-defined (pure) state of the system are equivalent to the projector over the subspace generated by the vector describing that state in Dirac's notation.

Density matrix formalism is particularly suitable for the representation of mixed states, which encode the (classical) distribution of the states in an ensemble of identical systems.

The axiomatic definition of density matrix is based on the following properties:

  1. Hermitianity
  2. Unit trace
  3. Positivity

Methods

  • Density_Matrix(x)

    Constructs an instance of Density_Matrix.

    Parameters

    • x: either int or ndarray.

      When x is an integer, the constructor initialises matrix as an x-dimensional maximally entangled density matrix (identity(x)/x).

      When x is an array, it is assigned directly to matrix. In this case, the constructor checks that the given object is a square array, and raises appropriate errors if it is not. Also, the defining properties of density matrices are checked and errors are raised if any of them is not satisfied.

    Returns

    The initialised Density_Matrix object.

    Raises

    • ValueError, when x is an array but some of the three definining properties (hermitianity, unit trace and positivity) are not verified. Also, an error message displaying which properties are missing is shown;
    • IndexError, when the passed array x is not a 2D square array.
  • free_evolution(static_hamiltonian, time)

    Returns the density matrix represented by the owner object evolved through a time interval time under the action of the stationary Hamiltonian static_hamiltonian.

    Parameters

    • static_hamiltonian: Observable or in general a hermitian Operator

      Time-independent Hamiltonian of the system, in MHz.

    • time: float

      Duration of the evolution, expressed in microseconds.

    Returns

    A Density_Matrix object representing the evolved state.

Class Observable(Operator)

Observables are the measurable properties of a physical system, and in quantum mechanics are represented by hermitian operators.

The expectation value of an observable of a quantum system in a certain state is conventionally computed as the bra-operator-ket product of the observable's operator in between the state vector. Alternatively, one can exploit the density matrix representation of the state and find the expectation value as the trace of the product of the density matrix and the observable's operator.

Methods

  • Observable(x)

    Constructs an instance of Observable.

    Parameters

    • x: either int or ndarray

      When x is an integer, the constructor initialises matrix as an x-dimensional identity matrix.

      When x is an array, it is assigned directly to matrix. In this case, the constructor checks that the given object is a hermitian square matrix, and raises appropriate errors if it is not.

    Returns

    The initialised Observable object.

    Raises

    • ValueError, when x is a square array but it is not hermitian;
    • IndexError, when the passed array x is not a 2D square array.
  • expectation_value(density_matrix)

    Returns the expectation value of the observable calculated in the state represented by density_matrix.

    Parameters

    • density_matrix: Density_Matrix (or any Operator which can be cast to Density_Matrix)

      State of the system.

    Returns

    In general, a complex number representing the expectation value of the observable for the given density matrix. When the imaginary part of this number is smaller than 10-10 (in absolute value), only the real part is retained.

Other functions

  • random_operator(d)

    Returns a randomly generated operator object of dimensions d.

    Parameters

    • d: int

      Dimensions of the Operator to be generated.

    Returns

    An Operator object whose matrix is d-dimensional and has random complex elements with real and imaginary parts in the half-open interval [-10., 10.).

  • random_observable(d)

    Returns a randomly generated observable of dimensions d.

    Parameters

    • d: int

      Dimensions of the Observable to be generated.

    Returns

    An Observable object whose matrix is d-dimensional and has random complex elements with real and imaginary parts in the half-open interval [-10., 10.).

  • random_density_matrix(d)

    Returns a randomly generated density matrix of dimensions d.

    Parameters

    • d: int

      Dimensions of the Density_Matrix to be generated.

    Returns

    A Density_Matrix object whose matrix is d-dimensional and has randomly generated eigenvalues.

  • commutator(A, B)

    Returns the commutator of operators A and B. The commutator of two operators is defined as

    Parameters

    • A, B: Operator

    Returns

    An Operator representing the commutator of A and B.

  • magnus_expansion_1st_term(h, time_step)

    Returns the 1st order term of the Magnus expansion of the passed time-dependent Hamiltonian. The mathematical formula of this term is

    Parameters

    • h: np.ndarray of Observable

      Time-dependent Hamiltonian (expressed in MHz). Technically, an array of Observable objects which correspond to the Hamiltonian evaluated at successive instants of time. The start and end points of the array are taken as the extremes of integration 0 and t;

    • time_step: float

      Time difference between adjacent points of the array h, expressed in microseconds.

    Returns

    An adimensional Operator object resulting from the integral of h over the whole array size, multiplied by -1j*2*math.pi. The integration is carried out through the traditional trapezoidal rule.

  • magnus_expansion_2nd_term(h, time_step)

    Returns the 2nd order term of the Magnus expansion of the passed time-dependent Hamiltonian. The mathematical expression of this term is

    Parameters

    • h: np.ndarray of Observable

      Time-dependent Hamiltonian (expressed in MHz). Technically, an array of Observable objects which correspond to the Hamiltonian evaluated at successive instants of time. The start and end points of the array are taken as the extremes of integration 0 and t;

    • time_step: float

      Time difference between adjacent points of the array h, expressed in microseconds.

    Returns

    An adimensional Operator object representing the 2nd order Magnus term of the Hamiltonian, calculated applying Commutator to the elements in h and summing them.

  • magnus_expansion_3rd_term(h, time_step)

    Returns the 3rd order term of the Magnus expansion of the passed time-dependent Hamiltonian. The mathematical expression of this term is

    Parameters

    • h: np.ndarray of Observable

      Time-dependent Hamiltonian (expressed in MHz). Technically, an array of Observable objects which correspond to the Hamiltonian evaluated at successive instants of time. The start and end points of the array are taken as the extremes of integration 0 and t;

    • time_step: float

      Time difference between adjacent points of the array h, expressed in microseconds.

    Returns

    An adimensional Operator object representing the 3rd order Magnus term of the Hamiltonian, calculated applying nested Commutator to the elements in h and summing them.

  • canonical_density_matrix(hamiltonian, temperature)

    Returns the density matrix of a canonical ensemble of quantum systems at thermal equilibrium, i.e. the canonical density matrix calculated through the formula

    Parameters

    • hamiltonian: Operator

      Hamiltonian of the system at equilibrium, expressed in MHz.

    • temperature: positive float

      Temperature of the system in kelvin.

    Returns

    A Density_Matrix object which embodies the canonical density matrix.

    Raises

    • ValueError, if temperature is negative or equal to zero.
Clone this wiki locally