code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def measure_qubits(self, ids): """ Measure the qubits with IDs ids and return a list of measurement outcomes (True/False). Args: ids (list<int>): List of qubit IDs to measure. Returns: List of measurement results (containing either True or False). """ ...
Measure the qubits with IDs ids and return a list of measurement outcomes (True/False). Args: ids (list<int>): List of qubit IDs to measure. Returns: List of measurement results (containing either True or False).
measure_qubits
python
ProjectQ-Framework/ProjectQ
projectq/backends/_unitary.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_unitary.py
Apache-2.0
def __init__( self, use_hardware=False, num_runs=100, verbose=False, token='', device='simulator', num_retries=3000, interval=1, retrieve_execution=None, ): # pylint: disable=too-many-arguments """ Initialize the Backend object...
Initialize the Backend object. Args: use_hardware (bool): If True, the code is run on the AQT quantum chip (instead of using the AQT simulator) num_runs (int): Number of runs to collect statistics. (default is 100, max is usually around 200) verbose (bool): If True...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def is_available(self, cmd): """ Return true if the command can be executed. The AQT ion trap can only do Rx,Ry and Rxx. Args: cmd (Command): Command for which to check availability """ if get_control_count(cmd) == 0: if isinstance(cmd.gate, (Rx,...
Return true if the command can be executed. The AQT ion trap can only do Rx,Ry and Rxx. Args: cmd (Command): Command for which to check availability
is_available
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def _reset(self): """Reset all temporary variables (after flush gate).""" self._clear = True self._measured_ids = []
Reset all temporary variables (after flush gate).
_reset
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def _store(self, cmd): """ Temporarily store the command cmd. Translates the command and stores it in a local variable (self._cmds). Args: cmd: Command to store """ if self._clear: self._probabilities = {} self._clear = False ...
Temporarily store the command cmd. Translates the command and stores it in a local variable (self._cmds). Args: cmd: Command to store
_store
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def _logical_to_physical(self, qb_id): """ Return the physical location of the qubit with the given logical id. If no mapper is present then simply returns the qubit ID. Args: qb_id (int): ID of the logical qubit whose position should be returned. """ try: ...
Return the physical location of the qubit with the given logical id. If no mapper is present then simply returns the qubit ID. Args: qb_id (int): ID of the logical qubit whose position should be returned.
_logical_to_physical
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def get_probabilities(self, qureg): """ Return the probability of the outcome `bit_string` when measuring the quantum register `qureg`. Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register used for the experiment, then returns the...
Return the probability of the outcome `bit_string` when measuring the quantum register `qureg`. Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register used for the experiment, then returns the projected probabilities over the other states....
get_probabilities
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def _run(self): """ Run the circuit. Send the circuit via the AQT API using the provided user token / ask for the user token. """ # finally: measurements # NOTE AQT DOESN'T SEEM TO HAVE MEASUREMENT INSTRUCTIONS (no # intermediate measurements are allowed, so impl...
Run the circuit. Send the circuit via the AQT API using the provided user token / ask for the user token.
_run
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a command list and, for each command, stores it until completion. Upon flush, send the data to the AQT API. Args: command_list: List of commands to execute """ for cmd in comman...
Receive a list of commands. Receive a command list and, for each command, stores it until completion. Upon flush, send the data to the AQT API. Args: command_list: List of commands to execute
receive
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py
Apache-2.0
def __init__(self): """Initialize an AQT session with AQT's APIs.""" super().__init__() self.backends = {} self.timeout = 5.0 self.token = None
Initialize an AQT session with AQT's APIs.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def update_devices_list(self, verbose=False): """ Update the internal device list. Returns: (list): list of available devices Note: Up to my knowledge there is no proper API call for online devices, so we just assume that the list from AQT portal alw...
Update the internal device list. Returns: (list): list of available devices Note: Up to my knowledge there is no proper API call for online devices, so we just assume that the list from AQT portal always up to date
update_devices_list
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def can_run_experiment(self, info, device): """ Check if the device is big enough to run the code. Args: info (dict): dictionary sent by the backend containing the code to run device (str): name of the aqt device to use Returns: (bool)...
Check if the device is big enough to run the code. Args: info (dict): dictionary sent by the backend containing the code to run device (str): name of the aqt device to use Returns: (bool): True if device is big enough, False otherwise ...
can_run_experiment
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def authenticate(self, token=None): """ Authenticate with the AQT Web API. Args: token (str): AQT user API token. """ if token is None: token = getpass.getpass(prompt='AQT token > ') self.headers.update({'Ocp-Apim-Subscription-Key': token, 'SDK': ...
Authenticate with the AQT Web API. Args: token (str): AQT user API token.
authenticate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def get_result( # pylint: disable=too-many-arguments self, device, execution_id, num_retries=3000, interval=1, verbose=False ): """Get the result of an execution.""" if verbose: print(f"Waiting for results. [Job ID: {execution_id}]") original_sigint_handler = signal.get...
Get the result of an execution.
get_result
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def show_devices(verbose=False): """ Access the list of available devices and their properties (ex: for setup configuration). Args: verbose (bool): If True, additional information is printed Returns: (list) list of available devices and their properties """ aqt_session = AQT() ...
Access the list of available devices and their properties (ex: for setup configuration). Args: verbose (bool): If True, additional information is printed Returns: (list) list of available devices and their properties
show_devices
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def retrieve(device, token, jobid, num_retries=3000, interval=1, verbose=False): # pylint: disable=too-many-arguments """ Retrieve a previously run job by its ID. Args: device (str): Device on which the code was run / is running. token (str): AQT user API token. jobid (str): Id of ...
Retrieve a previously run job by its ID. Args: device (str): Device on which the code was run / is running. token (str): AQT user API token. jobid (str): Id of the job to retrieve Returns: (list) samples form the AQT server
retrieve
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def send( info, device='aqt_simulator', token=None, num_retries=100, interval=1, verbose=False, ): # pylint: disable=too-many-arguments """ Send circuit through the AQT API and runs the quantum circuit. Args: info(dict): Contains representation of the circuit to run. ...
Send circuit through the AQT API and runs the quantum circuit. Args: info(dict): Contains representation of the circuit to run. device (str): name of the aqt device. Simulator chosen by default token (str): AQT user API token. verbose (bool): If True, additional information is ...
send
python
ProjectQ-Framework/ProjectQ
projectq/backends/_aqt/_aqt_http_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py
Apache-2.0
def __init__( self, use_hardware=False, num_runs=1000, verbose=False, credentials=None, s3_folder=None, device='Aspen-8', num_retries=30, interval=1, retrieve_execution=None, ): # pylint: disable=too-many-arguments """ ...
Initialize the Backend object. Args: use_hardware (bool): If True, the code is run on one of the AWS Braket backends, by default on the Rigetti Aspen-8 chip (instead of using the AWS Braket SV1 Simulator) num_runs (int): Number of runs to collect statistics. (d...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def is_available(self, cmd): # pylint: disable=too-many-return-statements,too-many-branches """ Return true if the command can be executed. Depending on the device chosen, the operations available differ. The operations available for the Aspen-8 Rigetti device are: - "cz" = Co...
Return true if the command can be executed. Depending on the device chosen, the operations available differ. The operations available for the Aspen-8 Rigetti device are: - "cz" = Control Z, "xy" = Not available in ProjectQ, "ccnot" = Toffoli (ie. controlled CNOT), "cnot" = C...
is_available
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def _store(self, cmd): # pylint: disable=too-many-branches """ Temporarily store the command cmd. Translates the command and stores it in a local variable (self._circuit) in JSON format. Args: cmd: Command to store """ gate = cmd.gate # Do not clea...
Temporarily store the command cmd. Translates the command and stores it in a local variable (self._circuit) in JSON format. Args: cmd: Command to store
_store
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def _logical_to_physical(self, qb_id): """ Return the physical location of the qubit with the given logical id. Args: qb_id (int): ID of the logical qubit whose position should be returned. """ if self.main_engine.mapper is not None: mapping = self.main_e...
Return the physical location of the qubit with the given logical id. Args: qb_id (int): ID of the logical qubit whose position should be returned.
_logical_to_physical
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def get_probabilities(self, qureg): """ Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register used for the experiment, then returns the projected probabilities over the other states. The measured bits are ordered according ...
Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register used for the experiment, then returns the projected probabilities over the other states. The measured bits are ordered according to the supplied quantum register, i.e., the lef...
get_probabilities
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def _run(self): """ Run the circuit. Send the circuit via the AWS Boto3 SDK. Use the provided Access Key and Secret key or ask for them if not provided """ # NB: the AWS Braket API does not require explicit measurement commands at the end of a circuit; after running ...
Run the circuit. Send the circuit via the AWS Boto3 SDK. Use the provided Access Key and Secret key or ask for them if not provided
_run
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def receive(self, command_list): """ Receives a command list and, for each command, stores it until completion. Args: command_list: List of commands to execute """ for cmd in command_list: if not isinstance(cmd.gate, FlushGate): self._stor...
Receives a command list and, for each command, stores it until completion. Args: command_list: List of commands to execute
receive
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py
Apache-2.0
def __init__(self): """Initialize a session with the AWS Braket Web APIs.""" self.backends = {} self.timeout = 5.0 self._credentials = {} self._s3_folder = []
Initialize a session with the AWS Braket Web APIs.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def authenticate(self, credentials=None): """ Authenticate with AWSBraket Web APIs. Args: credentials (dict): mapping the AWS key credentials as the AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. """ if credentials is None: # pragma: no cover credentials['AWS_ACC...
Authenticate with AWSBraket Web APIs. Args: credentials (dict): mapping the AWS key credentials as the AWS_ACCESS_KEY_ID and AWS_SECRET_KEY.
authenticate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def get_s3_folder(self, s3_folder=None): """ Get the S3 bucket that contains the results. Args: s3_folder (list): contains the S3 bucket and directory to store the results. """ if s3_folder is None: # pragma: no cover s3_bucket = input("Enter the S3 Bucke...
Get the S3 bucket that contains the results. Args: s3_folder (list): contains the S3 bucket and directory to store the results.
get_s3_folder
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def get_list_devices(self, verbose=False): """ Get the list of available devices with their basic properties. Args: verbose (bool): print the returned dictionary if True Returns: (dict) backends dictionary by deviceName, containing the qubit size 'nq', the coupl...
Get the list of available devices with their basic properties. Args: verbose (bool): print the returned dictionary if True Returns: (dict) backends dictionary by deviceName, containing the qubit size 'nq', the coupling map 'coupling_map' if applicabl...
get_list_devices
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def is_online(self, device): """ Check if the device is in the list of available backends. Args: device (str): name of the device to check Returns: (bool) True if device is available, False otherwise """ # TODO: Add info for the device if it is a...
Check if the device is in the list of available backends. Args: device (str): name of the device to check Returns: (bool) True if device is available, False otherwise
is_online
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def can_run_experiment(self, info, device): """ Check if the device is big enough to run the code. Args: info (dict): dictionary sent by the backend containing the code to run device (str): name of the device to use Returns: (tuple): (bool) True if d...
Check if the device is big enough to run the code. Args: info (dict): dictionary sent by the backend containing the code to run device (str): name of the device to use Returns: (tuple): (bool) True if device is big enough, False otherwise (int) ...
can_run_experiment
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def run(self, info, device): """ Run the quantum code to the AWS Braket selected device. Args: info (dict): dictionary sent by the backend containing the code to run device (str): name of the device to use Returns: task_arn (str): The Arn of the task...
Run the quantum code to the AWS Braket selected device. Args: info (dict): dictionary sent by the backend containing the code to run device (str): name of the device to use Returns: task_arn (str): The Arn of the task
run
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def _calculate_measurement_probs(measurements): """ Calculate the measurement probabilities . Calculate the measurement probabilities based on the list of measurements for a job sent to a SV1 Braket simulator. Args: measurements (list): list ...
Calculate the measurement probabilities . Calculate the measurement probabilities based on the list of measurements for a job sent to a SV1 Braket simulator. Args: measurements (list): list of measurements Returns: measureme...
_calculate_measurement_probs
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def show_devices(credentials=None, verbose=False): """ Access the list of available devices and their properties (ex: for setup configuration). Args: credentials (dict): Dictionary storing the AWS credentials with keys AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. verbose (bool): If True, additiona...
Access the list of available devices and their properties (ex: for setup configuration). Args: credentials (dict): Dictionary storing the AWS credentials with keys AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. verbose (bool): If True, additional information is printed Returns: (list) list...
show_devices
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def retrieve(credentials, task_arn, num_retries=30, interval=1, verbose=False): """ Retrieve a job/task by its Arn. Args: credentials (dict): Dictionary storing the AWS credentials with keys AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. task_arn (str): The Arn of the task to retrieve Returns:...
Retrieve a job/task by its Arn. Args: credentials (dict): Dictionary storing the AWS credentials with keys AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. task_arn (str): The Arn of the task to retrieve Returns: (dict) measurement probabilities from the result stored in the S3 folder
retrieve
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def send( # pylint: disable=too-many-branches,too-many-arguments,too-many-locals info, device, credentials, s3_folder, num_retries=30, interval=1, verbose=False ): """ Send circuit through the Boto3 SDK and runs the quantum circuit. Args: info(dict): Contains representation of the circuit to r...
Send circuit through the Boto3 SDK and runs the quantum circuit. Args: info(dict): Contains representation of the circuit to run. device (str): name of the AWS Braket device. credentials (dict): Dictionary storing the AWS credentials with keys AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. ...
send
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client.py
Apache-2.0
def retrieve_devicetypes_setup(request, arntask, creds, results_json, device_value_devicecapabilities): """Retrieve device types value test setup.""" if request.param == "qpu": body_qpu = StreamingBody(StringIO(results_json), len(results_json)) results_dict = { 'ResponseMetadata': { ...
Retrieve device types value test setup.
retrieve_devicetypes_setup
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client_test_fixtures.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client_test_fixtures.py
Apache-2.0
def send_too_many_setup(creds, s3_folder, search_value, device_value): """Send too many value test setup.""" info_too_much = { 'circuit': '{"braketSchemaHeader":' '{"name": "braket.ir.jaqcd.program", "version": "1"}, ' '"results": [], "basis_rotation_instructions": [], ' '"instru...
Send too many value test setup.
send_too_many_setup
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client_test_fixtures.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client_test_fixtures.py
Apache-2.0
def real_device_online_setup( arntask, creds, s3_folder, info, search_value, device_value, res_completed, results_json, ): """Real device online value test setup.""" qtarntask = {'quantumTaskArn': arntask} body = StreamingBody(StringIO(results_json), len(results_json)) re...
Real device online value test setup.
real_device_online_setup
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_boto3_client_test_fixtures.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_boto3_client_test_fixtures.py
Apache-2.0
def mapper(request): """ Adds a mapper which changes qubit ids by adding 1 """ if request.param == "mapper": class TrivialMapper(BasicMapperEngine): def __init__(self): super().__init__() self.current_mapping = {} def receive(self, comman...
Adds a mapper which changes qubit ids by adding 1
mapper
python
ProjectQ-Framework/ProjectQ
projectq/backends/_awsbraket/_awsbraket_test.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket_test.py
Apache-2.0
def _reset(self): """ Reset this backend. Note: This sets ``_clear = True``, which will trigger state cleanup on the next call to ``_store``. """ # Lastly, reset internal state for measured IDs and circuit body. self._circuit = None self._clear = True
Reset this backend. Note: This sets ``_clear = True``, which will trigger state cleanup on the next call to ``_store``.
_reset
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum.py
Apache-2.0
def _store(self, cmd): # pylint: disable=too-many-branches """ Temporarily store the command cmd. Translates the command and stores it in a local variable (self._cmds). Args: cmd (Command): Command to store """ if self._clear: self._probabilitie...
Temporarily store the command cmd. Translates the command and stores it in a local variable (self._cmds). Args: cmd (Command): Command to store
_store
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum.py
Apache-2.0
def is_available(self, cmd): """ Test if this backend is available to process the provided command. Args: cmd (Command): A command to process. Returns: bool: If this backend can process the command. """ if self._provider_id == IONQ_PROVIDER_ID: ...
Test if this backend is available to process the provided command. Args: cmd (Command): A command to process. Returns: bool: If this backend can process the command.
is_available
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum.py
Apache-2.0
def get_probability(self, state, qureg): """Shortcut to get a specific state's probability. Args: state (str): A state in bit-string format. qureg (Qureg): A ProjectQ Qureg object. Returns: float: The probability for the provided state. """ i...
Shortcut to get a specific state's probability. Args: state (str): A state in bit-string format. qureg (Qureg): A ProjectQ Qureg object. Returns: float: The probability for the provided state.
get_probability
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum.py
Apache-2.0
def get_probabilities(self, qureg): """ Given the provided qubit register, determine the probability of each possible outcome. Note: This method should only be called *after* a circuit has been run and its results are available. Args: qureg (Qureg): A ProjectQ Q...
Given the provided qubit register, determine the probability of each possible outcome. Note: This method should only be called *after* a circuit has been run and its results are available. Args: qureg (Qureg): A ProjectQ Qureg object. Returns: dict...
get_probabilities
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum.py
Apache-2.0
def _run(self): # pylint: disable=too-many-locals """Run the circuit this object has built during engine execution.""" # Nothing to do with an empty circuit. if not self._circuit: return if self._retrieve_execution is None: res = send( input_data...
Run the circuit this object has built during engine execution.
_run
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum.py
Apache-2.0
def retrieve(job_id, target, num_retries=100, interval=1, verbose=False): """ Retrieve a job from Azure Quantum. Args: job_id (str), Azure Quantum job id. target (Target), The target job runs on. num_retries (int, optional): Number of times to retry while the job is not ...
Retrieve a job from Azure Quantum. Args: job_id (str), Azure Quantum job id. target (Target), The target job runs on. num_retries (int, optional): Number of times to retry while the job is not finished. Defaults to 100. interval (int, optional): Sleep interval betwe...
retrieve
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_azure_quantum_client.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_azure_quantum_client.py
Apache-2.0
def is_available_ionq(cmd): """ Test if IonQ backend is available to process the provided command. Args: cmd (Command): A command to process. Returns: bool: If this backend can process the command. """ gate = cmd.gate if has_negative_control(cmd): return False ...
Test if IonQ backend is available to process the provided command. Args: cmd (Command): A command to process. Returns: bool: If this backend can process the command.
is_available_ionq
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_utils.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_utils.py
Apache-2.0
def is_available_quantinuum(cmd): """ Test if Quantinuum backend is available to process the provided command. Args: cmd (Command): A command to process. Returns: bool: If this backend can process the command. """ gate = cmd.gate if has_negative_control(cmd): retur...
Test if Quantinuum backend is available to process the provided command. Args: cmd (Command): A command to process. Returns: bool: If this backend can process the command.
is_available_quantinuum
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_utils.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_utils.py
Apache-2.0
def to_json(cmd): """ Convert ProjectQ command to JSON format. Args: cmd (Command): A command to process. Returns: dict: JSON format of given command. """ # Invalid command, raise exception if not is_available_ionq(cmd): raise InvalidCommandError('Invalid command:',...
Convert ProjectQ command to JSON format. Args: cmd (Command): A command to process. Returns: dict: JSON format of given command.
to_json
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_utils.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_utils.py
Apache-2.0
def to_qasm(cmd): # pylint: disable=too-many-return-statements,too-many-branches """ Convert ProjectQ command to QASM format. Args: cmd (Command): A command to process. Returns: dict: QASM format of given command. """ # Invalid command, raise exception if not is_available_...
Convert ProjectQ command to QASM format. Args: cmd (Command): A command to process. Returns: dict: QASM format of given command.
to_qasm
python
ProjectQ-Framework/ProjectQ
projectq/backends/_azure/_utils.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_azure/_utils.py
Apache-2.0
def __init__(self, gate, lines, ctrl_lines): """ Initialize a circuit item. Args: gate: Gate object. lines (list<int>): Circuit lines the gate acts on. ctrl_lines (list<int>): Circuit lines which control the gate. """ self.gate = gate ...
Initialize a circuit item. Args: gate: Gate object. lines (list<int>): Circuit lines the gate acts on. ctrl_lines (list<int>): Circuit lines which control the gate.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def __init__(self, accept_input=False, default_measure=0): """ Initialize a circuit drawing engine. The TikZ code generator uses a settings file (settings.json), which can be altered by the user. It contains gate widths, heights, offsets, etc. Args: accept_input (bo...
Initialize a circuit drawing engine. The TikZ code generator uses a settings file (settings.json), which can be altered by the user. It contains gate widths, heights, offsets, etc. Args: accept_input (bool): If accept_input is true, the printer queries the user to input me...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def is_available(self, cmd): """ Test whether a Command is supported by a compiler engine. Specialized implementation of is_available: Returns True if the CircuitDrawer is the last engine (since it can print any command). Args: cmd (Command): Command for which to ch...
Test whether a Command is supported by a compiler engine. Specialized implementation of is_available: Returns True if the CircuitDrawer is the last engine (since it can print any command). Args: cmd (Command): Command for which to check availability (all Commands can be pr...
is_available
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def set_qubit_locations(self, id_to_loc): """ Set the qubit lines to use for the qubits explicitly. To figure out the qubit IDs, simply use the setting `draw_id` in the settings file. It is located in "gates":"AllocateQubitGate". If draw_id is True, the qubit IDs are drawn in red. ...
Set the qubit lines to use for the qubits explicitly. To figure out the qubit IDs, simply use the setting `draw_id` in the settings file. It is located in "gates":"AllocateQubitGate". If draw_id is True, the qubit IDs are drawn in red. Args: id_to_loc (dict): Dictionary m...
set_qubit_locations
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def _print_cmd(self, cmd): """ Add a command to the list of commands to be printed. Add the command cmd to the circuit diagram, taking care of potential measurements as specified in the __init__ function. Queries the user for measurement input if a measurement command arrives i...
Add a command to the list of commands to be printed. Add the command cmd to the circuit diagram, taking care of potential measurements as specified in the __init__ function. Queries the user for measurement input if a measurement command arrives if accept_input was set to True...
_print_cmd
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def get_latex(self, ordered=False, draw_gates_in_parallel=True): """ Return the latex document string representing the circuit. Simply write this string into a tex-file or, alternatively, pipe the output directly to, e.g., pdflatex: .. code-block:: bash python3 my_...
Return the latex document string representing the circuit. Simply write this string into a tex-file or, alternatively, pipe the output directly to, e.g., pdflatex: .. code-block:: bash python3 my_circuit.py | pdflatex where my_circuit.py calls this function and p...
get_latex
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a list of commands from the previous engine, print the commands, and then send them on to the next engine. Args: command_list (list<Command>): List of Commands to print (and potentially send on...
Receive a list of commands. Receive a list of commands from the previous engine, print the commands, and then send them on to the next engine. Args: command_list (list<Command>): List of Commands to print (and potentially send on to the next engine).
receive
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer.py
Apache-2.0
def __init__(self, accept_input=False, default_measure=0): """ Initialize a circuit drawing engine(mpl). Args: accept_input (bool): If accept_input is true, the printer queries the user to input measurement results if the CircuitDrawerMPL is the last engine. Otherwis...
Initialize a circuit drawing engine(mpl). Args: accept_input (bool): If accept_input is true, the printer queries the user to input measurement results if the CircuitDrawerMPL is the last engine. Otherwise, all measurements yield the result default_measure (...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer_matplotlib.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer_matplotlib.py
Apache-2.0
def is_available(self, cmd): """ Test whether a Command is supported by a compiler engine. Specialized implementation of is_available: Returns True if the CircuitDrawerMatplotlib is the last engine (since it can print any command). Args: cmd (Command): Command for w...
Test whether a Command is supported by a compiler engine. Specialized implementation of is_available: Returns True if the CircuitDrawerMatplotlib is the last engine (since it can print any command). Args: cmd (Command): Command for which to check availability (all Commands...
is_available
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer_matplotlib.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer_matplotlib.py
Apache-2.0
def _process(self, cmd): # pylint: disable=too-many-branches """ Process the command cmd and stores it in the internal storage. Queries the user for measurement input if a measurement command arrives if accept_input was set to True. Otherwise, it uses the default_measure parameter to r...
Process the command cmd and stores it in the internal storage. Queries the user for measurement input if a measurement command arrives if accept_input was set to True. Otherwise, it uses the default_measure parameter to register the measurement outcome. Args: cmd (Command)...
_process
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer_matplotlib.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer_matplotlib.py
Apache-2.0
def draw(self, qubit_labels=None, drawing_order=None, **kwargs): """ Generate and returns the plot of the quantum circuit stored so far. Args: qubit_labels (dict): label for each wire in the output figure. Keys: qubit IDs, Values: string to print out as label for th...
Generate and returns the plot of the quantum circuit stored so far. Args: qubit_labels (dict): label for each wire in the output figure. Keys: qubit IDs, Values: string to print out as label for that particular qubit wire. drawing_order (dict): position of each...
draw
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_drawer_matplotlib.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_drawer_matplotlib.py
Apache-2.0
def to_draw(qubit_lines, qubit_labels=None, drawing_order=None, **kwargs): """ Translate a given circuit to a matplotlib figure. Args: qubit_lines (dict): list of gates for each qubit axis qubit_labels (dict): label to print in front of the qubit wire for each qubit ID drawing_order...
Translate a given circuit to a matplotlib figure. Args: qubit_lines (dict): list of gates for each qubit axis qubit_labels (dict): label to print in front of the qubit wire for each qubit ID drawing_order (dict): index of the wire for each qubit ID to be drawn. **kwargs (dict):...
to_draw
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def gate_width(axes, gate_str, plot_params): """ Calculate the width of a gate based on its string representation. Args: axes (matplotlib.axes.Axes): axes object gate_str (str): string representation of a gate plot_params (dict): plot parameters Returns: The width of a ...
Calculate the width of a gate based on its string representation. Args: axes (matplotlib.axes.Axes): axes object gate_str (str): string representation of a gate plot_params (dict): plot parameters Returns: The width of a gate on the figure (in inches)
gate_width
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def calculate_gate_grid(axes, qubit_lines, plot_params): """ Calculate an optimal grid spacing for a list of quantum gates. Args: axes (matplotlib.axes.Axes): axes object qubit_lines (dict): list of gates for each qubit axis plot_params (dict): plot parameters Returns: ...
Calculate an optimal grid spacing for a list of quantum gates. Args: axes (matplotlib.axes.Axes): axes object qubit_lines (dict): list of gates for each qubit axis plot_params (dict): plot parameters Returns: An array (np.ndarray) with the gate x positions.
calculate_gate_grid
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def text(axes, gate_pos, wire_pos, textstr, plot_params): """ Draw a text box on the figure. Args: axes (matplotlib.axes.Axes): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire textstr (str): text of the gat...
Draw a text box on the figure. Args: axes (matplotlib.axes.Axes): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire textstr (str): text of the gate and box plot_params (dict): plot parameters box...
text
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def create_figure(plot_params): """ Create a new figure as well as a new axes instance. Args: plot_params (dict): plot parameters Returns: A tuple with (figure, axes) """ fig = plt.figure(facecolor='w', edgecolor='w') axes = plt.axes() axes.set_axis_off() axes.set_a...
Create a new figure as well as a new axes instance. Args: plot_params (dict): plot parameters Returns: A tuple with (figure, axes)
create_figure
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_gates( # pylint: disable=too-many-arguments axes, qubit_lines, drawing_order, gate_grid, wire_grid, plot_params ): """ Draw the gates. Args: qubit_lines (dict): list of gates for each qubit axis drawing_order (dict): index of the wire for each qubit ID to be drawn gate...
Draw the gates. Args: qubit_lines (dict): list of gates for each qubit axis drawing_order (dict): index of the wire for each qubit ID to be drawn gate_grid (np.ndarray): x positions of the gates wire_grid (np.ndarray): y positions of the qubit wires plot_params (dict): ...
draw_gates
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_gate( axes, gate_str, gate_pos, target_wires, targets_order, control_wires, plot_params ): # pylint: disable=too-many-arguments """ Draw a single gate at a given location. Args: axes (AxesSubplot): axes object gate_str (str): string representation of a gate gate_pos (f...
Draw a single gate at a given location. Args: axes (AxesSubplot): axes object gate_str (str): string representation of a gate gate_pos (float): x coordinate of the gate [data units] target_wires (list): y coordinates of the target qubits targets_order (list): index of t...
draw_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_generic_gate(axes, gate_pos, wire_pos, gate_str, plot_params): """ Draw a measurement gate. Args: axes (AxesSubplot): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire gate_str (str) : string represe...
Draw a measurement gate. Args: axes (AxesSubplot): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire gate_str (str) : string representation of a gate plot_params (dict): plot parameters
draw_generic_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_measure_gate(axes, gate_pos, wire_pos, plot_params): """ Draw a measurement gate. Args: axes (AxesSubplot): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire plot_params (dict): plot parameters "...
Draw a measurement gate. Args: axes (AxesSubplot): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire plot_params (dict): plot parameters
draw_measure_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def multi_qubit_gate( # pylint: disable=too-many-arguments axes, gate_str, gate_pos, wire_pos_min, wire_pos_max, plot_params ): """ Draw a multi-target qubit gate. Args: axes (matplotlib.axes.Axes): axes object gate_str (str): string representation of a gate gate_pos (float): x...
Draw a multi-target qubit gate. Args: axes (matplotlib.axes.Axes): axes object gate_str (str): string representation of a gate gate_pos (float): x coordinate of the gate [data units] wire_pos_min (float): y coordinate of the lowest qubit wire wire_pos_max (float): y coo...
multi_qubit_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_x_gate(axes, gate_pos, wire_pos, plot_params): """ Draw the symbol for a X/NOT gate. Args: axes (matplotlib.axes.Axes): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire [data units] plot_params (dic...
Draw the symbol for a X/NOT gate. Args: axes (matplotlib.axes.Axes): axes object gate_pos (float): x coordinate of the gate [data units] wire_pos (float): y coordinate of the qubit wire [data units] plot_params (dict): plot parameters
draw_x_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_control_z_gate(axes, gate_pos, wire_pos1, wire_pos2, plot_params): """ Draw the symbol for a controlled-Z gate. Args: axes (matplotlib.axes.Axes): axes object wire_pos (float): x coordinate of the gate [data units] y1 (float): y coordinate of the 1st qubit wire y2 (...
Draw the symbol for a controlled-Z gate. Args: axes (matplotlib.axes.Axes): axes object wire_pos (float): x coordinate of the gate [data units] y1 (float): y coordinate of the 1st qubit wire y2 (float): y coordinate of the 2nd qubit wire plot_params (dict): plot paramet...
draw_control_z_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_swap_gate(axes, gate_pos, wire_pos1, wire_pos2, plot_params): """ Draw the symbol for a SWAP gate. Args: axes (matplotlib.axes.Axes): axes object x (float): x coordinate [data units] y1 (float): y coordinate of the 1st qubit wire y2 (float): y coordinate of the 2nd ...
Draw the symbol for a SWAP gate. Args: axes (matplotlib.axes.Axes): axes object x (float): x coordinate [data units] y1 (float): y coordinate of the 1st qubit wire y2 (float): y coordinate of the 2nd qubit wire plot_params (dict): plot parameters
draw_swap_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_wires(axes, n_labels, gate_grid, wire_grid, plot_params): """ Draw all the circuit qubit wires. Args: axes (matplotlib.axes.Axes): axes object n_labels (int): number of qubit gate_grid (ndarray): array with the ref. x positions of the gates wire_grid (ndarray): arra...
Draw all the circuit qubit wires. Args: axes (matplotlib.axes.Axes): axes object n_labels (int): number of qubit gate_grid (ndarray): array with the ref. x positions of the gates wire_grid (ndarray): array with the ref. y positions of the qubit wires plot_params (dict):...
draw_wires
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def draw_labels(axes, qubit_labels, drawing_order, wire_grid, plot_params): """ Draw the labels at the start of each qubit wire. Args: axes (matplotlib.axes.Axes): axes object qubit_labels (list): labels of the qubit to be drawn drawing_order (dict): Mapping between wire indices and...
Draw the labels at the start of each qubit wire. Args: axes (matplotlib.axes.Axes): axes object qubit_labels (list): labels of the qubit to be drawn drawing_order (dict): Mapping between wire indices and qubit IDs gate_grid (ndarray): array with the ref. x positions of the gate...
draw_labels
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_plot.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_plot.py
Apache-2.0
def _gate_name(gate): """ Return the string representation of the gate. Tries to use gate.tex_str and, if that is not available, uses str(gate) instead. Args: gate: Gate object of which to get the name / latex representation. Returns: gate_name (string): Latex gate name. """ ...
Return the string representation of the gate. Tries to use gate.tex_str and, if that is not available, uses str(gate) instead. Args: gate: Gate object of which to get the name / latex representation. Returns: gate_name (string): Latex gate name.
_gate_name
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def to_latex(circuit, drawing_order=None, draw_gates_in_parallel=True): """ Translate a given circuit to a TikZ picture in a Latex document. It uses a json-configuration file which (if it does not exist) is created automatically upon running this function for the first time. The config file can be used...
Translate a given circuit to a TikZ picture in a Latex document. It uses a json-configuration file which (if it does not exist) is created automatically upon running this function for the first time. The config file can be used to determine custom gate sizes, offsets, etc. New gate options can be add...
to_latex
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def write_settings(settings): """ Write all settings to a json-file. Args: settings (dict): Settings dict to write. """ with open('settings.json', 'w') as settings_file: json.dump(settings, settings_file, sort_keys=True, indent=4) return settings
Write all settings to a json-file. Args: settings (dict): Settings dict to write.
write_settings
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def get_default_settings(): """ Return the default settings for the circuit drawing function to_latex(). Returns: settings (dict): Default circuit settings """ settings = {} settings['gate_shadow'] = True settings['lines'] = { 'style': 'very thin', 'double_classical'...
Return the default settings for the circuit drawing function to_latex(). Returns: settings (dict): Default circuit settings
get_default_settings
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _header(settings): """ Write the Latex header using the settings file. The header includes all packages and defines all tikz styles. Returns: header (string): Header of the Latex document. """ packages = ( "\\documentclass{standalone}\n\\usepackage[margin=1in]" "{ge...
Write the Latex header using the settings file. The header includes all packages and defines all tikz styles. Returns: header (string): Header of the Latex document.
_header
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _body(circuit, settings, drawing_order=None, draw_gates_in_parallel=True): """ Return the body of the Latex document, including the entire circuit in TikZ format. Args: circuit (list<list<CircuitItem>>): Circuit to draw. settings: Dictionary of settings to use for the TikZ image. ...
Return the body of the Latex document, including the entire circuit in TikZ format. Args: circuit (list<list<CircuitItem>>): Circuit to draw. settings: Dictionary of settings to use for the TikZ image. drawing_order: A list of circuit wires from where to read one gate command. ...
_body
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def __init__(self, settings, num_lines): """ Initialize a circuit to latex converter object. Args: settings (dict): Dictionary of settings to use for the TikZ image. num_lines (int): Number of qubit lines to use for the entire circuit. """ ...
Initialize a circuit to latex converter object. Args: settings (dict): Dictionary of settings to use for the TikZ image. num_lines (int): Number of qubit lines to use for the entire circuit.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def to_tikz( # pylint: disable=too-many-branches,too-many-locals,too-many-statements self, line, circuit, end=None, draw_gates_in_parallel=True ): """ Generate the TikZ code for one line of the circuit up to a certain gate. It modifies the circuit to include only the gates which ha...
Generate the TikZ code for one line of the circuit up to a certain gate. It modifies the circuit to include only the gates which have not been drawn. It automatically switches to other lines if the gates on those lines have to be drawn earlier. Args: line (int): Line to ge...
to_tikz
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _sqrtswap_gate(self, lines, ctrl_lines, daggered): # pylint: disable=too-many-locals """ Return the TikZ code for a Square-root Swap-gate. Args: lines (list<int>): List of length 2 denoting the target qubit of the Swap gate. ctrl_lines (list<int>): L...
Return the TikZ code for a Square-root Swap-gate. Args: lines (list<int>): List of length 2 denoting the target qubit of the Swap gate. ctrl_lines (list<int>): List of qubit lines which act as controls. daggered (bool): Show the daggered one if True....
_sqrtswap_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _swap_gate(self, lines, ctrl_lines): # pylint: disable=too-many-locals """ Return the TikZ code for a Swap-gate. Args: lines (list<int>): List of length 2 denoting the target qubit of the Swap gate. ctrl_lines (list<int>): List of qubit lines which a...
Return the TikZ code for a Swap-gate. Args: lines (list<int>): List of length 2 denoting the target qubit of the Swap gate. ctrl_lines (list<int>): List of qubit lines which act as controls.
_swap_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _x_gate(self, lines, ctrl_lines): """ Return the TikZ code for a NOT-gate. Args: lines (list<int>): List of length 1 denoting the target qubit of the NOT / X gate. ctrl_lines (list<int>): List of qubit lines which act as controls. """ ...
Return the TikZ code for a NOT-gate. Args: lines (list<int>): List of length 1 denoting the target qubit of the NOT / X gate. ctrl_lines (list<int>): List of qubit lines which act as controls.
_x_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _cz_gate(self, lines): """ Return the TikZ code for an n-controlled Z-gate. Args: lines (list<int>): List of all qubits involved. """ line = lines[0] delta_pos = self._gate_offset(Z) gate_width = self._gate_width(Z) gate_str = self._phase(...
Return the TikZ code for an n-controlled Z-gate. Args: lines (list<int>): List of all qubits involved.
_cz_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _gate_width(self, gate): """ Return the gate width, using the settings (if available). Returns: gate_width (float): Width of the gate. (settings['gates'][gate_class_name]['width']) """ if isinstance(gate, DaggeredGate): gate = gate._ga...
Return the gate width, using the settings (if available). Returns: gate_width (float): Width of the gate. (settings['gates'][gate_class_name]['width'])
_gate_width
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _gate_pre_offset(self, gate): """ Return the offset to use before placing this gate. Returns: gate_pre_offset (float): Offset to use before the gate. (settings['gates'][gate_class_name]['pre_offset']) """ if isinstance(gate, DaggeredGate): ...
Return the offset to use before placing this gate. Returns: gate_pre_offset (float): Offset to use before the gate. (settings['gates'][gate_class_name]['pre_offset'])
_gate_pre_offset
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _gate_offset(self, gate): """ Return the offset to use after placing this gate. If no pre_offset is defined, the same offset is used in front of the gate. Returns: gate_offset (float): Offset. (settings['gates'][gate_class_name]['offset']) """ if isinst...
Return the offset to use after placing this gate. If no pre_offset is defined, the same offset is used in front of the gate. Returns: gate_offset (float): Offset. (settings['gates'][gate_class_name]['offset'])
_gate_offset
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _gate_height(self, gate): """ Return the height to use for this gate. Returns: gate_height (float): Height of the gate. (settings['gates'][gate_class_name]['height']) """ if isinstance(gate, DaggeredGate): gate = gate._gate # pylint: ...
Return the height to use for this gate. Returns: gate_height (float): Height of the gate. (settings['gates'][gate_class_name]['height'])
_gate_height
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _op(self, line, op=None, offset=0): """ Return the gate name for placing a gate on a line. Args: line (int): Line number. op (int): Operation number or, by default, uses the current op count. Returns: op_str (string): Gate name. ...
Return the gate name for placing a gate on a line. Args: line (int): Line number. op (int): Operation number or, by default, uses the current op count. Returns: op_str (string): Gate name.
_op
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _line(self, point1, point2, double=False, line=None): # pylint: disable=too-many-locals,unused-argument """ Create a line that connects two points. Connects point1 and point2, where point1 and point2 are either to qubit line indices, in which case the two most recent gates are conn...
Create a line that connects two points. Connects point1 and point2, where point1 and point2 are either to qubit line indices, in which case the two most recent gates are connected, or two gate indices, in which case line denotes the line number and the two gates are connected on the gi...
_line
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def _regular_gate(self, gate, lines, ctrl_lines): # pylint: disable=too-many-locals """ Draw a regular gate. Args: gate: Gate to draw. lines (list<int>): Lines the gate acts on. ctrl_lines (list<int>): Control lines. Returns: tex_str (st...
Draw a regular gate. Args: gate: Gate to draw. lines (list<int>): Lines the gate acts on. ctrl_lines (list<int>): Control lines. Returns: tex_str (string): Latex string drawing a regular gate at the given location
_regular_gate
python
ProjectQ-Framework/ProjectQ
projectq/backends/_circuits/_to_latex.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_circuits/_to_latex.py
Apache-2.0
def __init__( self, use_hardware=False, num_runs=1024, verbose=False, token='', device='ibmq_essex', num_retries=3000, interval=1, retrieve_execution=None, ): # pylint: disable=too-many-arguments """ Initialize the Backend obje...
Initialize the Backend object. Args: use_hardware (bool): If True, the code is run on the IBM quantum chip (instead of using the IBM simulator) num_runs (int): Number of runs to collect statistics. (default is 1024) verbose (bool): If...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/backends/_ibm/_ibm.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_ibm/_ibm.py
Apache-2.0
def is_available(self, cmd): """ Return true if the command can be executed. The IBM quantum chip can only do U1,U2,U3,barriers, and CX / CNOT. Conversion implemented for Rotation gates and H gates. Args: cmd (Command): Command for which to check availability ...
Return true if the command can be executed. The IBM quantum chip can only do U1,U2,U3,barriers, and CX / CNOT. Conversion implemented for Rotation gates and H gates. Args: cmd (Command): Command for which to check availability
is_available
python
ProjectQ-Framework/ProjectQ
projectq/backends/_ibm/_ibm.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_ibm/_ibm.py
Apache-2.0
def _logical_to_physical(self, qb_id): """ Return the physical location of the qubit with the given logical id. Args: qb_id (int): ID of the logical qubit whose position should be returned. """ mapping = self.main_engine.mapper.current_mapping ...
Return the physical location of the qubit with the given logical id. Args: qb_id (int): ID of the logical qubit whose position should be returned.
_logical_to_physical
python
ProjectQ-Framework/ProjectQ
projectq/backends/_ibm/_ibm.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_ibm/_ibm.py
Apache-2.0
def get_probabilities(self, qureg): """ Return the probability of the outcome `bit_string` when measuring the quantum register `qureg`. Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register used for the experiment, then returns the...
Return the probability of the outcome `bit_string` when measuring the quantum register `qureg`. Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register used for the experiment, then returns the projected probabilities over the other states....
get_probabilities
python
ProjectQ-Framework/ProjectQ
projectq/backends/_ibm/_ibm.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_ibm/_ibm.py
Apache-2.0
def _run(self): # pylint: disable=too-many-locals """ Run the circuit. Send the circuit via a non documented IBM API (using JSON written circuits) using the provided user data / ask for the user token. """ # finally: add measurements (no intermediate measurements are al...
Run the circuit. Send the circuit via a non documented IBM API (using JSON written circuits) using the provided user data / ask for the user token.
_run
python
ProjectQ-Framework/ProjectQ
projectq/backends/_ibm/_ibm.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_ibm/_ibm.py
Apache-2.0