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 _send_qubit_pipeline(self, idx, n_gates): """Send n gate operations of the qubit with index idx to the next engine.""" il = self._l[idx] # pylint: disable=invalid-name for i in range(min(n_gates, len(il))): # loop over first n operations # send all gates before n-qubit gate for...
Send n gate operations of the qubit with index idx to the next engine.
_send_qubit_pipeline
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_optimize.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_optimize.py
Apache-2.0
def _get_gate_indices(self, idx, i, qubit_ids): """ Return all indices of a command. Each index corresponding to the command's index in one of the qubits' command lists. Args: idx (int): qubit index i (int): command position in qubit idx's command list ...
Return all indices of a command. Each index corresponding to the command's index in one of the qubits' command lists. Args: idx (int): qubit index i (int): command position in qubit idx's command list IDs (list<int>): IDs of all qubits involved in the comma...
_get_gate_indices
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_optimize.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_optimize.py
Apache-2.0
def _optimize(self, idx, lim=None): """ Gate cancellation routine. Try to remove identity gates using the is_identity function, then merge or even cancel successive gates using the get_merged and get_inverse functions of the gate (see, e.g., BasicRotationGate). It does so for a...
Gate cancellation routine. Try to remove identity gates using the is_identity function, then merge or even cancel successive gates using the get_merged and get_inverse functions of the gate (see, e.g., BasicRotationGate). It does so for all qubit command lists.
_optimize
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_optimize.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_optimize.py
Apache-2.0
def _check_and_send(self): """Check whether a qubit pipeline must be sent on and, if so, optimize the pipeline and then send it on.""" # NB: self.optimize(i) modifies self._l for i in self._l: # pylint: disable=consider-using-dict-items if ( len(self._l[i]) >= self._...
Check whether a qubit pipeline must be sent on and, if so, optimize the pipeline and then send it on.
_check_and_send
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_optimize.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_optimize.py
Apache-2.0
def _cache_cmd(self, cmd): """Cache a command, i.e., inserts it into the command lists of all qubits involved.""" # are there qubit ids that haven't been added to the list? idlist = [qubit.id for sublist in cmd.all_qubits for qubit in sublist] # add gate command to each of the qubits in...
Cache a command, i.e., inserts it into the command lists of all qubits involved.
_cache_cmd
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_optimize.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_optimize.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive commands from the previous engine and cache them. If a flush gate arrives, the entire buffer is sent on. """ for cmd in command_list: if cmd.gate == FlushGate(): # flush gate --> optim...
Receive a list of commands. Receive commands from the previous engine and cache them. If a flush gate arrives, the entire buffer is sent on.
receive
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_optimize.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_optimize.py
Apache-2.0
def __init__(self, connectivity): """ Initialize the engine. Args: connectivity (set): Set of tuples (c, t) where if (c, t) is an element of the set means that a CNOT can be performed between the physical ids (c, t) with c being the control and t being the target qub...
Initialize the engine. Args: connectivity (set): Set of tuples (c, t) where if (c, t) is an element of the set means that a CNOT can be performed between the physical ids (c, t) with c being the control and t being the target qubit.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_swapandcnotflipper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_swapandcnotflipper.py
Apache-2.0
def _needs_flipping(self, cmd): """ Return True if cmd is a CNOT which needs to be flipped around. Args: cmd (Command): Command to check """ if not self._is_cnot(cmd): return False target = cmd.qubits[0][0].id control = cmd.control_qubits...
Return True if cmd is a CNOT which needs to be flipped around. Args: cmd (Command): Command to check
_needs_flipping
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_swapandcnotflipper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_swapandcnotflipper.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a command list and if the command is a CNOT gate, it flips it using Hadamard gates if necessary; if it is a Swap gate, it decomposes it using 3 CNOTs. All other gates are simply sent to the next engine. Ar...
Receive a list of commands. Receive a command list and if the command is a CNOT gate, it flips it using Hadamard gates if necessary; if it is a Swap gate, it decomposes it using 3 CNOTs. All other gates are simply sent to the next engine. Args: command_list (list of Comman...
receive
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_swapandcnotflipper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_swapandcnotflipper.py
Apache-2.0
def __init__(self, tags=None): """ Initialize a TagRemover object. Args: tags: A list of meta tag classes (e.g., [ComputeTag, UncomputeTag]) denoting the tags to remove """ super().__init__() if not tags: self._tags = [ComputeTag, ...
Initialize a TagRemover object. Args: tags: A list of meta tag classes (e.g., [ComputeTag, UncomputeTag]) denoting the tags to remove
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_tagremover.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_tagremover.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a list of commands from the previous engine, remove all tags which are an instance of at least one of the meta tags provided in the constructor, and then send them on to the next compiler engine. Args: ...
Receive a list of commands. Receive a list of commands from the previous engine, remove all tags which are an instance of at least one of the meta tags provided in the constructor, and then send them on to the next compiler engine. Args: command_list (list<Command>): List ...
receive
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_tagremover.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_tagremover.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a command list and, for each command, stores it inside the cache before sending it to the next compiler engine. Args: command_list (list of Command objects): list of commands to receive. ...
Receive a list of commands. Receive a command list and, for each command, stores it inside the cache before sending it to the next compiler engine. Args: command_list (list of Command objects): list of commands to receive.
receive
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_testengine.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_testengine.py
Apache-2.0
def __init__(self, save_commands=False): """ Initialize a DummyEngine. Args: save_commands (default = False): If True, commands are saved in self.received_commands. """ super().__init__() self.save_commands = save_...
Initialize a DummyEngine. Args: save_commands (default = False): If True, commands are saved in self.received_commands.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_testengine.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_testengine.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a command list and, for each command, stores it internally if requested before sending it to the next compiler engine. Args: command_list (list of Command objects): list of commands to receive....
Receive a list of commands. Receive a command list and, for each command, stores it internally if requested before sending it to the next compiler engine. Args: command_list (list of Command objects): list of commands to receive.
receive
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_testengine.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_testengine.py
Apache-2.0
def __init__( # pylint: disable=too-many-arguments self, num_rows, num_columns, mapped_ids_to_backend_ids=None, storage=1000, optimization_function=return_swap_depth, num_optimization_steps=50, ): """ Initialize a GridMapper compiler engine. ...
Initialize a GridMapper compiler engine. Args: num_rows(int): Number of rows in the grid num_columns(int): Number of columns in the grid. mapped_ids_to_backend_ids(dict): Stores a mapping from mapped ids which are 0,...,self.num_qubits-1 in ...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_twodmapper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_twodmapper.py
Apache-2.0
def is_available(self, cmd): """Only allow 1 or two qubit gates.""" num_qubits = 0 for qureg in cmd.all_qubits: num_qubits += len(qureg) return num_qubits <= 2
Only allow 1 or two qubit gates.
is_available
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_twodmapper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_twodmapper.py
Apache-2.0
def _return_new_mapping(self): """ Return a new mapping of the qubits. It goes through self._saved_commands and tries to find a mapping to apply these gates on a first come first served basis. It reuses the function of a 1D mapper and creates a mapping for a 1D linear chain and then ...
Return a new mapping of the qubits. It goes through self._saved_commands and tries to find a mapping to apply these gates on a first come first served basis. It reuses the function of a 1D mapper and creates a mapping for a 1D linear chain and then wraps it like a snake onto the squar...
_return_new_mapping
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_twodmapper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_twodmapper.py
Apache-2.0
def _compare_and_swap(self, element0, element1, key): """If swapped (inplace), then return swap operation so that key(element0) < key(element1).""" if key(element0) > key(element1): mapped_id0 = element0.current_column + element0.current_row * self.num_columns mapped_id1 = elemen...
If swapped (inplace), then return swap operation so that key(element0) < key(element1).
_compare_and_swap
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_twodmapper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_twodmapper.py
Apache-2.0
def return_swaps( # pylint: disable=too-many-locals,too-many-branches,too-many-statements self, old_mapping, new_mapping, permutation=None ): """ Return the swap operation to change mapping. Args: old_mapping: dict: keys are logical ids and values are mapped qubit ids ...
Return the swap operation to change mapping. Args: old_mapping: dict: keys are logical ids and values are mapped qubit ids new_mapping: dict: keys are logical ids and values are mapped qubit ids permutation: list of int from 0, 1, ..., self.num_rows-1. It is used to...
return_swaps
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_twodmapper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_twodmapper.py
Apache-2.0
def _send_possible_commands(self): # pylint: disable=too-many-branches """ Send the stored commands possible without changing the mapping. Note: self._current_row_major_mapping (hence also self.current_mapping) must exist already """ active_ids = deepcopy(self._currently_alloca...
Send the stored commands possible without changing the mapping. Note: self._current_row_major_mapping (hence also self.current_mapping) must exist already
_send_possible_commands
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_twodmapper.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_twodmapper.py
Apache-2.0
def test_with_flushing_with_exception(): """Test with flushing() as eng: with an exception raised in the 'with' block.""" try: with flushing(DummyEngine()) as engine: engine.flush = MagicMock() assert engine.flush.call_count == 0 raise ValueError("An exception is rais...
Test with flushing() as eng: with an exception raised in the 'with' block.
test_with_flushing_with_exception
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_withflushing_test.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_withflushing_test.py
Apache-2.0
def flushing(engine): """ Context manager to flush the given engine at the end of the 'with' context block. Example: with flushing(MainEngine()) as eng: qubit = eng.allocate_qubit() ... Calling 'eng.flush()' is no longer needed because the engine will be flushed at the ...
Context manager to flush the given engine at the end of the 'with' context block. Example: with flushing(MainEngine()) as eng: qubit = eng.allocate_qubit() ... Calling 'eng.flush()' is no longer needed because the engine will be flushed at the end of the 'with' block e...
flushing
python
ProjectQ-Framework/ProjectQ
projectq/cengines/__init__.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/__init__.py
Apache-2.0
def __init__(self, gate_class, gate_decomposer, gate_recognizer=lambda cmd: True): """ Initialize a DecompositionRule object. Args: gate_class (type): The type of gate that this rule decomposes. The gate class is redundant information used to make lookups faster whe...
Initialize a DecompositionRule object. Args: gate_class (type): The type of gate that this rule decomposes. The gate class is redundant information used to make lookups faster when iterating over a circuit and deciding "which rules apply to this gate?" agai...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_decomposition_rule.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_decomposition_rule.py
Apache-2.0
def __init__(self, rules=None, modules=None): """ Initialize a DecompositionRuleSet object. Args: rules list[DecompositionRule]: Initial decomposition rules. modules (iterable[ModuleWithDecompositionRuleSet]): A list of things with an "all_defined_decompo...
Initialize a DecompositionRuleSet object. Args: rules list[DecompositionRule]: Initial decomposition rules. modules (iterable[ModuleWithDecompositionRuleSet]): A list of things with an "all_defined_decomposition_rules" property containing decomposition rules to ...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_decomposition_rule_set.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_decomposition_rule_set.py
Apache-2.0
def add_decomposition_rule(self, rule): """ Add a decomposition rule to the rule set. Args: rule (DecompositionRuleGate): The decomposition rule to add. """ decomp_obj = _Decomposition(rule.gate_decomposer, rule.gate_recognizer) cls = rule.gate_class.__name__...
Add a decomposition rule to the rule set. Args: rule (DecompositionRuleGate): The decomposition rule to add.
add_decomposition_rule
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_decomposition_rule_set.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_decomposition_rule_set.py
Apache-2.0
def __init__(self, replacement_fun, recogn_fun): """ Initialize a Decomposition object. Args: replacement_fun: Function that, when called with a `Command` object, decomposes this command. recogn_fun: Function that, when called with a `Command` object, returns True if and...
Initialize a Decomposition object. Args: replacement_fun: Function that, when called with a `Command` object, decomposes this command. recogn_fun: Function that, when called with a `Command` object, returns True if and only if the replacement rule can handle thi...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_decomposition_rule_set.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_decomposition_rule_set.py
Apache-2.0
def get_inverse_decomposition(self): """ Return the Decomposition object which handles the inverse of the original command. This simulates the user having added a decomposition rule for the inverse as well. Since decomposing the inverse of a command can be achieved by running the origin...
Return the Decomposition object which handles the inverse of the original command. This simulates the user having added a decomposition rule for the inverse as well. Since decomposing the inverse of a command can be achieved by running the original decomposition inside a `with Dagger(engine):`...
get_inverse_decomposition
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_decomposition_rule_set.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_decomposition_rule_set.py
Apache-2.0
def __init__(self, filterfun): """ Initialize an InstructionFilter object. Initializer: The provided filterfun returns True for all commands which do not need replacement and False for commands that do. Args: filterfun (function): Filter function which returns True ...
Initialize an InstructionFilter object. Initializer: The provided filterfun returns True for all commands which do not need replacement and False for commands that do. Args: filterfun (function): Filter function which returns True for available commands, and False ...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_replacer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_replacer.py
Apache-2.0
def __init__( self, decomposition_rule_se, decomposition_chooser=lambda cmd, decomposition_list: decomposition_list[0], ): """ Initialize an AutoReplacer. Args: decomposition_chooser (function): A function which, given the Command to decom...
Initialize an AutoReplacer. Args: decomposition_chooser (function): A function which, given the Command to decompose and a list of potential Decomposition objects, determines (and then returns) the 'best' decomposition. The default d...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_replacer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_replacer.py
Apache-2.0
def _process_command(self, cmd): # pylint: disable=too-many-locals,too-many-branches """ Process a command. Check whether a command cmd can be handled by further engines and, if not, replace it using the decomposition rules loaded with the setup (e.g., setups.default). Args: ...
Process a command. Check whether a command cmd can be handled by further engines and, if not, replace it using the decomposition rules loaded with the setup (e.g., setups.default). Args: cmd (Command): Command to process. Raises: Exception if no replac...
_process_command
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_replacer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_replacer.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive a list of commands from the previous compiler engine and, if necessary, replace/decompose the gates according to the decomposition rules in the loaded setup. Args: command_list (list<Command>):...
Receive a list of commands. Receive a list of commands from the previous compiler engine and, if necessary, replace/decompose the gates according to the decomposition rules in the loaded setup. Args: command_list (list<Command>): List of commands to handle.
receive
python
ProjectQ-Framework/ProjectQ
projectq/cengines/_replacer/_replacer.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/cengines/_replacer/_replacer.py
Apache-2.0
def histogram(backend, qureg): """ Make a measurement outcome probability histogram for the given qubits. Args: backend (BasicEngine): A ProjectQ backend qureg (list of qubits and/or quregs): The qubits, for which to make the histogram Returns: A tuple (fig, axes, p...
Make a measurement outcome probability histogram for the given qubits. Args: backend (BasicEngine): A ProjectQ backend qureg (list of qubits and/or quregs): The qubits, for which to make the histogram Returns: A tuple (fig, axes, probabilities), where: fig: The...
histogram
python
ProjectQ-Framework/ProjectQ
projectq/libs/hist/_histogram.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/hist/_histogram.py
Apache-2.0
def add_constant(eng, constant, quint): """ Add a classical constant c to the quantum integer (qureg) quint using Draper addition. Note: Uses the Fourier-transform adder from https://arxiv.org/abs/quant-ph/0008033. """ with Compute(eng): QFT | quint for i, qubit in enumerate(qu...
Add a classical constant c to the quantum integer (qureg) quint using Draper addition. Note: Uses the Fourier-transform adder from https://arxiv.org/abs/quant-ph/0008033.
add_constant
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_constantmath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_constantmath.py
Apache-2.0
def add_constant_modN(eng, constant, N, quint): # pylint: disable=invalid-name """ Add a classical constant c to a quantum integer (qureg) quint modulo N using Draper addition. This function uses Draper addition and the construction from https://arxiv.org/abs/quant-ph/0205095. """ if constant < 0 ...
Add a classical constant c to a quantum integer (qureg) quint modulo N using Draper addition. This function uses Draper addition and the construction from https://arxiv.org/abs/quant-ph/0205095.
add_constant_modN
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_constantmath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_constantmath.py
Apache-2.0
def mul_by_constant_modN(eng, constant, N, quint_in): # pylint: disable=invalid-name """ Multiply a quantum integer by a classical number a modulo N. i.e., |x> -> |a*x mod N> (only works if a and N are relative primes, otherwise the modular inverse does not exist). """ if constant < ...
Multiply a quantum integer by a classical number a modulo N. i.e., |x> -> |a*x mod N> (only works if a and N are relative primes, otherwise the modular inverse does not exist).
mul_by_constant_modN
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_constantmath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_constantmath.py
Apache-2.0
def __init__(self, a): # pylint: disable=invalid-name """ Initialize the gate to the number to add. Args: a (int): Number to add to a quantum register. It also initializes its base class, BasicMathGate, with the corresponding function, so it can be emulated efficie...
Initialize the gate to the number to add. Args: a (int): Number to add to a quantum register. It also initializes its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def __init__(self, a, N): """ Initialize the gate to the number to add modulo N. Args: a (int): Number to add to a quantum register (0 <= a < N). N (int): Number modulo which the addition is carried out. It also initializes its base class, BasicMathGate, with th...
Initialize the gate to the number to add modulo N. Args: a (int): Number to add to a quantum register (0 <= a < N). N (int): Number modulo which the addition is carried out. It also initializes its base class, BasicMathGate, with the corresponding function, so it can b...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def __init__(self, a, N): # pylint: disable=invalid-name """ Initialize the gate to the number to multiply with modulo N. Args: a (int): Number by which to multiply a quantum register (0 <= a < N). N (int): Number modulo which the multiplication is carri...
Initialize the gate to the number to multiply with modulo N. Args: a (int): Number by which to multiply a quantum register (0 <= a < N). N (int): Number modulo which the multiplication is carried out. It also initializes its base class, BasicMathGate, w...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def get_math_function(self, qubits): """Get the math function associated with an AddQuantumGate.""" n_qubits = len(qubits[0]) def math_fun(a): # pylint: disable=invalid-name a[1] = a[0] + a[1] if len(bin(a[1])[2:]) > n_qubits: a[1] = a[1] % (2**n_qubits)...
Get the math function associated with an AddQuantumGate.
get_math_function
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def __init__(self): """ Initialize a SubtractQuantumGate object. Initializes the gate to its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently. """ def subtract(a, b): # pylint: disable=invalid-name return (a, b -...
Initialize a SubtractQuantumGate object. Initializes the gate to its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def __init__(self): """ Initialize a ComparatorQuantumGate object. Initialize the gate and its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently. """ def compare(a, b, c): # pylint: disable=invalid-name # pylint: ...
Initialize a ComparatorQuantumGate object. Initialize the gate and its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def __init__(self): """ Initialize a DivideQuantumGate object. Initialize the gate and its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently. """ def division(dividend, remainder, divisor): if divisor == 0 or divis...
Initialize a DivideQuantumGate object. Initialize the gate and its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def __init__(self): """ Initialize a MultiplyQuantumGate object. Initialize the gate and its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently. """ def multiply(a, b, c): # pylint: disable=invalid-name return (a, ...
Initialize a MultiplyQuantumGate object. Initialize the gate and its base class, BasicMathGate, with the corresponding function, so it can be emulated efficiently.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_gates.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_gates.py
Apache-2.0
def add_quantum(eng, quint_a, quint_b, carry=None): """ Add two quantum integers. i.e., |a0...a(n-1)>|b(0)...b(n-1)>|c> -> |a0...a(n-1)>|b+a(0)...b+a(n)> (only works if quint_a and quint_b are the same size and carry is a single qubit) Args: eng (MainEngine): ProjectQ MainEngine ...
Add two quantum integers. i.e., |a0...a(n-1)>|b(0)...b(n-1)>|c> -> |a0...a(n-1)>|b+a(0)...b+a(n)> (only works if quint_a and quint_b are the same size and carry is a single qubit) Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits...
add_quantum
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def subtract_quantum(eng, quint_a, quint_b): """ Subtract two quantum integers. i.e., |a>|b> -> |a>|b-a> (only works if quint_a and quint_b are the same size) Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits) quint_b (lis...
Subtract two quantum integers. i.e., |a>|b> -> |a>|b-a> (only works if quint_a and quint_b are the same size) Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits) quint_b (list): Quantum register (or list of qubits) Notes:...
subtract_quantum
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def inverse_add_quantum_carry(eng, quint_a, quint_b): """ Inverse of quantum addition with carry. Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits) quint_b (list): Quantum register (or list of qubits) """ # pylint: disable = poi...
Inverse of quantum addition with carry. Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits) quint_b (list): Quantum register (or list of qubits)
inverse_add_quantum_carry
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def comparator(eng, quint_a, quint_b, comp): """ Compare the size of two quantum integers. i.e, if a>b: |a>|b>|c> -> |a>|b>|c+1> else: |a>|b>|c> -> |a>|b>|c> (only works if quint_a and quint_b are the same size and the comparator is 1 qubit) Args: eng (MainEngine): ProjectQ Ma...
Compare the size of two quantum integers. i.e, if a>b: |a>|b>|c> -> |a>|b>|c+1> else: |a>|b>|c> -> |a>|b>|c> (only works if quint_a and quint_b are the same size and the comparator is 1 qubit) Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (o...
comparator
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def quantum_conditional_add(eng, quint_a, quint_b, conditional): """ Add up two quantum integers if conditional is high. i.e., |a>|b>|c> -> |a>|b+a>|c> (without a carry out qubit) if conditional is low, no operation is performed, i.e., |a>|b>|c> -> |a>|b>|c> Args: eng (MainEn...
Add up two quantum integers if conditional is high. i.e., |a>|b>|c> -> |a>|b+a>|c> (without a carry out qubit) if conditional is low, no operation is performed, i.e., |a>|b>|c> -> |a>|b>|c> Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or ...
quantum_conditional_add
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def quantum_division(eng, dividend, remainder, divisor): """ Perform restoring integer division. i.e., |dividend>|remainder>|divisor> -> |remainder>|quotient>|divisor> (only works if all three qubits are of equal length) Args: eng (MainEngine): ProjectQ MainEngine dividend (l...
Perform restoring integer division. i.e., |dividend>|remainder>|divisor> -> |remainder>|quotient>|divisor> (only works if all three qubits are of equal length) Args: eng (MainEngine): ProjectQ MainEngine dividend (list): Quantum register (or list of qubits) remainder (li...
quantum_division
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def inverse_quantum_division(eng, remainder, quotient, divisor): """ Perform the inverse of a restoring integer division. i.e., |remainder>|quotient>|divisor> -> |dividend>|remainder(0)>|divisor> Args: eng (MainEngine): ProjectQ MainEngine dividend (list): Quantum register (or li...
Perform the inverse of a restoring integer division. i.e., |remainder>|quotient>|divisor> -> |dividend>|remainder(0)>|divisor> Args: eng (MainEngine): ProjectQ MainEngine dividend (list): Quantum register (or list of qubits) remainder (list): Quantum register (or list of qub...
inverse_quantum_division
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def quantum_conditional_add_carry(eng, quint_a, quint_b, ctrl, z): # pylint: disable=invalid-name """ Add up two quantum integers if the control qubit is |1>. i.e., |a>|b>|ctrl>|z(0)z(1)> -> |a>|s(0)...s(n-1)>|ctrl>|s(n)z(1)> (where s denotes the sum of a and b) If the control qubit is |0> n...
Add up two quantum integers if the control qubit is |1>. i.e., |a>|b>|ctrl>|z(0)z(1)> -> |a>|s(0)...s(n-1)>|ctrl>|s(n)z(1)> (where s denotes the sum of a and b) If the control qubit is |0> no operation is performed: |a>|b>|ctrl>|z(0)z(1)> -> |a>|b>|ctrl>|z(0)z(1)> (only works if quint_...
quantum_conditional_add_carry
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def quantum_multiplication(eng, quint_a, quint_b, product): """ Multiplies two quantum integers. i.e, |a>|b>|0> -> |a>|b>|a*b> (only works if quint_a and quint_b are of the same size, n qubits and product has size 2n+1). Args: eng (MainEngine): ProjectQ MainEngine quint_a (li...
Multiplies two quantum integers. i.e, |a>|b>|0> -> |a>|b>|a*b> (only works if quint_a and quint_b are of the same size, n qubits and product has size 2n+1). Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits) quint_b (list): Q...
quantum_multiplication
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def inverse_quantum_multiplication(eng, quint_a, quint_b, product): """ Inverse of the multiplication of two quantum integers. i.e, |a>|b>|a*b> -> |a>|b>|0> (only works if quint_a and quint_b are of the same size, n qubits and product has size 2n+1) Args: eng (MainEngine): ProjectQ M...
Inverse of the multiplication of two quantum integers. i.e, |a>|b>|a*b> -> |a>|b>|0> (only works if quint_a and quint_b are of the same size, n qubits and product has size 2n+1) Args: eng (MainEngine): ProjectQ MainEngine quint_a (list): Quantum register (or list of qubits) ...
inverse_quantum_multiplication
python
ProjectQ-Framework/ProjectQ
projectq/libs/math/_quantummath.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/math/_quantummath.py
Apache-2.0
def __init__(self, function, **kwargs): """ Initialize a control function oracle. Args: function (int): Function truth table. Keyword Args: synth: A RevKit synthesis command which creates a reversible circuit based on a truth table and require...
Initialize a control function oracle. Args: function (int): Function truth table. Keyword Args: synth: A RevKit synthesis command which creates a reversible circuit based on a truth table and requires no additional ancillae (e.g., ...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/revkit/_control_function.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/revkit/_control_function.py
Apache-2.0
def __or__(self, qubits): """ Apply control function to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the control function is being applied. The first `n` qubits are for the contro...
Apply control function to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the control function is being applied. The first `n` qubits are for the controls, the last qubit is for the ...
__or__
python
ProjectQ-Framework/ProjectQ
projectq/libs/revkit/_control_function.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/revkit/_control_function.py
Apache-2.0
def __init__(self, permutation, **kwargs): """ Initialize a permutation oracle. Args: permutation (list<int>): Permutation (starting from 0). Keyword Args: synth: A RevKit synthesis command which creates a reversible circuit based on a reversible truth table ...
Initialize a permutation oracle. Args: permutation (list<int>): Permutation (starting from 0). Keyword Args: synth: A RevKit synthesis command which creates a reversible circuit based on a reversible truth table (e.g., ``revkit.tbs`` or ``revkit.dbs`...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/revkit/_permutation.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/revkit/_permutation.py
Apache-2.0
def __or__(self, qubits): """ Apply permutation to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the permutation is being applied. """ try: import revkit # pylint: disable=import-outside-toplevel except ImportErro...
Apply permutation to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the permutation is being applied.
__or__
python
ProjectQ-Framework/ProjectQ
projectq/libs/revkit/_permutation.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/revkit/_permutation.py
Apache-2.0
def __init__(self, function, **kwargs): """ Initialize a phase oracle. Args: function (int): Function truth table. Keyword Args: synth: A RevKit synthesis command which creates a reversible circuit based on a truth table and requires no additi...
Initialize a phase oracle. Args: function (int): Function truth table. Keyword Args: synth: A RevKit synthesis command which creates a reversible circuit based on a truth table and requires no additional ancillae (e.g., ``revkit.esopps``). Can also ...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/libs/revkit/_phase.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/revkit/_phase.py
Apache-2.0
def __or__(self, qubits): """ Apply phase circuit to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the phase circuit is being applied. """ try: import revkit # pylint: disable=import-outside-toplevel except Import...
Apply phase circuit to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the phase circuit is being applied.
__or__
python
ProjectQ-Framework/ProjectQ
projectq/libs/revkit/_phase.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/libs/revkit/_phase.py
Apache-2.0
def run_uncompute(self): # pylint: disable=too-many-branches,too-many-statements """ Send uncomputing gates. Sends the inverse of the stored commands in reverse order down to the next engine. And also deals with allocated qubits in Compute section. If a qubit has been allocated during...
Send uncomputing gates. Sends the inverse of the stored commands in reverse order down to the next engine. And also deals with allocated qubits in Compute section. If a qubit has been allocated during compute, it will be deallocated during uncompute. If a qubit has been allocated and ...
run_uncompute
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def end_compute(self): """ End the compute step (exit the with Compute() - statement). Will tell the Compute-engine to stop caching. It then waits for the uncompute instruction, which is when it sends all cached commands inverted and in reverse order down to the next compiler engine. ...
End the compute step (exit the with Compute() - statement). Will tell the Compute-engine to stop caching. It then waits for the uncompute instruction, which is when it sends all cached commands inverted and in reverse order down to the next compiler engine. Raises: QubitMa...
end_compute
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. If in compute-mode, receive commands and store deepcopy of each cmd. Add ComputeTag to received cmd and send it on. Otherwise, send all received commands directly to next_engine. Args: command_list (l...
Receive a list of commands. If in compute-mode, receive commands and store deepcopy of each cmd. Add ComputeTag to received cmd and send it on. Otherwise, send all received commands directly to next_engine. Args: command_list (list<Command>): List of commands to receive. ...
receive
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands. Receive commands and add an UncomputeTag to their tags. Args: command_list (list<Command>): List of commands to handle. """ for cmd in command_list: if cmd.gate == Allocate: ...
Receive a list of commands. Receive commands and add an UncomputeTag to their tags. Args: command_list (list<Command>): List of commands to handle.
receive
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def __init__(self, engine): """ Initialize a Compute context. Args: engine (BasicEngine): Engine which is the first to receive all commands (normally: MainEngine). """ self.engine = engine self._compute_eng = None
Initialize a Compute context. Args: engine (BasicEngine): Engine which is the first to receive all commands (normally: MainEngine).
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def __init__(self, engine): """ Initialize a CustomUncompute context. Args: engine (BasicEngine): Engine which is the first to receive all commands (normally: MainEngine). """ self.engine = engine # Save all qubit ids from qubits which are created or destroye...
Initialize a CustomUncompute context. Args: engine (BasicEngine): Engine which is the first to receive all commands (normally: MainEngine).
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def Uncompute(engine): # pylint: disable=invalid-name """ Uncompute automatically. Example: .. code-block:: python with Compute(eng): do_something(qubits) action(qubits) Uncompute(eng) # runs inverse of the compute section """ compute_e...
Uncompute automatically. Example: .. code-block:: python with Compute(eng): do_something(qubits) action(qubits) Uncompute(eng) # runs inverse of the compute section
Uncompute
python
ProjectQ-Framework/ProjectQ
projectq/meta/_compute.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_compute.py
Apache-2.0
def canonical_ctrl_state(ctrl_state, num_qubits): """ Return canonical form for control state. Args: ctrl_state (int,str,CtrlAll): Initial control state representation num_qubits (int): number of control qubits Returns: Canonical form of control state (currently a string compos...
Return canonical form for control state. Args: ctrl_state (int,str,CtrlAll): Initial control state representation num_qubits (int): number of control qubits Returns: Canonical form of control state (currently a string composed of '0' and '1') Note: In case of integer ...
canonical_ctrl_state
python
ProjectQ-Framework/ProjectQ
projectq/meta/_control.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_control.py
Apache-2.0
def _has_compute_uncompute_tag(cmd): """ Return True if command cmd has a compute/uncompute tag. Args: cmd (Command object): a command object. """ for tag in cmd.tags: if tag in [UncomputeTag(), ComputeTag()]: return True return False
Return True if command cmd has a compute/uncompute tag. Args: cmd (Command object): a command object.
_has_compute_uncompute_tag
python
ProjectQ-Framework/ProjectQ
projectq/meta/_control.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_control.py
Apache-2.0
def __init__(self, qubits, ctrl_state=CtrlAll.One): """ Initialize the control engine. Args: qubits (list of Qubit objects): qubits conditional on which the following operations are executed. """ super().__init__() self._qubits = qubits ...
Initialize the control engine. Args: qubits (list of Qubit objects): qubits conditional on which the following operations are executed.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_control.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_control.py
Apache-2.0
def __init__(self, engine, qubits, ctrl_state=CtrlAll.One): """ Enter a controlled section. Args: engine: Engine which handles the commands (usually MainEngine) qubits (list of Qubit objects): Qubits to condition on Enter the section using a with-statement: ...
Enter a controlled section. Args: engine: Engine which handles the commands (usually MainEngine) qubits (list of Qubit objects): Qubits to condition on Enter the section using a with-statement: .. code-block:: python with Control(eng, ctrlqubits):...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_control.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_control.py
Apache-2.0
def run(self): """Run the stored circuit in reverse and check that local qubits have been deallocated.""" if self._deallocated_qubit_ids != self._allocated_qubit_ids: raise QubitManagementError( "\n Error. Qubits have been allocated in 'with " + "Dagger(eng)' ...
Run the stored circuit in reverse and check that local qubits have been deallocated.
run
python
ProjectQ-Framework/ProjectQ
projectq/meta/_dagger.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_dagger.py
Apache-2.0
def receive(self, command_list): """ Receive a list of commands and store them for later inversion. Args: command_list (list<Command>): List of commands to temporarily store. """ for cmd in command_list: if cmd.gate == Allocate: ...
Receive a list of commands and store them for later inversion. Args: command_list (list<Command>): List of commands to temporarily store.
receive
python
ProjectQ-Framework/ProjectQ
projectq/meta/_dagger.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_dagger.py
Apache-2.0
def __init__(self, engine): """ Enter an inverted section. Args: engine: Engine which handles the commands (usually MainEngine) Example (executes an inverse QFT): .. code-block:: python with Dagger(eng): QFT | qubits """ ...
Enter an inverted section. Args: engine: Engine which handles the commands (usually MainEngine) Example (executes an inverse QFT): .. code-block:: python with Dagger(eng): QFT | qubits
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_dagger.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_dagger.py
Apache-2.0
def __init__(self, num): """ Initialize a LoopEngine. Args: num (int): Number of loop iterations. """ super().__init__() self._tag = LoopTag(num) self._cmd_list = [] self._allocated_qubit_ids = set() self._deallocated_qubit_ids = set()...
Initialize a LoopEngine. Args: num (int): Number of loop iterations.
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_loop.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_loop.py
Apache-2.0
def run(self): """ Apply the loop statements to all stored commands. Unrolls the loop if LoopTag is not supported by any of the following engines, i.e., if .. code-block:: python is_meta_tag_supported(next_engine, LoopTag) == False """ error_message...
Apply the loop statements to all stored commands. Unrolls the loop if LoopTag is not supported by any of the following engines, i.e., if .. code-block:: python is_meta_tag_supported(next_engine, LoopTag) == False
run
python
ProjectQ-Framework/ProjectQ
projectq/meta/_loop.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_loop.py
Apache-2.0
def receive(self, command_list): # pylint: disable=too-many-branches """ Receive (and potentially temporarily store) all commands. Add LoopTag to all receiving commands and send to the next engine if a further engine is a LoopTag-handling engine. Otherwise store all commands (t...
Receive (and potentially temporarily store) all commands. Add LoopTag to all receiving commands and send to the next engine if a further engine is a LoopTag-handling engine. Otherwise store all commands (to later unroll them). Check that within the loop body, all allocated qubi...
receive
python
ProjectQ-Framework/ProjectQ
projectq/meta/_loop.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_loop.py
Apache-2.0
def __init__(self, engine, num): """ Enter a looped section. Args: engine: Engine handling the commands (usually MainEngine) num (int): Number of loop iterations Example: .. code-block:: python with Loop(eng, 4): ...
Enter a looped section. Args: engine: Engine handling the commands (usually MainEngine) num (int): Number of loop iterations Example: .. code-block:: python with Loop(eng, 4): H | qb Rz(M_PI / 3.0) | ...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/meta/_loop.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_loop.py
Apache-2.0
def insert_engine(prev_engine, engine_to_insert): """ Insert an engine into the singly-linked list of engines. It also sets the correct main_engine for engine_to_insert. Args: prev_engine (projectq.cengines.BasicEngine): The engine just before the insertion point. engine_to_insert (pro...
Insert an engine into the singly-linked list of engines. It also sets the correct main_engine for engine_to_insert. Args: prev_engine (projectq.cengines.BasicEngine): The engine just before the insertion point. engine_to_insert (projectq.cengines.BasicEngine): The engine to insert at the ...
insert_engine
python
ProjectQ-Framework/ProjectQ
projectq/meta/_util.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_util.py
Apache-2.0
def drop_engine_after(prev_engine): """ Remove an engine from the singly-linked list of engines. Args: prev_engine (projectq.cengines.BasicEngine): The engine just before the engine to drop. Returns: Engine: The dropped engine. """ dropped_engine = prev_engine.next_engine p...
Remove an engine from the singly-linked list of engines. Args: prev_engine (projectq.cengines.BasicEngine): The engine just before the engine to drop. Returns: Engine: The dropped engine.
drop_engine_after
python
ProjectQ-Framework/ProjectQ
projectq/meta/_util.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/meta/_util.py
Apache-2.0
def make_tuple_of_qureg(qubits): """ Convert quantum input of "gate | quantum input" to internal formatting. A Command object only accepts tuples of Quregs (list of Qubit objects) as qubits input parameter. However, with this function we allow the user to use a more flexible syntax: ...
Convert quantum input of "gate | quantum input" to internal formatting. A Command object only accepts tuples of Quregs (list of Qubit objects) as qubits input parameter. However, with this function we allow the user to use a more flexible syntax: 1) Gate | qubit 2) Gat...
make_tuple_of_qureg
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def generate_command(self, qubits): """ Generate a command. The command object created consists of the gate and the qubits being acted upon. Args: qubits: see BasicGate.make_tuple_of_qureg(qubits) Returns: A Command object containing the gate and the qu...
Generate a command. The command object created consists of the gate and the qubits being acted upon. Args: qubits: see BasicGate.make_tuple_of_qureg(qubits) Returns: A Command object containing the gate and the qubits.
generate_command
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __eq__(self, other): """ Equal operator. Return True if instance of the same class, unless other is an instance of :class:MatrixGate, in which case equality is to be checked by testing for existence and (approximate) equality of matrix representations. """ if isinsta...
Equal operator. Return True if instance of the same class, unless other is an instance of :class:MatrixGate, in which case equality is to be checked by testing for existence and (approximate) equality of matrix representations.
__eq__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __init__(self, matrix=None): """ Initialize a MatrixGate object. Args: matrix(numpy.matrix): matrix which defines the gate. Default: None """ super().__init__() self._matrix = np.matrix(matrix) if matrix is not None else None
Initialize a MatrixGate object. Args: matrix(numpy.matrix): matrix which defines the gate. Default: None
__init__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __eq__(self, other): """ Equal operator. Return True only if both gates have a matrix representation and the matrices are (approximately) equal. Otherwise return False. """ if not hasattr(other, 'matrix'): return False if not isinstance(self.matri...
Equal operator. Return True only if both gates have a matrix representation and the matrices are (approximately) equal. Otherwise return False.
__eq__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __init__(self, angle): """ Initialize a basic rotation gate. Args: angle (float): Angle of rotation (saved modulo 4 * pi) """ super().__init__() rounded_angle = round(float(angle) % (4.0 * math.pi), ANGLE_PRECISION) if rounded_angle > 4 * math.pi ...
Initialize a basic rotation gate. Args: angle (float): Angle of rotation (saved modulo 4 * pi)
__init__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def to_string(self, symbols=False): """ Return the string representation of a BasicRotationGate. Args: symbols (bool): uses the pi character and round the angle for a more user friendly display if True, full angle written in radian otherwise. """ ...
Return the string representation of a BasicRotationGate. Args: symbols (bool): uses the pi character and round the angle for a more user friendly display if True, full angle written in radian otherwise.
to_string
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def get_inverse(self): """Return the inverse of this rotation gate (negate the angle, return new object).""" if self.angle == 0: return self.__class__(0) return self.__class__(-self.angle + 4 * math.pi)
Return the inverse of this rotation gate (negate the angle, return new object).
get_inverse
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def get_merged(self, other): """ Return self merged with another gate. Default implementation handles rotation gate of the same type, where angles are simply added. Args: other: Rotation gate of same type. Raises: NotMergeable: For non-rotation gates or...
Return self merged with another gate. Default implementation handles rotation gate of the same type, where angles are simply added. Args: other: Rotation gate of same type. Raises: NotMergeable: For non-rotation gates or rotation gates of different type. ...
get_merged
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __eq__(self, other): """Return True if same class and same rotation angle.""" if isinstance(other, self.__class__): return self.angle == other.angle return False
Return True if same class and same rotation angle.
__eq__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __init__(self, angle): """ Initialize a basic rotation gate. Args: angle (float): Angle of rotation (saved modulo 2 * pi) """ super().__init__() rounded_angle = round(float(angle) % (2.0 * math.pi), ANGLE_PRECISION) if rounded_angle > 2 * math.pi ...
Initialize a basic rotation gate. Args: angle (float): Angle of rotation (saved modulo 2 * pi)
__init__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def get_merged(self, other): """ Return self merged with another gate. Default implementation handles rotation gate of the same type, where angles are simply added. Args: other: Rotation gate of same type. Raises: NotMergeable: For non-rotation gates or...
Return self merged with another gate. Default implementation handles rotation gate of the same type, where angles are simply added. Args: other: Rotation gate of same type. Raises: NotMergeable: For non-rotation gates or rotation gates of diffe...
get_merged
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __init__(self, math_fun): """ Initialize a BasicMathGate by providing the mathematical function that it implements. Args: math_fun (function): Function which takes as many int values as input, as the gate takes registers. For each of these values, it then returns...
Initialize a BasicMathGate by providing the mathematical function that it implements. Args: math_fun (function): Function which takes as many int values as input, as the gate takes registers. For each of these values, it then returns the output (i.e., it returns a list/tupl...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_basics.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_basics.py
Apache-2.0
def __init__( self, engine, gate, qubits, controls=(), tags=(), control_state=CtrlAll.One ): # pylint: disable=too-many-arguments """ Initialize a Command object. Note: control qubits (Command.control_qubits) are stored as a list of qubits, and command tags (Command.tag...
Initialize a Command object. Note: control qubits (Command.control_qubits) are stored as a list of qubits, and command tags (Command.tags) as a list of tag-objects. All functions within this class also work if WeakQubitRefs are supplied instead of normal Qubit objec...
__init__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def __deepcopy__(self, memo): """Deepcopy implementation. Engine should stay a reference.""" return Command( self.engine, deepcopy(self.gate), self.qubits, list(self.control_qubits), deepcopy(self.tags), )
Deepcopy implementation. Engine should stay a reference.
__deepcopy__
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def get_inverse(self): """ Get the command object corresponding to the inverse of this command. Inverts the gate (if possible) and creates a new command object from the result. Raises: NotInvertible: If the gate does not provide an inverse (see BasicGate.get_inverse) ...
Get the command object corresponding to the inverse of this command. Inverts the gate (if possible) and creates a new command object from the result. Raises: NotInvertible: If the gate does not provide an inverse (see BasicGate.get_inverse)
get_inverse
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def get_merged(self, other): """ Merge this command with another one and return the merged command object. Args: other: Other command to merge with this one (self) Raises: NotMergeable: if the gates don't supply a get_merged()-function or can't be merged for oth...
Merge this command with another one and return the merged command object. Args: other: Other command to merge with this one (self) Raises: NotMergeable: if the gates don't supply a get_merged()-function or can't be merged for other reasons.
get_merged
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def _order_qubits(self, qubits): """ Order the given qubits according to their IDs (for unique comparison of commands). Args: qubits: Tuple of quantum registers (i.e., tuple of lists of qubits) Returns: Ordered tuple of quantum registers """ ordered_qubits =...
Order the given qubits according to their IDs (for unique comparison of commands). Args: qubits: Tuple of quantum registers (i.e., tuple of lists of qubits) Returns: Ordered tuple of quantum registers
_order_qubits
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def control_qubits(self, qubits): """ Set control_qubits to qubits. Args: control_qubits (Qureg): quantum register """ self._control_qubits = [WeakQubitRef(qubit.engine, qubit.id) for qubit in qubits] self._control_qubits = sorted(self._control_qubits, key=la...
Set control_qubits to qubits. Args: control_qubits (Qureg): quantum register
control_qubits
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def control_state(self, state): """ Set control_state to state. Args: state (int,str,projectq.meta.CtrtAll): state of control qubit (ie. positive or negative) """ # NB: avoid circular imports from projectq.meta import ( # pylint: disable=import-outside-tople...
Set control_state to state. Args: state (int,str,projectq.meta.CtrtAll): state of control qubit (ie. positive or negative)
control_state
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0
def add_control_qubits(self, qubits, state=CtrlAll.One): """ Add (additional) control qubits to this command object. They are sorted to ensure a canonical order. Also Qubit objects are converted to WeakQubitRef objects to allow garbage collection and thus early deallocation of q...
Add (additional) control qubits to this command object. They are sorted to ensure a canonical order. Also Qubit objects are converted to WeakQubitRef objects to allow garbage collection and thus early deallocation of qubits. Args: qubits (list of Qubit objects): Li...
add_control_qubits
python
ProjectQ-Framework/ProjectQ
projectq/ops/_command.py
https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/ops/_command.py
Apache-2.0