<commit_before>// Distributed under MIT licence. See https://github.com/aniabrown/QuEST/blob/master/LICENCE.txt 
// for details 

# ifndef QuEST
# define QuEST

# include "QuEST_precision.h"
/** @file
 * The QuEST library API and objects. 
*/

/** Represents an array of complex numbers grouped into an array of real components and an array of coressponding complex components.
*/
typedef struct ComplexArray
{
	REAL *real; 
	REAL *imag;
} ComplexArray;

/** Represents one complex number.
*/
typedef struct Complex
{
	REAL real;
	REAL imag;
} Complex;

/** Represents a 2x2 matrix of complex numbers
*/
typedef struct ComplexMatrix2
{
	Complex r0c0, r0c1;
	Complex r1c0, r1c1;
} ComplexMatrix2;

/** Represents a 3-vector of real numbers
*/
typedef struct Vector
{
	REAL x, y, z;
} Vector;

/** Represents a system of qubits.
Qubits are zero-based
*/
typedef struct MultiQubit
{
	//! Probablilty amplitudes for the multi qubit state
	ComplexArray stateVec; 
	//! Temporary storage for a chunk of the state vector received from another process in the MPI version
	ComplexArray pairStateVec;
	//! Number of qubits in the state
	int numQubits;
	//! Number of probability amplitudes held in stateVec by this process
	//! In the non-MPI version, this is the total number of amplitudes
	long long int numAmps;
	//! The position of the chunk of the state vector held by this process in the full state vector
	int chunkId;
	//! Number of chunks the state vector is broken up into -- the number of MPI processes used
	int numChunks;
} MultiQubit;

/** Information about the environment the program is running in.
In practice, this holds info about MPI ranks and helps to hide MPI initialization code
*/
typedef struct QuESTEnv
{
	int rank;
	int numRanks;
} QuESTEnv;

// Codes for sigmaZ phase gate variations
enum phaseGateType {SIGMA_Z=0, S_GATE=1, T_GATE=2};

// QuEST library functions whose implementation is independent of environment (local, MPI)

/** Create a MultiQubit object representing a set of qubits.
 * Allocate space for state vector of probability amplitudes, including space for temporary values to be copied from
 * one other chunk if running the distributed version. Define properties related to the size of the set of qubits.
 * initStateZero should be called after this to initialise the qubits to the zero state.
 *
 * @param[in,out] multiQubit a pointer to an object representing the set of qubits
 * @param[in] numQubits number of qubits in the system
 * @param[in] env object representing the execution environment (local, multinode etc)
 * @throws exitWithError if \p numQubits <= 0
 */
void createMultiQubit(MultiQubit *multiQubit, int numQubits, QuESTEnv env);

/** Deallocate a MultiQubit object representing a set of qubits.
 * Free memory allocated to state vector of probability amplitudes, including temporary vector for
 * values copied from another chunk if running the distributed version.
 *
 * @param[in,out] multiQubit object to be deallocated
 * @param[in] env object representing the execution environment (local, multinode etc)
 */
void destroyMultiQubit(MultiQubit multiQubit, QuESTEnv env);

/** Print the current state vector of probability amplitudes for a set of qubits to file.
 * File format:
 * @verbatim
real, imag
realComponent1, imagComponent1
realComponent2, imagComponent2
...
realComponentN, imagComponentN
@endverbatim
 *
 * File naming convention:
 *
 * For each node that the program runs on, a file 'state_rank_[node_rank].csv' is generated. If there is
 * more than one node, ranks after the first do not include the header
 * @verbatim
real, imag
@endverbatim
 * so that files are easier to combine.

 * @param[in,out] multiQubit object representing the set of qubits
 */
void reportState(MultiQubit multiQubit);

/** Print the current state vector of probability amplitudes for a set of qubits to standard out. 
 * For debugging purposes. Each rank should print output serially. 
 * Only print output for systems <= 5 qubits
 */
void reportStateToScreen(MultiQubit multiQubit, QuESTEnv env, int reportRank);

/** Report metainformation about a set of qubits: number of qubits, number of probability amplitudes.

 * @param[in,out] multiQubit object representing the set of qubits
 * @param[in] env object representing the execution environment (local, multinode etc)
 */
void reportMultiQubitParams(MultiQubit multiQubit);

/**
 * Initialise a set of \f$ N \f$ qubits to the classical zero state 
 * \f$ {| 0 \rangle}^{\otimes N} \f$.
 *
 * @param[in,out] multiQubit a pointer to the object representing the set of all qubits to initialise
 */
void initStateZero(MultiQubit *multiQubit);

/**
 * Initialise a set of \f$ N \f$ qubits to the plus state
 * \f$ {| + \rangle}^{\otimes N} = \frac{1}{\sqrt{2^N}} (| 0 \rangle + | 1 \rangle)^{\otimes N} \f$.
 * This is the product state of \f$N\f$ qubits where every classical state is uniformly 
 * populated with real coefficient \f$\frac{1}{\sqrt{2^N}}\f$.
 * This is equivalent to applying a Hadamard to every qubit in the zero state: 
 * \f$ \hat{H}^{\otimes N} {|0\rangle}^{\otimes N} \f$
 *
 * @param[in,out] multiQubit a pointer to the object representing the set of qubits to be initialised
 */
void initStatePlus(MultiQubit *multiQubit);
<commit_msg>added docstring for initClassicalState<commit_after>// Distributed under MIT licence. See https://github.com/aniabrown/QuEST/blob/master/LICENCE.txt 
// for details 

# ifndef QuEST
# define QuEST

# include "QuEST_precision.h"
/** @file
 * The QuEST library API and objects. 
*/

/** Represents an array of complex numbers grouped into an array of real components and an array of coressponding complex components.
*/
typedef struct ComplexArray
{
	REAL *real; 
	REAL *imag;
} ComplexArray;

/** Represents one complex number.
*/
typedef struct Complex
{
	REAL real;
	REAL imag;
} Complex;

/** Represents a 2x2 matrix of complex numbers
*/
typedef struct ComplexMatrix2
{
	Complex r0c0, r0c1;
	Complex r1c0, r1c1;
} ComplexMatrix2;

/** Represents a 3-vector of real numbers
*/
typedef struct Vector
{
	REAL x, y, z;
} Vector;

/** Represents a system of qubits.
Qubits are zero-based
*/
typedef struct MultiQubit
{
	//! Probablilty amplitudes for the multi qubit state
	ComplexArray stateVec; 
	//! Temporary storage for a chunk of the state vector received from another process in the MPI version
	ComplexArray pairStateVec;
	//! Number of qubits in the state
	int numQubits;
	//! Number of probability amplitudes held in stateVec by this process
	//! In the non-MPI version, this is the total number of amplitudes
	long long int numAmps;
	//! The position of the chunk of the state vector held by this process in the full state vector
	int chunkId;
	//! Number of chunks the state vector is broken up into -- the number of MPI processes used
	int numChunks;
} MultiQubit;

/** Information about the environment the program is running in.
In practice, this holds info about MPI ranks and helps to hide MPI initialization code
*/
typedef struct QuESTEnv
{
	int rank;
	int numRanks;
} QuESTEnv;

// Codes for sigmaZ phase gate variations
enum phaseGateType {SIGMA_Z=0, S_GATE=1, T_GATE=2};

// QuEST library functions whose implementation is independent of environment (local, MPI)

/** Create a MultiQubit object representing a set of qubits.
 * Allocate space for state vector of probability amplitudes, including space for temporary values to be copied from
 * one other chunk if running the distributed version. Define properties related to the size of the set of qubits.
 * initStateZero should be called after this to initialise the qubits to the zero state.
 *
 * @param[in,out] multiQubit a pointer to an object representing the set of qubits
 * @param[in] numQubits number of qubits in the system
 * @param[in] env object representing the execution environment (local, multinode etc)
 * @throws exitWithError if \p numQubits <= 0
 */
void createMultiQubit(MultiQubit *multiQubit, int numQubits, QuESTEnv env);

/** Deallocate a MultiQubit object representing a set of qubits.
 * Free memory allocated to state vector of probability amplitudes, including temporary vector for
 * values copied from another chunk if running the distributed version.
 *
 * @param[in,out] multiQubit object to be deallocated
 * @param[in] env object representing the execution environment (local, multinode etc)
 */
void destroyMultiQubit(MultiQubit multiQubit, QuESTEnv env);

/** Print the current state vector of probability amplitudes for a set of qubits to file.
 * File format:
 * @verbatim
real, imag
realComponent1, imagComponent1
realComponent2, imagComponent2
...
realComponentN, imagComponentN
@endverbatim
 *
 * File naming convention:
 *
 * For each node that the program runs on, a file 'state_rank_[node_rank].csv' is generated. If there is
 * more than one node, ranks after the first do not include the header
 * @verbatim
real, imag
@endverbatim
 * so that files are easier to combine.

 * @param[in,out] multiQubit object representing the set of qubits
 */
void reportState(MultiQubit multiQubit);

/** Print the current state vector of probability amplitudes for a set of qubits to standard out. 
 * For debugging purposes. Each rank should print output serially. 
 * Only print output for systems <= 5 qubits
 */
void reportStateToScreen(MultiQubit multiQubit, QuESTEnv env, int reportRank);

/** Report metainformation about a set of qubits: number of qubits, number of probability amplitudes.

 * @param[in,out] multiQubit object representing the set of qubits
 * @param[in] env object representing the execution environment (local, multinode etc)
 */
void reportMultiQubitParams(MultiQubit multiQubit);

/**
 * Initialise a set of \f$ N \f$ qubits to the classical zero state 
 * \f$ {| 0 \rangle}^{\otimes N} \f$.
 *
 * @param[in,out] multiQubit a pointer to the object representing the set of all qubits to initialise
 */
void initStateZero(MultiQubit *multiQubit);

/**
 * Initialise a set of \f$ N \f$ qubits to the plus state
 * \f$ {| + \rangle}^{\otimes N} = \frac{1}{\sqrt{2^N}} (| 0 \rangle + | 1 \rangle)^{\otimes N} \f$.
 * This is the product state of \f$N\f$ qubits where every classical state is uniformly 
 * populated with real coefficient \f$\frac{1}{\sqrt{2^N}}\f$.
 * This is equivalent to applying a Hadamard to every qubit in the zero state: 
 * \f$ \hat{H}^{\otimes N} {|0\rangle}^{\otimes N} \f$
 *
 * @param[in,out] multiQubit a pointer to the object representing the set of qubits to be initialised
 */
void initStatePlus(MultiQubit *multiQubit);

/**
 * Initialise a set of \f$ N \f$ qubits to the classical state with index \p stateInd.
 * Note \f$ | 00 \dots 00 \rangle \f$ has \p stateInd 0, \f$ | 00 \dots 01 \rangle \f$ has \p stateInd 1, 
 * \f$ | 11 \dots 11 \rangle \f$ has \p stateInd \f$ 2^N - 1 \f$, etc.
 * Subsequent calls to getProbEl will yield 0 for all indices except \p stateInd.
 *
 * @param[in,out] multiQubit a pointer to the object representing the set of qubits to be initialised
 * @param[in] stateInd the index (0 to the number of amplitudes, exclusive) of the state to give probability 1
 */
void initClassicalState(MultiQubit *multiQubit, long long int stateInd);

{'fraction_non_alphanumeric': 0.0837354781054513, 'fraction_numerical': 0.007059874888293119, 'mean_word_length': 4.1571428571428575, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2168009', 'n_tokens_mistral': 3388, 'n_tokens_neox': 3194, 'n_words': 1473}