Cheat

Cheated functions in PyQuest-cffi

Provides access to the wavefunction or density matrix.

pyquest_cffi.cheat.measurement Measurement function in PyQuest-cffi
pyquest_cffi.cheat.initialization Initialisation objects in PyQuest-cffi

Measurement

Measurement function in PyQuest-cffi

pyquest_cffi.cheat.measurement.basis_state_to_index(basis_state: Union[int, Sequence[int]], endianness: str = 'little') → int[source]

Convert a basis state to index

Converts a up/down representation of a basis state to the index of the basis depending on the Endian convention of the system

Parameters:
  • basis_state – a sequence of 0 and one representing the qubit basis stae
  • endianness – ‘big’ or ‘little’ corresponding to the least significant bit being stored in the last or first element of the array respectively In little endianness the qubit 0 corresponds to the bit at index 0 of basis_state the qubit 1 to the bit at index 1 and so on. Note however, that when initialising basis_state = np.array([0, 1, 1, 0,…]) the sequence of bits in the list needs to be inverted form the binary representation. For example 4 which will be 100 in binary would correspond to basis_state= np.array([0,0,1])
Returns:

int

class pyquest_cffi.cheat.measurement.calcDensityInnerProduct(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate the Frobenius inner matrix product between two density matrix quregs

Parameters:
  • qureg1 – first quantum register
  • qureg2 – first quantum register
call_interactive(qureg1: Qureg, qureg2: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg1 – first quantum register
  • qureg2 – first quantum register
Returns:

float

Raises:
  • RuntimeError – Qureg1 has to be a density matrix qureg but wavefunction qureg was used
  • RuntimeError – Qureg2 has to be a density matrix qureg but wavefunction qureg was used
class pyquest_cffi.cheat.measurement.calcExpecDiagonalOp(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Computes the expected value of the diagonal operator op for state qureg

Since op is not necessarily Hermitian, the expected value may be a complex number.

Parameters:
  • qureg – quantum register that is measured
  • operator – operator acting on a certain number of qubits (operator[0]: int) and in a certain QuEST environment (operator[1]: tquestenv)
call_interactive(qureg: Qureg, operator: Tuple[int, QuESTEnv]) → complex[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register that is measured
  • operator – operator acting on a certain number of qubits (operator[0]: int) and in a certain QuEST environment (operator[1]: tquestenv)
Returns:

float

class pyquest_cffi.cheat.measurement.calcExpecPauliHamil(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the expectation value of a product of Pauli operators

Parameters:
  • qureg – quantum register that is measured
  • pauli_hamil – a PauliHamil created with createPauliHamil()
  • workspace – A qureg of same type and size as input qureg, is used as temporary work qureg
call_interactive(qureg: Qureg, pauli_hamil: PauliHamil, workspace: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register that is measured
  • pauli_hamil – a PauliHamil created with createPauliHamil()
  • workspace – A qureg of same type and size as input qureg, is used as temporary work qureg
Returns:

float

Raises:

RuntimeError – Qureg and PauliHamil must be defined for the same number of qubits

class pyquest_cffi.cheat.measurement.calcExpecPauliProd(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the expectation value of a product of Pauli operators

A product of Pauli operators (including Identity) is measured. For each qubit in qubits a Pauli operator must be given in each sum term (can be identity)

Parameters:
  • qureg – quantum register that is measured
  • qubits – target qubits
  • paulis – List of Pauli operators in the product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • workspace – A qureg of same type and size as input qureg, is used as temporary work qureg
call_interactive(qureg: Qureg, qubits: Sequence[int], paulis: Sequence[Sequence[int]], workspace: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register that is measured
  • qubits – target qubits
  • paulis – List of Pauli operators in the product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • workspace – A qureg of same type and size as input qureg, is used as temporary work qureg
Returns:

float

Raises:

RuntimeError – Need the number of qubits and pauli products to be equal

class pyquest_cffi.cheat.measurement.calcExpecPauliSum(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the expectation value of a sum of products of Pauli operators

A sum of products of Pauli operators (including Identity) is measured. For each qubit a Pauli operator must be given in each sum term (can be identity)

Parameters:
  • qureg – quantum register that is measured
  • paulis – List of Lists of Pauli operators in each product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • coefficients – coefficients of the sum
  • workspace – A qureg of same type and size as input qureg, is used as temporary work qureg
call_interactive(qureg: Qureg, paulis: Sequence[Sequence[int]], coefficients: Sequence[float], workspace: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register that is measured
  • paulis – List of Lists of Pauli operators in each product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • coefficients – coefficients of the sum
  • workspace – A qureg of same type and size as input qureg, is used as temporary work qureg
Returns:

float

class pyquest_cffi.cheat.measurement.calcFidelity(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate Fidelity of a quantum register

Determine the fidelity of a qureg (wavefunction \(\left| \psi \right\rangle\)
or density matrix \(\rho\))

with respect to a reference_qureg of a wavefunction \(\left| \psi_{ref} \right\rangle\) Fidelity is defined as:

\[\begin{split}\mathcal{F} &= \left\langle \psi | \psi_{ref} \right \rangle \\ \mathcal{F} &= \left\langle \psi_{ref}| \rho | \psi_{ref} \right \rangle\end{split}\]
Parameters:
  • qureg – a qureg containing a wavefunction or a density matrix
  • qureg_reference – a qureg containing a wavefunction
  • readout – the readout register for static compilation
call_interactive(qureg: Qureg, qureg_reference: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction or a density matrix
  • qureg_reference – a qureg containing a wavefunction
Returns:

float

Raises:

RuntimeError – Reference qureg has to be a wavefunction qureg but density matrix qureg was used

class pyquest_cffi.cheat.measurement.calcHilbertSchmidtDistance(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate the Hilbert-Schmidt distance between two density matrix quregs

Parameters:
  • qureg1 – first quantum register
  • qureg2 – first quantum register
call_interactive(qureg1: Qureg, qureg2: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg1 – first quantum register
  • qureg2 – first quantum register
Returns:

float

class pyquest_cffi.cheat.measurement.calcInnerProduct(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate the inner-product/overlap of two wavefunction quregs

Inner product defined as: .. math:

\left\langle \psi_{qureg1} | \psi_{qureg2} \right \rangle
Parameters:
  • qureg1 – a qureg containing a wavefunction
  • qureg2 – a qureg containing a wavefunction
  • readout – the readout register for static compilation
call_interactive(qureg1: Qureg, qureg2: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg1 – a qureg containing a wavefunction
  • qureg2 – a qureg containing a wavefunction
Returns:

float

Raises:
  • RuntimeError – Qureg1 has to be a wavefunction qureg but density matrix qureg was used
  • RuntimeError – Qureg2 has to be a wavefunction qureg but density matrix qureg was used
class pyquest_cffi.cheat.measurement.calcProbOfOutcome(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate the probability that qubit #qubit of qureg is measured in state outcome

Parameters:
  • qureg – a qureg containing a wavefunction or density matrix
  • qubit – the index of the qubit for which the probability is determined
  • outcome – the outcome of the measurement
  • readout – the readout register for static compilation
call_interactive(qureg: Qureg, qubit: int, outcome: int) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction or density matrix
  • qubit – the index of the qubit for which the probability is determined
  • outcome – the outcome of the measurement
Returns:

float

class pyquest_cffi.cheat.measurement.calcPurity(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate the purity of a density matrix in qureg

Purity defined as: .. math:

\mathcal{Tr}\left(\rho^2\right)
Parameters:
  • qureg – a qureg containing a density matrix
  • readout – the readout register for static compilation
call_interactive(qureg: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a density matrix
Returns:float
Raises:RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used
class pyquest_cffi.cheat.measurement.calcTotalProb(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Calculate total probability

Check physicality of system by calculating probability of system to be in any state. In other words check that trace of density matrix or norm of state vector is one.

Parameters:
  • qureg – a qureg containing a density matrix or wavefunction
  • readout – the readout register for static compilation
call_interactive(qureg: Qureg) → float[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a density matrix or wavefunction
Returns:float
class pyquest_cffi.cheat.measurement.getAbsoluteValSquaredatIndex(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the absulute value squared of a wavefunction/state vector in a quantum register at index

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int or as a sequence of 0 and 1 referencing the corresponding basis state
call_interactive(qureg: Qureg, index: Union[int, Sequence[int]]) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int or as a sequence of 0 and 1 referencing the corresponding basis state
Returns:

float

Raises:

RuntimeError – Qureg has to be a wavefunction qureg but density matrix qureg was used

pyquest_cffi.cheat.measurement.getAmp

alias of pyquest_cffi.cheat.measurement.getStateVectoratIndex

pyquest_cffi.cheat.measurement.getDensityAmp

alias of pyquest_cffi.cheat.measurement.getDensityMatrixatRowColumn

class pyquest_cffi.cheat.measurement.getDensityMatrix(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the full density matrix of a quantum register

Parameters:qureg – a qureg containing a wavefunction or density matrix
call_interactive(qureg: Qureg) → numpy.ndarray[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a wavefunction or density matrix
Returns:np.ndarray
class pyquest_cffi.cheat.measurement.getDensityMatrixatRowColumn(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the value of the density matrix in qureg at row and column

Parameters:
  • qureg – a qureg containing a density matrix
  • row – The row index either as an int of as a sequence of 0 and 1 referencing the corresponding basis state
  • column – The column index either as an int of as a sequence of 0 and 1 referencing the corresponding basis state
  • readout – The readout register for static compilation
call_interactive(qureg: Qureg, row: Union[int, Sequence[int]], column: Union[int, Sequence[int]]) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • row – The row index either as an int of as a sequence of 0 and 1 referencing the corresponding basis state
  • column – The column index either as an int of as a sequence of 0 and 1 referencing the corresponding basis state
Returns:

float

Raises:

RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used

class pyquest_cffi.cheat.measurement.getEnvironmentString(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Set input string to a string

Set string contains the number of qubits in qureg, and the hardware facilities used

Parameters:
  • env – object representing the execution environment
  • qureg – quantum register of which to query the simulating hardware
  • string – string to be populated with the output string
call_interactive(env: QuESTEnv, qureg: Qureg, string: str) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • env – object representing the execution environment
  • qureg – quantum register of which to query the simulating hardware
  • string – string to be populated with the output string
Raises:

NotImplementedError – Function added to QuEST.h but not QuEST.c

class pyquest_cffi.cheat.measurement.getExpectationValue(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the expectation value of an operator in matrix form

Not implemented for static compilation

Parameters:
  • qureg – a qureg containing a wavefunction or density matrix
  • operator_matrix – The operator in matrix form
call_interactive(qureg: Qureg, operator_matrix: numpy.ndarray) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction or density matrix
  • operator_matrix – The operator in matrix form
Returns:

float

class pyquest_cffi.cheat.measurement.getImagAmp(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the imaginary value of a wavefunction/state vector in qureg at index

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int or as a sequence of 0 and 1 referencing the corresponding basis state
  • readout – The readout register for static compilation
call_interactive(qureg: Qureg, index: Union[int, Sequence[int]]) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int or as a sequence of 0 and 1 referencing the corresponding basis state
Returns:

float

Raises:

RuntimeError – Qureg has to be a wavefunction qureg but density matrix qureg was used

class pyquest_cffi.cheat.measurement.getNumAmps(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the number of probability amplitudes in a qureg object, given by 2**number_qubits

Parameters:qureg – a qureg containing a wavefunction or a density matrix
call_interactive(qureg: Qureg) → int[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a wavefunction or a density matrix
Returns:int
class pyquest_cffi.cheat.measurement.getNumQubits(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the number of qubits in a qureg object

Parameters:qureg – a qureg containing a wavefunction or a density matrix
call_interactive(qureg: Qureg) → int[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a wavefunction or a density matrix
Returns:int
class pyquest_cffi.cheat.measurement.getOccupationProbability(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the full vector of occupation probabilities for each basis state

Parameters:qureg – a qureg containing a wavefunction or density matrix
call_interactive(qureg: Qureg) → numpy.ndarray[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a wavefunction or density matrix
Returns:np.ndarray
pyquest_cffi.cheat.measurement.getProbAmp

alias of pyquest_cffi.cheat.measurement.getAbsoluteValSquaredatIndex

class pyquest_cffi.cheat.measurement.getRealAmp(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the real value of a wavefunction/state vector in qureg at index

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int of as a sequence of 0 and 1 referencing the corresponding basis state
  • readout – The readout register for static compilation
call_interactive(qureg: Qureg, index: Union[int, Sequence[int]]) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int of as a sequence of 0 and 1 referencing the corresponding basis state
Returns:

float

Raises:

RuntimeError – Qureg has to be a wavefunction qureg but density matrix qureg was used

class pyquest_cffi.cheat.measurement.getRepeatedMeasurement(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get a measurement record of a repeated measurement

Parameters:
  • qureg – a qureg containing a wavefunction or density matrix
  • number_measurments – The number of measurement repetitions
  • qubits_to_readout_index_dict – The mapping of qubit indices to the readout index {qubit_index: readout_index}
Returns:

A measurement record 2d numpy array with N columns, one or each qubit and number_measuremnet rows. Each row contains one complete measurement result for each qubit

call_interactive(qureg: Qureg, number_measurements: int, qubits_to_readout_index_dict: dict) → numpy.ndarray[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction or density matrix
  • number_measurements – The number of measurement repetitions
  • qubits_to_readout_index_dict – The mapping of qubit indices to the readout index {qubit_index: readout_index}
Returns:

np.ndarray

class pyquest_cffi.cheat.measurement.getStateVector(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the full statevector of a quantum register

Parameters:qureg – a qureg containing a wavefunction
call_interactive(qureg: Qureg) → numpy.ndarray[source]

Interactive call of PyQuest-cffi

Parameters:qureg – a qureg containing a wavefunction
Returns:np.ndarray
Raises:RuntimeError – Reference qureg has to be a wavefunction qureg but density matrix qureg was used
class pyquest_cffi.cheat.measurement.getStateVectoratIndex(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Get the value of a wavefunction/state vector in qureg at index

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int or as a sequence of 0 and 1 referencing the corresponding basis state
  • readout – the readout register for static compilation
call_interactive(qureg: Qureg, index: Union[int, Sequence[int]]) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a wavefunction
  • index – The index either as an int or as a sequence of 0 and 1 referencing the corresponding basis state
Returns:

float

Raises:

RuntimeError – Qureg has to be a wavefunction qureg but density matrix qureg was used

pyquest_cffi.cheat.measurement.index_to_basis_state(index: int, num_qubits_represented: int, endianness: str = 'little') → List[source]

Converst index to basis state

Converts an index of the basis to the up/down representation of a basis state depending on the Endian convention of the system

Parameters:
  • index – the basis index
  • num_qubits_represented – Number of qubits represented
  • endianness – ‘big’ or ‘little’ corresponding to the least significant bit being stored in the last or first element of the array respectively In little endianness the qubit 0 corresponds to the bit at index 0 of basis_state the qubit 1 to the bit at index 1 and so on. Note however, that when initialising basis_state = np.array([0, 1, 1, 0,…]) the sequence of bits in the list needs to be inverted form the binary representation. For example 4 which will be 100 in binary would correspond to basis_state= np.array([0,0,1])
Returns:

a sequence of 0 and one representing the qubit basis state

Return type:

List

class pyquest_cffi.cheat.measurement.seedQuEST(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Seed the Mersenne Twister used for random number generation with a user defined seed

This function uses the mt19937 init_by_array function with numSeeds keys supplied by the user. Subsequent calls to mt19937 genrand functions will use this seeding. For a multi process code, the same seed is given to all process, therefore this seeding is only appropriate to use for functions e.g measure where all processes require the same random value.

Parameters:seed_array – Array of integers to use as seed
call_interactive(seed_array: Sequence[int]) → None[source]

Interactive call of PyQuest-cffi

Parameters:seed_array – Array of integers to use as seed
class pyquest_cffi.cheat.measurement.seedQuESTDefault(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Seed the Mersenne Twister used for random number generation with an example default seed

This function uses the mt19937 init_by_array function with numSeeds keys supplied by the user. Subsequent calls to mt19937 genrand functions will use this seeding. For a multi process code, the same seed is given to all process, therefore this seeding is only appropriate to use for functions e.g. measure where all processes require the same random value.

call_interactive() → None[source]

Interactive call of PyQuest-cffi

class pyquest_cffi.cheat.measurement.syncQuESTEnv(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Guarantees that all code up to the given point has been executed on all nodes

Parameters:env – execution environment
call_interactive(env: QuESTEnv) → None[source]

Interactive call of PyQuest-cffi

Parameters:env – execution environment
class pyquest_cffi.cheat.measurement.syncQuESTSuccess(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Performs a logical AND on all successCodes held by all processes.

If any one process has a zero successCode all processes will return a zero success code.

Parameters:success_code – 1 if process task succeeded, 0 if process task failed
call_interactive(success_code: int) → int[source]

Interactive call of PyQuest-cffi

Parameters:success_code – 1 if process task succeeded, 0 if process task failed
Returns:int

Initialization

Initialisation objects in PyQuest-cffi

class pyquest_cffi.cheat.initialization.initBlankState(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise classical zero state in quantum register

Parameters:qureg – qureg that is set to zero
call_interactive(qureg: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:qureg – qureg that is set to zero
class pyquest_cffi.cheat.initialization.initClassicalState(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise classical state in quantum register

Initialise classical state, a classical integer in binary representation in the quantum register

Parameters:
  • qureg – The quantum register
  • int – The integer that is initialised in binary representation in the quantum register
call_interactive(qureg: Qureg, state: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • state – The integer that is initialised in binary representation in the quantum register
class pyquest_cffi.cheat.initialization.initDebugState(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise debug state in quantum register

Parameters:qureg – quantum register
call_interactive(qureg: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:qureg – quantum register
class pyquest_cffi.cheat.initialization.initPauliHamil(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise a PauliHamil instance

Parameters:
  • pauli_hamil – PauliHamil instance to initialise
  • coeffs – array of coefficients
  • codes – array of Pauli codes
call_interactive(pauli_hamil: PauliHamil, coeffs: Sequence[float], codes: Sequence[Sequence[int]]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • pauli_hamil – PauliHamil instance to initialise
  • coeffs – array of coefficients
  • codes – array of Pauli codes
Raises:

RuntimeError – Need one coeff and one set of codes per qubit of PauliHamil and need one term in each set of codes per PauliProduct

class pyquest_cffi.cheat.initialization.initPlusState(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise plus state in quantum register

Parameters:qureg – quantum register
call_interactive(qureg: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:qureg – quantum register
class pyquest_cffi.cheat.initialization.initPureState(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise pure state in quantum register

Initialises a pure state in one wavefunction quantum register based on the pure state of another quantum register

Parameters:
  • qureg_a – Quantum register that is initialised
  • qureg_b – Quantum register that contains the reference pure state
call_interactive(qureg_a: Qureg, qureg_b: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg_a – Quantum register that is initialised
  • qureg_b – Quantum register that contains the reference pure state
class pyquest_cffi.cheat.initialization.initStateFromAmps(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise a state (from amplitudes) in quantum register

Initialise a wavefunction in a quantum register based on the real and imaginary parts of the statevector

Parameters:
  • qureg – the quantum register
  • reals – The real parts of the statevector
  • imags – The imaginary parts of the statevector
call_interactive(qureg: Qureg, reals: Union[numpy.ndarray, List[float]], imags: Union[numpy.ndarray, List[float]]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – the quantum register
  • reals – The real parts of the statevector
  • imags – The imaginary parts of the statevector
Raises:
  • RuntimeError – Size of reals and imags needs to match
  • RuntimeError – Shape of reals and imags for wavefunction should be: (1, 2**qubits)
  • RuntimeError – Shape of reals and imags for density matrix should be: (2**qubits, 2**qubits) OR (4**qubits, 1)
  • RuntimeError – Shape of reals and imags for density matrix should be: (2**qubits, 2**qubits) OR (4**qubits, 1)
  • RuntimeError – Need to set real and imaginary amplitudes for each qubit: 2**qubits for wavefunction qureg, 4**qubits for density matrix qureg
class pyquest_cffi.cheat.initialization.initZeroState(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Initialise zero state in quantum register

Parameters:qureg – quantum register
call_interactive(qureg: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:qureg – quantum register
class pyquest_cffi.cheat.initialization.setAmps(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Class setting the Amplitudes in statevector

Set the values of elements of the statevector in a quantum register

Parameters:
  • qureg – The quantum register
  • startind – The index of the first element of the statevector that is set
  • reals – the new real values of the elements of the statevector between startind and startind+numamps
  • imgas – the new imaginary values of the elements of the statevector between startind and startind+numamps
  • numaps – the number of new values that are set in the statevector
call_interactive(qureg: Qureg, startind: int, reals: Union[numpy.ndarray, List[float]], imags: Union[numpy.ndarray, List[float]], numamps: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – The quantum register
  • startind – The index of the first element of the statevector that is set
  • reals – the new real values of the elements of the statevector between startind and startind+numamps
  • imags – the new imaginary values of the elements of the statevector between startind and startind+numamps
  • numamps – the number of new values that are set in the statevector
Raises:

RuntimeError – Qureg has to be a wavefunction qureg but density matrix qureg was used

class pyquest_cffi.cheat.initialization.setDensityAmps(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Class setting the Amplitudes in density matrix

Set the values of elements of the vector representation of the density matrix in a quantum register

Parameters:
  • qureg – The quantum register of a density matrix
  • reals – the new real values of the elements of the density matrix between startind and startind+numamps
  • imags – the new imaginary values of the elements of the density matrix between startind and startind+numamps
call_interactive(qureg: Qureg, reals: Union[numpy.ndarray, List[List[float]]], imags: Union[numpy.ndarray, List[List[float]]]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – The quantum register of a density matrix
  • reals – the new real values of the elements of the density matrix between startind and startind+numamps
  • imags – the new imaginary values of the elements of the density matrix between startind and startind+numamps
Raises:

RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used

class pyquest_cffi.cheat.initialization.setWeightedQureg(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Class setting a qureg as a weighted sum of two quregs

Set the values of elements of the vector representation of the density matrix in a quantum register

Parameters:
  • fac1 – prefactor of first qureg in sum
  • qureg1 – first qureg in sum
  • fac2 – prefactor of second qureg in sum
  • qureg2 – second qureg in sum
  • facout – prefactor of output qureg
  • quregout – output qureg
call_interactive(fac1: complex, qureg1: Qureg, fac2: complex, qureg2: Qureg, facout: complex, quregout: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • fac1 – prefactor of first qureg in sum
  • qureg1 – first qureg in sum
  • fac2 – prefactor of second qureg in sum
  • qureg2 – second qureg in sum
  • facout – prefactor of output qureg
  • quregout – output qureg
Raises:

RuntimeError – Qureg has to be a wavefunction qureg but density matrix qureg was used