qiskit.providers.ibmq.random.CQCExtractor¶
-
class
CQCExtractor
(name, provider, client, methods)[source]¶ Class for interfacing with a CQC remote extractor.
There are two extractor methods - Dodis (extractor 1) and Hayashi (extractor 2). These methods can be invoked synchronously or asynchronously. To invoke them synchronously:
random_bits = extractor.run(*cqc_parameters)
To invoke them asynchronously:
import numpy as np extractor1_out = extractor.run_async_ext1(*ext1_parameters).block_until_ready() extractor2_out = extractor.run_async_ext2( ext2_seed=extractor1_out, *ext2_parameters).block_until_ready() random_bits = np.append(extractor1_out, extractor2_out)
Running them asynchronously takes more steps because extractor 2 uses the output of extractor 1 as its seed, so it must wait for extractor 1 to finish first.
BaseRandomService constructor.
- Parameters
name (
str
) – Name of the extractor.provider (
AccountProvider
) – IBM Quantum Experience account provider.client (
RandomClient
) – Client used to communicate with the server.methods (
List
) – Service methods.
-
__init__
(name, provider, client, methods)¶ BaseRandomService constructor.
- Parameters
name (
str
) – Name of the extractor.provider (
AccountProvider
) – IBM Quantum Experience account provider.client (
RandomClient
) – Client used to communicate with the server.methods (
List
) – Service methods.
Methods
__init__
(name, provider, client, methods)BaseRandomService constructor.
retrieve_job
(job_id)Retrieve a previously submitted job.
run
(ext1_input_num_bits, …[, …])Process input data synchronously.
run_async_ext1
(ext1_input_num_bits, …)Run the first extractor asynchronously.
run_async_ext2
(ext2_seed, …[, …])Run the second extractor asynchronously.
-
retrieve_job
(job_id)[source]¶ Retrieve a previously submitted job.
- Parameters
job_id (
str
) – Job ID.- Return type
CQCExtractorJob
- Returns
A
CQCExtractorJob
instance.
-
run
(ext1_input_num_bits, ext1_output_num_bits, ext1_raw_bytes, ext1_wsr_bytes, ext2_seed_num_bits, ext2_wsr_multiplier, ext2_wsr_generator=None)[source]¶ Process input data synchronously.
- Parameters
ext1_input_num_bits (
int
) – Number of input bits, for extractor 1.ext1_output_num_bits (
int
) – Number of output bits, for extractor 1.ext1_raw_bytes (
bytes
) – Initial random numbers, in bytes, for extractor 1.ext1_wsr_bytes (
bytes
) – Initial WSRs, in bytes, for extractor 1.ext2_seed_num_bits (
int
) – Number of bits in the seed, for extractor 2.ext2_wsr_multiplier (
int
) – WSR multiplier, for extractor 2. The number of bits used by extractor 2 is ext2_seed_num_bits*ext2_wsr_multiplier.ext2_wsr_generator (
Optional
[Callable
]) – WSR generator used for extractor 2. It must take the number of bits as the input and a list of random bits (0s and 1s) as the output. IfNone
, :func:generate_wsr
is used.
- Return type
List
[int
]- Returns
An instance of
CQCExtractorJob
which can be used to retrieve the results later.
-
run_async_ext1
(ext1_input_num_bits, ext1_output_num_bits, ext1_raw_bytes, ext1_wsr_bytes)[source]¶ Run the first extractor asynchronously.
- Parameters
ext1_input_num_bits (
int
) – Number of input bits, for extractor 1.ext1_output_num_bits (
int
) – Number of output bits, for extractor 1.ext1_raw_bytes (
bytes
) – Initial random numbers, in bytes, for extractor 1.ext1_wsr_bytes (
bytes
) – Initial WSRs, in bytes, for extractor 1.
- Return type
CQCExtractorJob
- Returns
An instance of
CQCExtractorJob
which can be used to retrieve the results later.- Raises
ValueError – If an invalid argument values are specified.
-
run_async_ext2
(ext2_seed, ext2_seed_num_bits, ext2_wsr_multiplier, ext2_wsr_generator=None)[source]¶ Run the second extractor asynchronously.
- Parameters
ext2_seed (
List
[int
]) – Seed used for extractor 2, such as the output of extractor 1.ext2_seed_num_bits (
int
) – Number of bits in the seed, for extractor 2.ext2_wsr_multiplier (
int
) – WSR multiplier, for extractor 2. The number of bits used by extractor 2 is ext2_seed_num_bits*ext2_wsr_multiplier.ext2_wsr_generator (
Optional
[Callable
]) – WSR generator used for extractor 2. It must take the number of bits as the input and a list of random bits (0s and 1s) as the output. IfNone
, :func:generate_wsr
is used.
- Return type
CQCExtractorJob
- Returns
An instance of
CQCExtractorJob
which can be used to retrieve the results later.- Raises
ValueError – If an invalid argument values are specified.