quara.qcircuit.data_generator module

calc_empi_dist_sequence(measurement_num, data, num_sums)[source]

calculates empirical distributions.

uses data from 0-th to num_sums[index]-th to calculate empirical distributions.

Parameters
  • measurement_num (int) – number of measurements.

  • data (List[int]) – data of measurement outcomes.

  • num_sums (List[int]) – a list of the range of data to calculate empirical distributions.

Returns

a list of (the range of data, empirical distribution). the dtype of each empirical distribution is np.float64.

Return type

List[Tuple[int, np.ndarray]]

Raises
  • ValueErrormeasurement_num is not non-negative integer.

  • ValueError – there is an element of num_sums that is not less than or equal to length of data.

  • ValueError – there is an element of data that is not non-negative and less than measurement_num.

  • ValueErrornum_sums is not an increasing sequence.

Examples

>>> measurement_num = 2
>>> data = [1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1]
>>> num_sums = [5, 10, 20]
>>> empi_dist = calc_empi_dist_sequence(measurement_num, data, num_sums)
>>> empi_dist
[(5, array([0.4, 0.6])), (10, array([0.3, 0.7])), (20, array([0.3, 0.7]))]
calc_empi_dists_sequence(measurement_nums, dataset, list_num_sums)[source]

calculates a sequence of empirical distributions by calc_empidist().

Parameters
  • measurement_nums (List[int]) – a list of measurement_num

  • dataset (List[List[int]]) – a dataset

  • list_num_sums (List[List[int]]) – a list of num_sums

Returns

a sequence of empirical distributions.

Return type

List[List[np.ndarray]]

Raises
  • ValueError – the length of measurement_nums does not equal the length of dataset.

  • ValueError – the length of measurement_nums does not equal the length of list_llist_num_sumsist_num_sum.

generate_data_from_prob_dist(prob_dist, data_num, seed=None, atol=None)[source]

generates random data from a probability distribution.

the data is a sequence (list) of measurement outcomes. measurement outcomes are integers. 0 <= each measurement outcomes < len(probdist). length of the data equals data_num.

Parameters
  • prob_dist (np.ndarray) – a probability distribution used to generate random data.

  • data_num (int) – length of the data.

  • seed (int, optional) – a seed used to generate random data, by default None.

  • atol (float, optional) – the absolute tolerance parameter, uses get_atol() by default. checks absolute(the sum of probabilities - 1) <= atol in this function.

Returns

generated data.

Return type

List[int]

Raises
  • ValueError – each probability is not a positive number.

  • ValueError – the sum of probabilities does not equal 1.

generate_dataset_from_prob_dists(prob_dists, data_nums, seeds=None)[source]

generates random dataset from probability distributions.

the dataset is a list of data generated by generate_data_from_probdist()

Parameters
  • prob_dists (List[np.ndarray]) – a list of probdist.

  • data_nums (List[int]) – a list of data_num.

  • seeds (List[int], optional) – a list of seed, by default None

Returns

generated dataset.

Return type

List[List[int]]

Raises
  • ValueError – the length of prob_dists does not equal the length of data_nums.

  • ValueErrorseeds is not None and the length of prob_dists does not equal the length of seeds.