Utilities

The utilities make your life easier by providing functionalities which are repeatedly when working with the quantum gates library.

class quantum_gates.utilities.DeviceParameters(qubits_layout: list)[source]

Bases: object

Snapshot of the noise of the IBM backend. Can load and save the properties.

Parameters:

qubits_layout (list[int]) – Layout of the qubits.

qubits_layout[source]

Layout of the qubits.

Type:

list[int]

nr_of_qubits[source]

Number of qubits to be used.

Type:

int

T1[source]

T1 time.

Type:

np.array

T2[source]

T2 time.

Type:

np.array

p[source]

To be added.

Type:

np.array

rout[source]

To be added.

Type:

np.array

p_cnot[source]

Error probabilites in the CNOT gate.

Type:

np.array

p_cnot[source]

Gate time to implement controlled not operations in the CNOT gate.

Type:

np.array

tm[source]

To be added.

Type:

np.array

dt[source]

To be added.

Type:

np.array

f_T1 = 'T1.txt'[source]
f_T2 = 'T2.txt'[source]
f_p = 'p.txt'[source]
f_rout = 'rout.txt'[source]
f_p_cnot = 'p_cnot.txt'[source]
f_t_cnot = 't_cnot.txt'[source]
f_tm = 'tm.txt'[source]
f_dt = 'dt.txt'[source]
f_json = 'device_parameters.json'[source]
f_metadata = 'metadata.json'[source]
load_from_json(location: str)[source]

Load device parameters from single json file at the location.

Parameters:

location (str) –

load_from_texts(location: str)[source]

Load device parameters from many text files at the location.

Parameters:

location (str) –

load_from_backend(backend)[source]

Load device parameters from the IBM backend.

save_to_texts(location: str)[source]

Save device parameters to text files at a specific location.

Parameters:

location (str) –

save_to_json(location: str)[source]

Save device parameters to a json file at the location. The arrays are converted to lists in the process.

Parameters:

location (str) –

get_as_tuple() tuple[source]

Get the parameters as a tuple. The parameters have to be already loaded.

Return type:

tuple

is_complete() bool[source]

Returns whether all device parameters have been successfully initialized.

Return type:

bool

check_T1_and_T2_times(do_raise_exception: bool) bool[source]

Checks the T1 and T2 times. Raises an exception in case of invalid T1, T2 times if the flag is set. Returns whether or not all qubits are flawless.

Parameters:

do_raise_exception (bool) –

Return type:

bool

_texts_exist_at_location(location)[source]

Checks if the text files with the device parameters exist at the expected location. Raises an exception if more than one text is missing.

_json_exists_at_location(location)[source]

Checks if the json files with the device parameters exist, otherwise raises an exception.

quantum_gates.utilities.multiprocessing_parallel_simulation(args: list, simulation: callable, max_workers: int | None = None)[source]

The .map method allows to execute the function simulation N_process times simultaneously.

Preserves the order of the given comprehension list. We create a deepcopy of the argument, the simulation currently modifies it during execution.

Parameters:
  • args (list) –

  • simulation (callable) –

  • max_workers (int | None) –

quantum_gates.utilities.mock_parallel_simulation(args: dict, simulation: callable, max_workers: int | None = None)[source]

This function mocks the parallel simulation.

It is useful for debugging, because the error messages are displayed. In the real parallel simulation, they are muted.

Parameters:
  • args (dict) –

  • simulation (callable) –

  • max_workers (int | None) –

quantum_gates.utilities.concurrent_parallel_simulation(args: list, simulation: callable, max_workers: int | None = None)[source]

The .map method allows to execute the function simulation N_process times simultaneously.

Preserves the order of the given comprehension list. We create a deepcopy of the argument, the simulation currently modifies it during execution.

Parameters:
  • args (list) –

  • simulation (callable) –

  • max_workers (int | None) –

quantum_gates.utilities.fix_counts(counts_0: dict, n_qubits: int)[source]

Fixes the qiskit counts in the standard convention, orders the list and adds strings with zero counts.

Parameters:
  • counts_0 (dict) –

  • n_qubits (int) –

quantum_gates.utilities.load_config(filename: str = '') dict[source]

Asks for the config filename in the prompt, loads it and returns it as json file.

Note: In case you provide a filename as argument, then you can choose to use this filename by providing the empty input.

Parameters:

filename (str) –

Return type:

dict

quantum_gates.utilities.create_qc_list(circuit_generator, nqubits_list, qubits_layout, backend)[source]

Creates a list of quantum circuit.

Parameters:
  • circuit_generator (callable) – Function which takes the number of qubits and returns a Qiskit circuit.

  • nqubits_list (list[int]) – List of the qubit numbers for which a quantum circuit should be generated.

  • qubits_layout (list[int]) – Layout of the qubits in the backend.

  • backend – IBM backend.

Returns:

1 to the items in the list of qubits.

Return type:

A list of transpiled circuits, generated by the Qiskit transpiler. The list items correspond 1

quantum_gates.utilities.setup_backend(Token: str, hub: str, group: str, project: str, device_name: str)[source]

Takes the backend configuration and returns the configured backend.

Parameters:
  • Token (str) – Token generated with the IBM Quantum Experience account.

  • hub (str) – Hub name of the account where the project is located.

  • group (str) – Group name of the account.

  • project (str) – Project under which the user has access to the device.

  • device_name (str) – Name of the quantum device.

Returns:

An IBM Quantum provider object that is configured with the given backend parameters and provides access to the specified quantum device.

quantum_gates.utilities.post_process_split(source_filenames: list, target_filenames: list, split: int)[source]

Takes a list of filenames corresponding to the source data. Loads the files as arrays and combines split many files into the target files with the given filenames.

Note

This is used as a postprocessing step when we use a split > 1 or when we reduce the shots size and perform more experiments.

Example

source_filenames = [“file1.txt”, …, “file100.txt”] target_filenames = [“target1.txt”, …, “target10.txt”] split = 10

Parameters:
  • source_filenames (list) –

  • target_filenames (list) –

  • split (int) –

quantum_gates.utilities.hellinger_distance(p_ng: float, p_real: float, nqubits: int) float[source]

Given two distributions as array, returns the Hellinger distance.

Parameters:
Return type:

float