Class QuantumStateBase

Inheritance Relationships

Derived Types

Class Documentation

class QuantumStateBase

Quantum state basis class

Subclassed by DensityMatrixCpu, QuantumStateCpu

Public Functions

QuantumStateBase(UINT qubit_count_, bool is_state_vector)

Constructor

Parameters
  • qubit_count_: Qubit number

QuantumStateBase(UINT qubit_count_, bool is_state_vector, UINT device_number_)
virtual ~QuantumStateBase()

Destructor

virtual bool is_state_vector() const

Determine if quantum state is state vector or density matrix

virtual void set_zero_state() = 0

Initialize the quantum state to the 0 state of the computational basis

virtual void set_computational_basis(ITYPE comp_basis) = 0

Initialize the quantum state to basis state of comp_basis

Parameters
  • comp_basis: An integer indicating the initializing basis

virtual void set_Haar_random_state() = 0

Initialize the quantum state to Haar random sampled quantum states

virtual void set_Haar_random_state(UINT seed) = 0

Initialize the quantum state to Haar random sampled quantum states using seed

virtual double get_zero_probability(UINT target_qubit_index) const = 0

Calculate the probability of observing 0 when measuring the qubit at the index of target_qubit_index.

The quantum state does not change.

Return

double

Parameters
  • target_qubit_index:

virtual double get_marginal_probability(std::vector<UINT> measured_values) const = 0

Calculate marginal probabilities when measuring multiple qubits

Return

Calculated marginal probabilities

Parameters
  • measured_values: An array of 0,1,2 with the same length as the number of qubits. 0,1 means that the value is observed, and 2 means no measurement.

virtual double get_entropy() const = 0

Calculate the entropy of the probability distribution obtained when measuring on the calculation basis.

Return

Entropy

virtual double get_squared_norm() const = 0

Calculate norm of quantum state

The norm of the quantum state becomes smaller when a non-unitary gate is applied.

Return

Norm

virtual void normalize(double squared_norm) = 0

Normalize quantum states

Parameters
  • norm: Norm of itself

virtual QuantumStateBase *allocate_buffer() const = 0

Create a quantum state of the same size as a buffer.

Return

Created quantum state

virtual QuantumStateBase *copy() const = 0

Generate a deep copy of itself

Return

Deep copy of itself

virtual void load(const QuantumStateBase *state) = 0

Copy quantum state state to itself

virtual void load(const std::vector<CPPCTYPE> &state) = 0

Copy quantum state state to itself

virtual void load(const CPPCTYPE *state) = 0

Copy quantum state state to itself

virtual const std::string get_device_name() const = 0

Obtain the name of the device that holds the memory where the quantum state is located.

virtual void *data() const = 0
virtual CPPCTYPE *data_cpp() const = 0

Obtain quantum state as an array of std::complex<double> of C++

Return

Pointer of complex vector

virtual CTYPE *data_c() const = 0

Obtain quantum state as an array of complex type of csim

Return

Pointer of complex vector

virtual CPPCTYPE *duplicate_data_cpp() const = 0

Secure quantum state as a new array of std::complex<double> of C++

Return

Pointer of complex vector

virtual CTYPE *duplicate_data_c() const = 0

Secure quantum state as a new array of complex type of csim

Return

Pointer of complex vector

virtual void add_state(const QuantumStateBase *state) = 0

Add quantum state

virtual void multiply_coef(CPPCTYPE coef) = 0

Multiply complex number

virtual void multiply_elementwise_function(const std::function<CPPCTYPE(ITYPE)> &func) = 0
virtual UINT get_classical_value(UINT index)

Obtain the value of the classical register with the specified index.

Return

Ponter of complex vector

Parameters
  • index: Index of register to be set

virtual void set_classical_value(UINT index, UINT val)

Set the value of the classical register with the specified index.

Return

Ponter of complex vector

Parameters
  • index: Index of register to be set

  • val: Value to be set

virtual const std::vector<UINT> get_classical_register() const

Return vectore of classic register

Return

Classic register

virtual std::vector<ITYPE> sampling(UINT sampling_count) = 0

Sampling the computational basis when measuring the quantum state

Return

List of sampled values

Parameters
  • [in] sampling_count: Number of times sampling is performed

virtual std::string to_string() const

Generate a string of debug information for a quantum circuit

Return

Generated string

virtual void *get_cuda_stream() const

Public Members

const UINT &qubit_count

Qubit number

const ITYPE &dim

Dimension of quantum state

const std::vector<UINT> &classical_register

Register of classic bit

const UINT &device_number

Protected Attributes

ITYPE _dim
UINT _qubit_count
bool _is_state_vector
std::vector<UINT> _classical_register
UINT _device_number
void *_cuda_stream

Friends

std::ostream &operator<<(std::ostream &os, const QuantumStateBase &state)

Output quantum state debug information.

Return

String received

std::ostream &operator<<(std::ostream &os, const QuantumStateBase *state)

Output quantum state debug information.

Return

String received