Home Reference Source
import QubitOperator from 'projectq/src/ops/qubitoperator.js'
public class | source

QubitOperator

Constructor Summary

Public Constructor
public

constructor(coefficient: number | Complex, term: Array<Array> | string)

Member Summary

Public Members
public

terms: {}

Method Summary

Public Methods
public

add(addend: Complex | number | QubitOperator): QubitOperator

public

compress(absTolerance: number)

Eliminates all terms with coefficients close to zero and removes imaginary parts of coefficients that are close to zero.

public

return copy of current qubit operator

public

div(divisor: *): *

public

iadd(addend: Complex | number | QubitOperator): QubitOperator

in-Place add

public

idiv(divisor: Complex | number | QubitOperator): QubitOperator

in-Place dived by divisor

public

imul(multiplier: Complex | number | QubitOperator): *

In-place multiply (*=) terms with scalar or QubitOperator.

public

isClose(other: QubitOperator, realTolerance: number, absTolerance: number): boolean

Returns true if other (QubitOperator) is close to this.

public

isub(subtrahend: Complex | number | QubitOperator): QubitOperator

in-Place subtract

public

mul(multiplier: Complex | number | QubitOperator): QubitOperator

Return self * multiplier for a scalar, or a QubitOperator.

public

return negative of current qubit operator

public

sub(subtrahend: *): *

public

string description of current qubit operator

Public Constructors

public constructor(coefficient: number | Complex, term: Array<Array> | string) source

Params:

NameTypeAttributeDescription
coefficient number | Complex

The coefficient of the first term of this QubitOperator. Default is 1.0.

term Array<Array> | string

(optional, empy array, a array of arrays, or a string): 1) Default is None which means there are no terms in the QubitOperator hence it is the "zero" Operator 2) An empty tuple means there are no non-trivial Pauli operators acting on the qubits hence only identities with a coefficient (which by default is 1.0). 3) A sorted tuple of tuples. The first element of each tuple is an integer indicating the qubit on which a non-trivial local operator acts, starting from zero. The second element of each tuple is a string, either 'X', 'Y' or 'Z', indicating which local operator acts on that qubit. 4) A string of the form 'X0 Z2 Y5', indicating an X on qubit 0, Z on qubit 2, and Y on qubit 5. The string should be sorted by the qubit number. '' is the identity.

Throw:

QubitOperatorError

Invalid operators provided to QubitOperator.

Example:


    

Public Members

public terms: {} source

Public Methods

public add(addend: Complex | number | QubitOperator): QubitOperator source

Params:

NameTypeAttributeDescription
addend Complex | number | QubitOperator

Return:

QubitOperator

public compress(absTolerance: number) source

Eliminates all terms with coefficients close to zero and removes imaginary parts of coefficients that are close to zero.

Params:

NameTypeAttributeDescription
absTolerance number

Absolute tolerance, must be at least 0.0

public copy(): QubitOperator source

return copy of current qubit operator

Return:

QubitOperator

public div(divisor: *): * source

Params:

NameTypeAttributeDescription
divisor *

Return:

*

public iadd(addend: Complex | number | QubitOperator): QubitOperator source

in-Place add

Params:

NameTypeAttributeDescription
addend Complex | number | QubitOperator

Return:

QubitOperator

public idiv(divisor: Complex | number | QubitOperator): QubitOperator source

in-Place dived by divisor

Params:

NameTypeAttributeDescription
divisor Complex | number | QubitOperator

Return:

QubitOperator

public imul(multiplier: Complex | number | QubitOperator): * source

In-place multiply (*=) terms with scalar or QubitOperator.

Params:

NameTypeAttributeDescription
multiplier Complex | number | QubitOperator

Return:

*

public isClose(other: QubitOperator, realTolerance: number, absTolerance: number): boolean source

Returns true if other (QubitOperator) is close to this.

Comparison is done for each term individually. Return true if the difference between each term in self and other is less than the relative tolerance w.r.t. either other or self (symmetric test) or if the difference is less than the absolute tolerance.

Params:

NameTypeAttributeDescription
other QubitOperator

QubitOperator to compare against.

realTolerance number

Relative tolerance, must be greater than 0.0

absTolerance number

Absolute tolerance, must be at least 0.0

Return:

boolean

public isub(subtrahend: Complex | number | QubitOperator): QubitOperator source

in-Place subtract

Params:

NameTypeAttributeDescription
subtrahend Complex | number | QubitOperator

Return:

QubitOperator

public mul(multiplier: Complex | number | QubitOperator): QubitOperator source

Return self * multiplier for a scalar, or a QubitOperator.

Params:

NameTypeAttributeDescription
multiplier Complex | number | QubitOperator

A scalar, or a QubitOperator.

Return:

QubitOperator

Throw:

Error

Invalid type cannot be multiply with QubitOperator.

public negative(): QubitOperator source

return negative of current qubit operator

Return:

QubitOperator

public sub(subtrahend: *): * source

Params:

NameTypeAttributeDescription
subtrahend *

Return:

*

public toString(): string source

string description of current qubit operator

Return:

string