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.
- 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) –
- 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:
- is_complete() bool [source]
Returns whether all device parameters have been successfully initialized.
- Return type:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- quantum_gates.utilities.create_qc_list(circuit_generator, nqubits_list, qubits_layout, backend)[source]
Creates a list of quantum circuit.
- Parameters:
- 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:
- 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