quara.qcircuit.experiment module

class Experiment(schedules, states=None, povms=None, gates=None, mprocesses=None, seed_data=None)[source]

Bases: object

Class to manage experiment settings This class is not limited to tomography, but deals with general quantum circuits.

Parameters
Return type

None

calc_prob_dist(schedule_index)[source]

Calculate the probability distributionthe by running the specified schedule.

Parameters

schedule_index (int) – Index of the schedule

Returns

Probability distribution

Return type

np.ndarray

Raises

ValueError – If the object referenced in the schedule, such as State, POVM, Gate, or Mprocess, is None.

calc_prob_dists()[source]

Caluclate probability distributions for all schedules.

Returns

Probability distributions for all schedules

Return type

List[np.ndarray]

copy()[source]

returns copied Experiment.

Returns

copied Experiment.

Return type

Experiment

property gates: List[quara.objects.gate.Gate]
generate_data(schedule_index, data_num, seed_or_generator=None)[source]

Runs the specified schedule to caluclate the probability distribution and generate random data.

Parameters
  • schedule_index (int) – Index of the schedule.

  • data_num (int) – Length of the data.

  • seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.

Returns

Generated data.

Return type

List[int]

Raises
  • TypeError – [description]

  • ValueError – [description]

  • IndexError – [description]

generate_dataset(data_nums, seed_or_generator=None)[source]

Run all the schedules to caluclate the probability distribution and generate random data.

Parameters
  • data_nums (List[int]) – A list of the number of data to be generated in each schedule. This parameter should be a list of non-negative integers.

  • seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.

Returns

Generated dataset.

Return type

List[List[np.ndarray]]

generate_empi_dist_sequence(schedule_index, num_sums, seed_or_generator=None)[source]

Generate an empirical distribution using the data generated from the probability distribution of a specified schedule.

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

Parameters
  • schedule_index (int) – Index of schedule.

  • num_sums (List[int]) – List of the number of data to caluclate the experience distribution

  • seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.

Returns

A list of the numbers of data and empirical distribution.

Return type

List[Tuple[int, np.ndarray]]

generate_empi_dists_sequence(list_num_sums, seed_or_generator=None)[source]

Generate empirical distributions using the data generated from probability distributions of all specified schedules.

Parameters
  • list_num_sums (List[List[int]]) – A list of the number of data to use to calculate the experience distribution for each schedule.

  • seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.

Returns

A list of tuples for the number of data and experience distribution for each schedules.

Return type

List[List[Tuple[int, np.ndarray]]]

property mprocesses: List[quara.objects.gate.Gate]
num_qoperations(mode)[source]

returns number of qoperations with specified mode.

Parameters

mode (str) – mode to get number of qoperations. mode can be “state”, “povm”, “gate”, or “mprocess”.

Returns

number of qoperations with specified mode.

Return type

int

Raises

ValueError – Unsupported mode is specified.

property povms: List[quara.objects.povm.Povm]
qoperations(mode)[source]

returns qoperations with specified mode.

Parameters

mode (str) – mode to get qoperations. mode can be “state”, “povm”, “gate”, or “mprocess”.

Returns

qoperations with specified mode.

Return type

Union[List[State], List[Povm], List[Gate], List[MProcess]]

Raises

ValueError – Unsupported mode is specified.

reset_seed_data(seed_data)[source]

reset new seed.

Parameters

seed_data (int) – new seed for generating data.

Return type

None

property schedules: List[List[Tuple[str, int]]]
property seed_data: int
property states: List[quara.objects.state.State]
exception QuaraScheduleItemError[source]

Bases: Exception

Raised when an element of the schedule is incorrect.

Parameters

Exception ([type]) – [description]

exception QuaraScheduleOrderError[source]

Bases: Exception

Raised when the order of the schedule is incorrect.

Parameters

Exception ([type]) – [description]