partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
CircuitTikzGenerator._x_gate
Return the TikZ code for a NOT-gate. :param lines: List of length 1 denoting the target qubit of the NOT / X gate. :type: list[int] :param ctrl_lines: List of qubit lines which act as controls. :type: list[int]
pyquil/latex/latex_generation.py
def _x_gate(self, lines, ctrl_lines): """ Return the TikZ code for a NOT-gate. :param lines: List of length 1 denoting the target qubit of the NOT / X gate. :type: list[int] :param ctrl_lines: List of qubit lines which act as controls. :type: list[int] """ ...
def _x_gate(self, lines, ctrl_lines): """ Return the TikZ code for a NOT-gate. :param lines: List of length 1 denoting the target qubit of the NOT / X gate. :type: list[int] :param ctrl_lines: List of qubit lines which act as controls. :type: list[int] """ ...
[ "Return", "the", "TikZ", "code", "for", "a", "NOT", "-", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L329-L356
[ "def", "_x_gate", "(", "self", ",", "lines", ",", "ctrl_lines", ")", ":", "line", "=", "lines", "[", "0", "]", "delta_pos", "=", "self", ".", "_gate_offset", "(", "'X'", ")", "gate_width", "=", "self", ".", "_gate_width", "(", "'X'", ")", "op", "=", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._cz_gate
Return the TikZ code for an n-controlled Z-gate. :param lines: List of all qubits involved. :type: list[int]
pyquil/latex/latex_generation.py
def _cz_gate(self, lines): """ Return the TikZ code for an n-controlled Z-gate. :param lines: List of all qubits involved. :type: list[int] """ line = lines[0] delta_pos = self._gate_offset(Z) gate_width = self._gate_width(Z) gate_str = self._phas...
def _cz_gate(self, lines): """ Return the TikZ code for an n-controlled Z-gate. :param lines: List of all qubits involved. :type: list[int] """ line = lines[0] delta_pos = self._gate_offset(Z) gate_width = self._gate_width(Z) gate_str = self._phas...
[ "Return", "the", "TikZ", "code", "for", "an", "n", "-", "controlled", "Z", "-", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L358-L379
[ "def", "_cz_gate", "(", "self", ",", "lines", ")", ":", "line", "=", "lines", "[", "0", "]", "delta_pos", "=", "self", ".", "_gate_offset", "(", "Z", ")", "gate_width", "=", "self", ".", "_gate_width", "(", "Z", ")", "gate_str", "=", "self", ".", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._gate_width
Return the gate width, using the settings (if available). :param string gate: The name of the gate whose height is desired. :return: Width of the gate. :rtype: float
pyquil/latex/latex_generation.py
def _gate_width(self, gate): """ Return the gate width, using the settings (if available). :param string gate: The name of the gate whose height is desired. :return: Width of the gate. :rtype: float """ try: gates = self.settings['gates'] ...
def _gate_width(self, gate): """ Return the gate width, using the settings (if available). :param string gate: The name of the gate whose height is desired. :return: Width of the gate. :rtype: float """ try: gates = self.settings['gates'] ...
[ "Return", "the", "gate", "width", "using", "the", "settings", "(", "if", "available", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L381-L394
[ "def", "_gate_width", "(", "self", ",", "gate", ")", ":", "try", ":", "gates", "=", "self", ".", "settings", "[", "'gates'", "]", "gate_width", "=", "gates", "[", "gate", ".", "__class__", ".", "__name__", "]", "[", "'width'", "]", "except", "KeyError"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._gate_pre_offset
Return the offset to use before placing this gate. :param string gate: The name of the gate whose pre-offset is desired. :return: Offset to use before the gate. :rtype: float
pyquil/latex/latex_generation.py
def _gate_pre_offset(self, gate): """ Return the offset to use before placing this gate. :param string gate: The name of the gate whose pre-offset is desired. :return: Offset to use before the gate. :rtype: float """ try: gates = self.settings['gates'...
def _gate_pre_offset(self, gate): """ Return the offset to use before placing this gate. :param string gate: The name of the gate whose pre-offset is desired. :return: Offset to use before the gate. :rtype: float """ try: gates = self.settings['gates'...
[ "Return", "the", "offset", "to", "use", "before", "placing", "this", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L396-L409
[ "def", "_gate_pre_offset", "(", "self", ",", "gate", ")", ":", "try", ":", "gates", "=", "self", ".", "settings", "[", "'gates'", "]", "delta_pos", "=", "gates", "[", "gate", ".", "__class__", ".", "__name__", "]", "[", "'pre_offset'", "]", "except", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._gate_height
Return the height to use for this gate. :param string gate: The name of the gate whose height is desired. :return: Height of the gate. :rtype: float
pyquil/latex/latex_generation.py
def _gate_height(self, gate): """ Return the height to use for this gate. :param string gate: The name of the gate whose height is desired. :return: Height of the gate. :rtype: float """ try: height = self.settings['gates'][gate.__class__.__name__]['h...
def _gate_height(self, gate): """ Return the height to use for this gate. :param string gate: The name of the gate whose height is desired. :return: Height of the gate. :rtype: float """ try: height = self.settings['gates'][gate.__class__.__name__]['h...
[ "Return", "the", "height", "to", "use", "for", "this", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L427-L439
[ "def", "_gate_height", "(", "self", ",", "gate", ")", ":", "try", ":", "height", "=", "self", ".", "settings", "[", "'gates'", "]", "[", "gate", ".", "__class__", ".", "__name__", "]", "[", "'height'", "]", "except", "KeyError", ":", "height", "=", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._phase
Places a phase / control circle on a qubit line at a given position. :param int line: Qubit line at which to place the circle. :param float pos: Position at which to place the circle. :return: Latex string representing a control circle at the given position. :rtype: string
pyquil/latex/latex_generation.py
def _phase(self, line, pos): """ Places a phase / control circle on a qubit line at a given position. :param int line: Qubit line at which to place the circle. :param float pos: Position at which to place the circle. :return: Latex string representing a control circle at the giv...
def _phase(self, line, pos): """ Places a phase / control circle on a qubit line at a given position. :param int line: Qubit line at which to place the circle. :param float pos: Position at which to place the circle. :return: Latex string representing a control circle at the giv...
[ "Places", "a", "phase", "/", "control", "circle", "on", "a", "qubit", "line", "at", "a", "given", "position", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L441-L451
[ "def", "_phase", "(", "self", ",", "line", ",", "pos", ")", ":", "phase_str", "=", "\"\\n\\\\node[phase] ({}) at ({},-{}) {{}};\"", "return", "phase_str", ".", "format", "(", "self", ".", "_op", "(", "line", ")", ",", "pos", ",", "line", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._op
Returns the gate name for placing a gate on a line. :param int line: Line number. :param int op: Operation number or, by default, uses the current op count. :return: Gate name. :rtype: string
pyquil/latex/latex_generation.py
def _op(self, line, op=None, offset=0): """ Returns the gate name for placing a gate on a line. :param int line: Line number. :param int op: Operation number or, by default, uses the current op count. :return: Gate name. :rtype: string """ if op is None: ...
def _op(self, line, op=None, offset=0): """ Returns the gate name for placing a gate on a line. :param int line: Line number. :param int op: Operation number or, by default, uses the current op count. :return: Gate name. :rtype: string """ if op is None: ...
[ "Returns", "the", "gate", "name", "for", "placing", "a", "gate", "on", "a", "line", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L453-L464
[ "def", "_op", "(", "self", ",", "line", ",", "op", "=", "None", ",", "offset", "=", "0", ")", ":", "if", "op", "is", "None", ":", "op", "=", "self", ".", "op_count", "[", "line", "]", "return", "\"line{}_gate{}\"", ".", "format", "(", "line", ","...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._line
Connects p1 and p2, where p1 and p2 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 given line. :param int p1: Index of the first object to con...
pyquil/latex/latex_generation.py
def _line(self, p1, p2, line=None): """ Connects p1 and p2, where p1 and p2 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 given line. ...
def _line(self, p1, p2, line=None): """ Connects p1 and p2, where p1 and p2 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 given line. ...
[ "Connects", "p1", "and", "p2", "where", "p1", "and", "p2", "are", "either", "to", "qubit", "line", "indices", "in", "which", "case", "the", "two", "most", "recent", "gates", "are", "connected", "or", "two", "gate", "indices", "in", "which", "case", "line...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L466-L503
[ "def", "_line", "(", "self", ",", "p1", ",", "p2", ",", "line", "=", "None", ")", ":", "dbl_classical", "=", "self", ".", "settings", "[", "'lines'", "]", "[", "'double_classical'", "]", "if", "line", "is", "None", ":", "quantum", "=", "not", "dbl_cl...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CircuitTikzGenerator._regular_gate
Draw a regular gate. :param string gate: Gate to draw. :param lines: Lines the gate acts on. :type: list[int] :param int ctrl_lines: Control lines. :param int used_lines: The lines that are actually involved in the gate. :return: LaTeX string drawing a regular gate at th...
pyquil/latex/latex_generation.py
def _regular_gate(self, gate, lines, ctrl_lines, used_lines): """ Draw a regular gate. :param string gate: Gate to draw. :param lines: Lines the gate acts on. :type: list[int] :param int ctrl_lines: Control lines. :param int used_lines: The lines that are actuall...
def _regular_gate(self, gate, lines, ctrl_lines, used_lines): """ Draw a regular gate. :param string gate: Gate to draw. :param lines: Lines the gate acts on. :type: list[int] :param int ctrl_lines: Control lines. :param int used_lines: The lines that are actuall...
[ "Draw", "a", "regular", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_generation.py#L505-L550
[ "def", "_regular_gate", "(", "self", ",", "gate", ",", "lines", ",", "ctrl_lines", ",", "used_lines", ")", ":", "imax", "=", "max", "(", "lines", ")", "imin", "=", "min", "(", "lines", ")", "delta_pos", "=", "self", ".", "_gate_offset", "(", "gate", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
WavefunctionSimulator.wavefunction
Simulate a Quil program and return the wavefunction. .. note:: If your program contains measurements or noisy gates, this method may not do what you want. If the execution of ``quil_program`` is **non-deterministic** then the final wavefunction only represents a stochastically generated...
pyquil/api/_wavefunction_simulator.py
def wavefunction(self, quil_program: Program, memory_map: Any = None) -> Wavefunction: """ Simulate a Quil program and return the wavefunction. .. note:: If your program contains measurements or noisy gates, this method may not do what you want. If the execution...
def wavefunction(self, quil_program: Program, memory_map: Any = None) -> Wavefunction: """ Simulate a Quil program and return the wavefunction. .. note:: If your program contains measurements or noisy gates, this method may not do what you want. If the execution...
[ "Simulate", "a", "Quil", "program", "and", "return", "the", "wavefunction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_wavefunction_simulator.py#L54-L82
[ "def", "wavefunction", "(", "self", ",", "quil_program", ":", "Program", ",", "memory_map", ":", "Any", "=", "None", ")", "->", "Wavefunction", ":", "if", "memory_map", "is", "not", "None", ":", "quil_program", "=", "self", ".", "augment_program_with_memory_va...
ec98e453084b0037d69d8c3245f6822a5422593d
train
WavefunctionSimulator.expectation
Calculate the expectation value of Pauli operators given a state prepared by prep_program. If ``pauli_terms`` is a ``PauliSum`` then the returned value is a single ``float``, otherwise the returned value is an array of values, one for each ``PauliTerm`` in the list. .. note:: If your p...
pyquil/api/_wavefunction_simulator.py
def expectation(self, prep_prog: Program, pauli_terms: Union[PauliSum, List[PauliTerm]], memory_map: Any = None) -> Union[float, np.ndarray]: """ Calculate the expectation value of Pauli operators given a state prepared by prep_program. If ``pauli_terms``...
def expectation(self, prep_prog: Program, pauli_terms: Union[PauliSum, List[PauliTerm]], memory_map: Any = None) -> Union[float, np.ndarray]: """ Calculate the expectation value of Pauli operators given a state prepared by prep_program. If ``pauli_terms``...
[ "Calculate", "the", "expectation", "value", "of", "Pauli", "operators", "given", "a", "state", "prepared", "by", "prep_program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_wavefunction_simulator.py#L85-L130
[ "def", "expectation", "(", "self", ",", "prep_prog", ":", "Program", ",", "pauli_terms", ":", "Union", "[", "PauliSum", ",", "List", "[", "PauliTerm", "]", "]", ",", "memory_map", ":", "Any", "=", "None", ")", "->", "Union", "[", "float", ",", "np", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
WavefunctionSimulator.run_and_measure
Run a Quil program once to determine the final wavefunction, and measure multiple times. Alternatively, consider using ``wavefunction`` and calling ``sample_bitstrings`` on the resulting object. For a large wavefunction and a low-medium number of trials, use this function. On the other...
pyquil/api/_wavefunction_simulator.py
def run_and_measure(self, quil_program: Program, qubits: List[int] = None, trials: int = 1, memory_map: Any = None) -> np.ndarray: """ Run a Quil program once to determine the final wavefunction, and measure multiple times. Alternatively, consider using ``wavefunction`` ...
def run_and_measure(self, quil_program: Program, qubits: List[int] = None, trials: int = 1, memory_map: Any = None) -> np.ndarray: """ Run a Quil program once to determine the final wavefunction, and measure multiple times. Alternatively, consider using ``wavefunction`` ...
[ "Run", "a", "Quil", "program", "once", "to", "determine", "the", "final", "wavefunction", "and", "measure", "multiple", "times", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_wavefunction_simulator.py#L133-L176
[ "def", "run_and_measure", "(", "self", ",", "quil_program", ":", "Program", ",", "qubits", ":", "List", "[", "int", "]", "=", "None", ",", "trials", ":", "int", "=", "1", ",", "memory_map", ":", "Any", "=", "None", ")", "->", "np", ".", "ndarray", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
field
Return an object to identify dataclass fields. default is the default value of the field. default_factory is a 0-argument function called to initialize a field's value. If init is True, the field will be a parameter to the class's __init__() function. If repr is True, the field will be included in t...
pyquil/external/dataclasses.py
def field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None): """Return an object to identify dataclass fields. default is the default value of the field. default_factory is a 0-argument function called to initialize a field's value. If in...
def field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None): """Return an object to identify dataclass fields. default is the default value of the field. default_factory is a 0-argument function called to initialize a field's value. If in...
[ "Return", "an", "object", "to", "identify", "dataclass", "fields", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L305-L324
[ "def", "field", "(", "*", ",", "default", "=", "MISSING", ",", "default_factory", "=", "MISSING", ",", "init", "=", "True", ",", "repr", "=", "True", ",", "hash", "=", "None", ",", "compare", "=", "True", ",", "metadata", "=", "None", ")", ":", "if...
ec98e453084b0037d69d8c3245f6822a5422593d
train
dataclass
Returns the same class as was passed in, with dunder methods added based on the fields defined in the class. Examines PEP 526 __annotations__ to determine fields. If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comp...
pyquil/external/dataclasses.py
def dataclass(_cls=None, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False): """Returns the same class as was passed in, with dunder methods added based on the fields defined in the class. Examines PEP 526 __annotations__ to determine fields. If init is true,...
def dataclass(_cls=None, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False): """Returns the same class as was passed in, with dunder methods added based on the fields defined in the class. Examines PEP 526 __annotations__ to determine fields. If init is true,...
[ "Returns", "the", "same", "class", "as", "was", "passed", "in", "with", "dunder", "methods", "added", "based", "on", "the", "fields", "defined", "in", "the", "class", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L935-L958
[ "def", "dataclass", "(", "_cls", "=", "None", ",", "*", ",", "init", "=", "True", ",", "repr", "=", "True", ",", "eq", "=", "True", ",", "order", "=", "False", ",", "unsafe_hash", "=", "False", ",", "frozen", "=", "False", ")", ":", "def", "wrap"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
fields
Return a tuple describing the fields of this dataclass. Accepts a dataclass or an instance of one. Tuple elements are of type Field.
pyquil/external/dataclasses.py
def fields(class_or_instance): """Return a tuple describing the fields of this dataclass. Accepts a dataclass or an instance of one. Tuple elements are of type Field. """ # Might it be worth caching this, per class? try: fields = getattr(class_or_instance, _FIELDS) except Attribute...
def fields(class_or_instance): """Return a tuple describing the fields of this dataclass. Accepts a dataclass or an instance of one. Tuple elements are of type Field. """ # Might it be worth caching this, per class? try: fields = getattr(class_or_instance, _FIELDS) except Attribute...
[ "Return", "a", "tuple", "describing", "the", "fields", "of", "this", "dataclass", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L961-L976
[ "def", "fields", "(", "class_or_instance", ")", ":", "# Might it be worth caching this, per class?", "try", ":", "fields", "=", "getattr", "(", "class_or_instance", ",", "_FIELDS", ")", "except", "AttributeError", ":", "raise", "TypeError", "(", "'must be called with a ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
asdict
Return the fields of a dataclass instance as a new dictionary mapping field names to field values. Example usage: @dataclass class C: x: int y: int c = C(1, 2) assert asdict(c) == {'x': 1, 'y': 2} If given, 'dict_factory' will be used instead of built-in dict....
pyquil/external/dataclasses.py
def asdict(obj, *, dict_factory=dict): """Return the fields of a dataclass instance as a new dictionary mapping field names to field values. Example usage: @dataclass class C: x: int y: int c = C(1, 2) assert asdict(c) == {'x': 1, 'y': 2} If given, 'dict_f...
def asdict(obj, *, dict_factory=dict): """Return the fields of a dataclass instance as a new dictionary mapping field names to field values. Example usage: @dataclass class C: x: int y: int c = C(1, 2) assert asdict(c) == {'x': 1, 'y': 2} If given, 'dict_f...
[ "Return", "the", "fields", "of", "a", "dataclass", "instance", "as", "a", "new", "dictionary", "mapping", "field", "names", "to", "field", "values", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L990-L1011
[ "def", "asdict", "(", "obj", ",", "*", ",", "dict_factory", "=", "dict", ")", ":", "if", "not", "_is_dataclass_instance", "(", "obj", ")", ":", "raise", "TypeError", "(", "\"asdict() should be called on dataclass instances\"", ")", "return", "_asdict_inner", "(", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
astuple
Return the fields of a dataclass instance as a new tuple of field values. Example usage:: @dataclass class C: x: int y: int c = C(1, 2) assert astuple(c) == (1, 2) If given, 'tuple_factory' will be used instead of built-in tuple. The function applies recursively t...
pyquil/external/dataclasses.py
def astuple(obj, *, tuple_factory=tuple): """Return the fields of a dataclass instance as a new tuple of field values. Example usage:: @dataclass class C: x: int y: int c = C(1, 2) assert astuple(c) == (1, 2) If given, 'tuple_factory' will be used instead of built...
def astuple(obj, *, tuple_factory=tuple): """Return the fields of a dataclass instance as a new tuple of field values. Example usage:: @dataclass class C: x: int y: int c = C(1, 2) assert astuple(c) == (1, 2) If given, 'tuple_factory' will be used instead of built...
[ "Return", "the", "fields", "of", "a", "dataclass", "instance", "as", "a", "new", "tuple", "of", "field", "values", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L1030-L1051
[ "def", "astuple", "(", "obj", ",", "*", ",", "tuple_factory", "=", "tuple", ")", ":", "if", "not", "_is_dataclass_instance", "(", "obj", ")", ":", "raise", "TypeError", "(", "\"astuple() should be called on dataclass instances\"", ")", "return", "_astuple_inner", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
make_dataclass
Return a new dynamically created dataclass. The dataclass name will be 'cls_name'. 'fields' is an iterable of either (name), (name, type) or (name, type, Field) objects. If type is omitted, use the string 'typing.Any'. Field objects are created by the equivalent of calling 'field(name, type [, Field-...
pyquil/external/dataclasses.py
def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False): """Return a new dynamically created dataclass. The dataclass name will be 'cls_name'. 'fields' is an iterable of either (nam...
def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False): """Return a new dynamically created dataclass. The dataclass name will be 'cls_name'. 'fields' is an iterable of either (nam...
[ "Return", "a", "new", "dynamically", "created", "dataclass", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L1070-L1133
[ "def", "make_dataclass", "(", "cls_name", ",", "fields", ",", "*", ",", "bases", "=", "(", ")", ",", "namespace", "=", "None", ",", "init", "=", "True", ",", "repr", "=", "True", ",", "eq", "=", "True", ",", "order", "=", "False", ",", "unsafe_hash...
ec98e453084b0037d69d8c3245f6822a5422593d
train
replace
Return a new object replacing specified fields with new values. This is especially useful for frozen classes. Example usage: @dataclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = replace(c, x=3) assert c1.x == 3 and c1.y == 2
pyquil/external/dataclasses.py
def replace(obj, **changes): """Return a new object replacing specified fields with new values. This is especially useful for frozen classes. Example usage: @dataclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = replace(c, x=3) assert c1.x == 3 and ...
def replace(obj, **changes): """Return a new object replacing specified fields with new values. This is especially useful for frozen classes. Example usage: @dataclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = replace(c, x=3) assert c1.x == 3 and ...
[ "Return", "a", "new", "object", "replacing", "specified", "fields", "with", "new", "values", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/external/dataclasses.py#L1136-L1177
[ "def", "replace", "(", "obj", ",", "*", "*", "changes", ")", ":", "# We're going to mutate 'changes', but that's okay because it's a", "# new dict, even if called with 'replace(obj, **my_changes)'.", "if", "not", "_is_dataclass_instance", "(", "obj", ")", ":", "raise", "TypeE...
ec98e453084b0037d69d8c3245f6822a5422593d
train
AbstractBenchmarker.generate_rb_sequence
Construct a randomized benchmarking experiment on the given qubits, decomposing into gateset. If interleaver is not provided, the returned sequence will have the form C_1 C_2 ... C_(depth-1) C_inv , where each C is a Clifford element drawn from gateset, C_{< depth} are randomly selected, ...
pyquil/api/_qac.py
def generate_rb_sequence(self, depth: int, gateset: List[Gate], seed: int = None, interleaver: Program = None) -> List[Program]: """ Construct a randomized benchmarking experiment on the given qubits, decomposing into gateset. If interleaver is not provided, the retu...
def generate_rb_sequence(self, depth: int, gateset: List[Gate], seed: int = None, interleaver: Program = None) -> List[Program]: """ Construct a randomized benchmarking experiment on the given qubits, decomposing into gateset. If interleaver is not provided, the retu...
[ "Construct", "a", "randomized", "benchmarking", "experiment", "on", "the", "given", "qubits", "decomposing", "into", "gateset", ".", "If", "interleaver", "is", "not", "provided", "the", "returned", "sequence", "will", "have", "the", "form" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qac.py#L70-L100
[ "def", "generate_rb_sequence", "(", "self", ",", "depth", ":", "int", ",", "gateset", ":", "List", "[", "Gate", "]", ",", "seed", ":", "int", "=", "None", ",", "interleaver", ":", "Program", "=", "None", ")", "->", "List", "[", "Program", "]", ":" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
qaoa_ansatz
Function that returns a QAOA ansatz program for a list of angles betas and gammas. len(betas) == len(gammas) == P for a QAOA program of order P. :param list(float) gammas: Angles over which to parameterize the cost Hamiltonian. :param list(float) betas: Angles over which to parameterize the driver Hamilton...
examples/qaoa_ansatz.py
def qaoa_ansatz(gammas, betas): """ Function that returns a QAOA ansatz program for a list of angles betas and gammas. len(betas) == len(gammas) == P for a QAOA program of order P. :param list(float) gammas: Angles over which to parameterize the cost Hamiltonian. :param list(float) betas: Angles ov...
def qaoa_ansatz(gammas, betas): """ Function that returns a QAOA ansatz program for a list of angles betas and gammas. len(betas) == len(gammas) == P for a QAOA program of order P. :param list(float) gammas: Angles over which to parameterize the cost Hamiltonian. :param list(float) betas: Angles ov...
[ "Function", "that", "returns", "a", "QAOA", "ansatz", "program", "for", "a", "list", "of", "angles", "betas", "and", "gammas", ".", "len", "(", "betas", ")", "==", "len", "(", "gammas", ")", "==", "P", "for", "a", "QAOA", "program", "of", "order", "P...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/qaoa_ansatz.py#L47-L59
[ "def", "qaoa_ansatz", "(", "gammas", ",", "betas", ")", ":", "return", "Program", "(", "[", "exponentiate_commuting_pauli_sum", "(", "h_cost", ")", "(", "g", ")", "+", "exponentiate_commuting_pauli_sum", "(", "h_driver", ")", "(", "b", ")", "for", "g", ",", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
list_devices
Query the Forest 2.0 server for a list of underlying QPU devices. NOTE: These can't directly be used to manufacture pyQuil Device objects, but this gives a list of legal values that can be supplied to list_lattices to filter its (potentially very noisy) output. :return: A list of device na...
pyquil/api/_devices.py
def list_devices(connection: ForestConnection = None): """ Query the Forest 2.0 server for a list of underlying QPU devices. NOTE: These can't directly be used to manufacture pyQuil Device objects, but this gives a list of legal values that can be supplied to list_lattices to filter its (potentia...
def list_devices(connection: ForestConnection = None): """ Query the Forest 2.0 server for a list of underlying QPU devices. NOTE: These can't directly be used to manufacture pyQuil Device objects, but this gives a list of legal values that can be supplied to list_lattices to filter its (potentia...
[ "Query", "the", "Forest", "2", ".", "0", "server", "for", "a", "list", "of", "underlying", "QPU", "devices", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_devices.py#L21-L46
[ "def", "list_devices", "(", "connection", ":", "ForestConnection", "=", "None", ")", ":", "# For the record, the dictionary stored in \"devices\" that we're getting back is keyed on device", "# names and has this structure in its values:", "#", "# {", "# \"is_online\": a boolean indi...
ec98e453084b0037d69d8c3245f6822a5422593d
train
list_lattices
Query the Forest 2.0 server for its knowledge of lattices. Optionally filters by underlying device name and lattice qubit count. :return: A dictionary keyed on lattice names and valued in dictionaries of the form { "device_name": device_name, "qubits": num_qubits ...
pyquil/api/_devices.py
def list_lattices(device_name: str = None, num_qubits: int = None, connection: ForestConnection = None): """ Query the Forest 2.0 server for its knowledge of lattices. Optionally filters by underlying device name and lattice qubit count. :return: A dictionary keyed on lattice names a...
def list_lattices(device_name: str = None, num_qubits: int = None, connection: ForestConnection = None): """ Query the Forest 2.0 server for its knowledge of lattices. Optionally filters by underlying device name and lattice qubit count. :return: A dictionary keyed on lattice names a...
[ "Query", "the", "Forest", "2", ".", "0", "server", "for", "its", "knowledge", "of", "lattices", ".", "Optionally", "filters", "by", "underlying", "device", "name", "and", "lattice", "qubit", "count", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_devices.py#L49-L99
[ "def", "list_lattices", "(", "device_name", ":", "str", "=", "None", ",", "num_qubits", ":", "int", "=", "None", ",", "connection", ":", "ForestConnection", "=", "None", ")", ":", "if", "connection", "is", "None", ":", "connection", "=", "ForestConnection", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_get_raw_lattice_data
Produces a dictionary of raw data for a lattice as queried from the Forest 2.0 server. Returns a dictionary of the form { "name": the name of the lattice as a string, "device_name": the name of the device, given as a string, that the lattice lies on, "specs": a Specs object...
pyquil/api/_devices.py
def _get_raw_lattice_data(lattice_name: str = None): """ Produces a dictionary of raw data for a lattice as queried from the Forest 2.0 server. Returns a dictionary of the form { "name": the name of the lattice as a string, "device_name": the name of the device, given as a string...
def _get_raw_lattice_data(lattice_name: str = None): """ Produces a dictionary of raw data for a lattice as queried from the Forest 2.0 server. Returns a dictionary of the form { "name": the name of the lattice as a string, "device_name": the name of the device, given as a string...
[ "Produces", "a", "dictionary", "of", "raw", "data", "for", "a", "lattice", "as", "queried", "from", "the", "Forest", "2", ".", "0", "server", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_devices.py#L114-L144
[ "def", "_get_raw_lattice_data", "(", "lattice_name", ":", "str", "=", "None", ")", ":", "from", "pyquil", ".", "api", ".", "_base_connection", "import", "get_session", ",", "get_json", "from", "requests", ".", "exceptions", "import", "MissingSchema", "session", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
get_bitstring_from_index
Returns the bitstring in lexical order that corresponds to the given index in 0 to 2^(qubit_num) :param int index: :param int qubit_num: :return: the bitstring :rtype: str
pyquil/wavefunction.py
def get_bitstring_from_index(index, qubit_num): """ Returns the bitstring in lexical order that corresponds to the given index in 0 to 2^(qubit_num) :param int index: :param int qubit_num: :return: the bitstring :rtype: str """ if index > (2**qubit_num - 1): raise IndexError("Ind...
def get_bitstring_from_index(index, qubit_num): """ Returns the bitstring in lexical order that corresponds to the given index in 0 to 2^(qubit_num) :param int index: :param int qubit_num: :return: the bitstring :rtype: str """ if index > (2**qubit_num - 1): raise IndexError("Ind...
[ "Returns", "the", "bitstring", "in", "lexical", "order", "that", "corresponds", "to", "the", "given", "index", "in", "0", "to", "2^", "(", "qubit_num", ")", ":", "param", "int", "index", ":", ":", "param", "int", "qubit_num", ":", ":", "return", ":", "...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L206-L216
[ "def", "get_bitstring_from_index", "(", "index", ",", "qubit_num", ")", ":", "if", "index", ">", "(", "2", "**", "qubit_num", "-", "1", ")", ":", "raise", "IndexError", "(", "\"Index {} too large for {} qubits.\"", ".", "format", "(", "index", ",", "qubit_num"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_round_to_next_multiple
Round up the the next multiple. :param n: The number to round up. :param m: The multiple. :return: The rounded number
pyquil/wavefunction.py
def _round_to_next_multiple(n, m): """ Round up the the next multiple. :param n: The number to round up. :param m: The multiple. :return: The rounded number """ return n if n % m == 0 else n + m - n % m
def _round_to_next_multiple(n, m): """ Round up the the next multiple. :param n: The number to round up. :param m: The multiple. :return: The rounded number """ return n if n % m == 0 else n + m - n % m
[ "Round", "up", "the", "the", "next", "multiple", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L219-L227
[ "def", "_round_to_next_multiple", "(", "n", ",", "m", ")", ":", "return", "n", "if", "n", "%", "m", "==", "0", "else", "n", "+", "m", "-", "n", "%", "m" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
_octet_bits
Get the bits of an octet. :param o: The octets. :return: The bits as a list in LSB-to-MSB order. :rtype: list
pyquil/wavefunction.py
def _octet_bits(o): """ Get the bits of an octet. :param o: The octets. :return: The bits as a list in LSB-to-MSB order. :rtype: list """ if not isinstance(o, integer_types): raise TypeError("o should be an int") if not (0 <= o <= 255): raise ValueError("o should be betw...
def _octet_bits(o): """ Get the bits of an octet. :param o: The octets. :return: The bits as a list in LSB-to-MSB order. :rtype: list """ if not isinstance(o, integer_types): raise TypeError("o should be an int") if not (0 <= o <= 255): raise ValueError("o should be betw...
[ "Get", "the", "bits", "of", "an", "octet", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L230-L247
[ "def", "_octet_bits", "(", "o", ")", ":", "if", "not", "isinstance", "(", "o", ",", "integer_types", ")", ":", "raise", "TypeError", "(", "\"o should be an int\"", ")", "if", "not", "(", "0", "<=", "o", "<=", "255", ")", ":", "raise", "ValueError", "("...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Wavefunction.from_bit_packed_string
From a bit packed string, unpacks to get the wavefunction :param bytes coef_string: :return:
pyquil/wavefunction.py
def from_bit_packed_string(coef_string): """ From a bit packed string, unpacks to get the wavefunction :param bytes coef_string: :return: """ num_octets = len(coef_string) # Parse the wavefunction wf = np.zeros(num_octets // OCTETS_PER_COMPLEX_DOUBLE, dty...
def from_bit_packed_string(coef_string): """ From a bit packed string, unpacks to get the wavefunction :param bytes coef_string: :return: """ num_octets = len(coef_string) # Parse the wavefunction wf = np.zeros(num_octets // OCTETS_PER_COMPLEX_DOUBLE, dty...
[ "From", "a", "bit", "packed", "string", "unpacks", "to", "get", "the", "wavefunction", ":", "param", "bytes", "coef_string", ":", ":", "return", ":" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L77-L94
[ "def", "from_bit_packed_string", "(", "coef_string", ")", ":", "num_octets", "=", "len", "(", "coef_string", ")", "# Parse the wavefunction", "wf", "=", "np", ".", "zeros", "(", "num_octets", "//", "OCTETS_PER_COMPLEX_DOUBLE", ",", "dtype", "=", "np", ".", "cflo...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Wavefunction.get_outcome_probs
Parses a wavefunction (array of complex amplitudes) and returns a dictionary of outcomes and associated probabilities. :return: A dict with outcomes as keys and probabilities as values. :rtype: dict
pyquil/wavefunction.py
def get_outcome_probs(self): """ Parses a wavefunction (array of complex amplitudes) and returns a dictionary of outcomes and associated probabilities. :return: A dict with outcomes as keys and probabilities as values. :rtype: dict """ outcome_dict = {} q...
def get_outcome_probs(self): """ Parses a wavefunction (array of complex amplitudes) and returns a dictionary of outcomes and associated probabilities. :return: A dict with outcomes as keys and probabilities as values. :rtype: dict """ outcome_dict = {} q...
[ "Parses", "a", "wavefunction", "(", "array", "of", "complex", "amplitudes", ")", "and", "returns", "a", "dictionary", "of", "outcomes", "and", "associated", "probabilities", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L115-L128
[ "def", "get_outcome_probs", "(", "self", ")", ":", "outcome_dict", "=", "{", "}", "qubit_num", "=", "len", "(", "self", ")", "for", "index", ",", "amplitude", "in", "enumerate", "(", "self", ".", "amplitudes", ")", ":", "outcome", "=", "get_bitstring_from_...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Wavefunction.pretty_print_probabilities
Prints outcome probabilities, ignoring all outcomes with approximately zero probabilities (up to a certain number of decimal digits) and rounding the probabilities to decimal_digits. :param int decimal_digits: The number of digits to truncate to. :return: A dict with outcomes as keys and probab...
pyquil/wavefunction.py
def pretty_print_probabilities(self, decimal_digits=2): """ Prints outcome probabilities, ignoring all outcomes with approximately zero probabilities (up to a certain number of decimal digits) and rounding the probabilities to decimal_digits. :param int decimal_digits: The number of dig...
def pretty_print_probabilities(self, decimal_digits=2): """ Prints outcome probabilities, ignoring all outcomes with approximately zero probabilities (up to a certain number of decimal digits) and rounding the probabilities to decimal_digits. :param int decimal_digits: The number of dig...
[ "Prints", "outcome", "probabilities", "ignoring", "all", "outcomes", "with", "approximately", "zero", "probabilities", "(", "up", "to", "a", "certain", "number", "of", "decimal", "digits", ")", "and", "rounding", "the", "probabilities", "to", "decimal_digits", "."...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L130-L146
[ "def", "pretty_print_probabilities", "(", "self", ",", "decimal_digits", "=", "2", ")", ":", "outcome_dict", "=", "{", "}", "qubit_num", "=", "len", "(", "self", ")", "for", "index", ",", "amplitude", "in", "enumerate", "(", "self", ".", "amplitudes", ")",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Wavefunction.pretty_print
Returns a string repr of the wavefunction, ignoring all outcomes with approximately zero amplitude (up to a certain number of decimal digits) and rounding the amplitudes to decimal_digits. :param int decimal_digits: The number of digits to truncate to. :return: A dict with outcomes as k...
pyquil/wavefunction.py
def pretty_print(self, decimal_digits=2): """ Returns a string repr of the wavefunction, ignoring all outcomes with approximately zero amplitude (up to a certain number of decimal digits) and rounding the amplitudes to decimal_digits. :param int decimal_digits: The number of dig...
def pretty_print(self, decimal_digits=2): """ Returns a string repr of the wavefunction, ignoring all outcomes with approximately zero amplitude (up to a certain number of decimal digits) and rounding the amplitudes to decimal_digits. :param int decimal_digits: The number of dig...
[ "Returns", "a", "string", "repr", "of", "the", "wavefunction", "ignoring", "all", "outcomes", "with", "approximately", "zero", "amplitude", "(", "up", "to", "a", "certain", "number", "of", "decimal", "digits", ")", "and", "rounding", "the", "amplitudes", "to",...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L148-L170
[ "def", "pretty_print", "(", "self", ",", "decimal_digits", "=", "2", ")", ":", "outcome_dict", "=", "{", "}", "qubit_num", "=", "len", "(", "self", ")", "pp_string", "=", "\"\"", "for", "index", ",", "amplitude", "in", "enumerate", "(", "self", ".", "a...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Wavefunction.plot
Plots a bar chart with bitstring on the x axis and probability on the y axis. :param list qubit_subset: Optional parameter used for plotting a subset of the Hilbert space.
pyquil/wavefunction.py
def plot(self, qubit_subset=None): """ Plots a bar chart with bitstring on the x axis and probability on the y axis. :param list qubit_subset: Optional parameter used for plotting a subset of the Hilbert space. """ import matplotlib.pyplot as plt prob_dict = self.get_out...
def plot(self, qubit_subset=None): """ Plots a bar chart with bitstring on the x axis and probability on the y axis. :param list qubit_subset: Optional parameter used for plotting a subset of the Hilbert space. """ import matplotlib.pyplot as plt prob_dict = self.get_out...
[ "Plots", "a", "bar", "chart", "with", "bitstring", "on", "the", "x", "axis", "and", "probability", "on", "the", "y", "axis", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L172-L191
[ "def", "plot", "(", "self", ",", "qubit_subset", "=", "None", ")", ":", "import", "matplotlib", ".", "pyplot", "as", "plt", "prob_dict", "=", "self", ".", "get_outcome_probs", "(", ")", "if", "qubit_subset", ":", "sub_dict", "=", "{", "}", "qubit_num", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Wavefunction.sample_bitstrings
Sample bitstrings from the distribution defined by the wavefunction. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits)
pyquil/wavefunction.py
def sample_bitstrings(self, n_samples): """ Sample bitstrings from the distribution defined by the wavefunction. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits) """ possible_bitstrings = np.array(list(itertools.produc...
def sample_bitstrings(self, n_samples): """ Sample bitstrings from the distribution defined by the wavefunction. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits) """ possible_bitstrings = np.array(list(itertools.produc...
[ "Sample", "bitstrings", "from", "the", "distribution", "defined", "by", "the", "wavefunction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/wavefunction.py#L193-L203
[ "def", "sample_bitstrings", "(", "self", ",", "n_samples", ")", ":", "possible_bitstrings", "=", "np", ".", "array", "(", "list", "(", "itertools", ".", "product", "(", "(", "0", ",", "1", ")", ",", "repeat", "=", "len", "(", "self", ")", ")", ")", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
get_default_settings
Return the default settings for generating LaTeX circuits. settings is a dictionary with the following keys: gate_shadow: Whether or not to apply shadowing to the gates. lines: Settings for the lines. gates: Settings for the gates. control: Settings for the control symbols. :return: De...
pyquil/latex/latex_config.py
def get_default_settings(): """ Return the default settings for generating LaTeX circuits. settings is a dictionary with the following keys: gate_shadow: Whether or not to apply shadowing to the gates. lines: Settings for the lines. gates: Settings for the gates. control: Settings f...
def get_default_settings(): """ Return the default settings for generating LaTeX circuits. settings is a dictionary with the following keys: gate_shadow: Whether or not to apply shadowing to the gates. lines: Settings for the lines. gates: Settings for the gates. control: Settings f...
[ "Return", "the", "default", "settings", "for", "generating", "LaTeX", "circuits", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_config.py#L34-L63
[ "def", "get_default_settings", "(", ")", ":", "settings", "=", "dict", "(", ")", "settings", "[", "'gate_shadow'", "]", "=", "True", "settings", "[", "'lines'", "]", "=", "(", "{", "'style'", ":", "'very thin'", ",", "'double_classical'", ":", "True", ",",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
header
Writes the Latex header using the settings file. The header includes all packages and defines all tikz styles. :param dictionary settings: LaTeX settings for document. :return: Header of the LaTeX document. :rtype: string
pyquil/latex/latex_config.py
def header(settings): """ Writes the Latex header using the settings file. The header includes all packages and defines all tikz styles. :param dictionary settings: LaTeX settings for document. :return: Header of the LaTeX document. :rtype: string """ packages = (r"\documentclass[conve...
def header(settings): """ Writes the Latex header using the settings file. The header includes all packages and defines all tikz styles. :param dictionary settings: LaTeX settings for document. :return: Header of the LaTeX document. :rtype: string """ packages = (r"\documentclass[conve...
[ "Writes", "the", "Latex", "header", "using", "the", "settings", "file", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/latex/latex_config.py#L66-L119
[ "def", "header", "(", "settings", ")", ":", "packages", "=", "(", "r\"\\documentclass[convert={density=300,outext=.png}]{standalone}\"", ",", "r\"\\usepackage[margin=1in]{geometry}\"", ",", "r\"\\usepackage[hang,small,bf]{caption}\"", ",", "r\"\\usepackage{tikz}\"", ",", "r\"\\usep...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_check_kraus_ops
Verify that the Kraus operators are of the correct shape and satisfy the correct normalization. :param int n: Number of qubits :param list|tuple kraus_ops: The Kraus operators as numpy.ndarrays.
pyquil/noise.py
def _check_kraus_ops(n, kraus_ops): """ Verify that the Kraus operators are of the correct shape and satisfy the correct normalization. :param int n: Number of qubits :param list|tuple kraus_ops: The Kraus operators as numpy.ndarrays. """ for k in kraus_ops: if not np.shape(k) == (2 ** ...
def _check_kraus_ops(n, kraus_ops): """ Verify that the Kraus operators are of the correct shape and satisfy the correct normalization. :param int n: Number of qubits :param list|tuple kraus_ops: The Kraus operators as numpy.ndarrays. """ for k in kraus_ops: if not np.shape(k) == (2 ** ...
[ "Verify", "that", "the", "Kraus", "operators", "are", "of", "the", "correct", "shape", "and", "satisfy", "the", "correct", "normalization", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L184-L199
[ "def", "_check_kraus_ops", "(", "n", ",", "kraus_ops", ")", ":", "for", "k", "in", "kraus_ops", ":", "if", "not", "np", ".", "shape", "(", "k", ")", "==", "(", "2", "**", "n", ",", "2", "**", "n", ")", ":", "raise", "ValueError", "(", "\"Kraus op...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_create_kraus_pragmas
Generate the pragmas to define a Kraus map for a specific gate on some qubits. :param str name: The name of the gate. :param list|tuple qubit_indices: The qubits :param list|tuple kraus_ops: The Kraus operators as matrices. :return: A QUIL string with PRAGMA ADD-KRAUS ... statements. :rtype: str
pyquil/noise.py
def _create_kraus_pragmas(name, qubit_indices, kraus_ops): """ Generate the pragmas to define a Kraus map for a specific gate on some qubits. :param str name: The name of the gate. :param list|tuple qubit_indices: The qubits :param list|tuple kraus_ops: The Kraus operators as matrices. :return:...
def _create_kraus_pragmas(name, qubit_indices, kraus_ops): """ Generate the pragmas to define a Kraus map for a specific gate on some qubits. :param str name: The name of the gate. :param list|tuple qubit_indices: The qubits :param list|tuple kraus_ops: The Kraus operators as matrices. :return:...
[ "Generate", "the", "pragmas", "to", "define", "a", "Kraus", "map", "for", "a", "specific", "gate", "on", "some", "qubits", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L202-L217
[ "def", "_create_kraus_pragmas", "(", "name", ",", "qubit_indices", ",", "kraus_ops", ")", ":", "pragmas", "=", "[", "Pragma", "(", "\"ADD-KRAUS\"", ",", "[", "name", "]", "+", "list", "(", "qubit_indices", ")", ",", "\"({})\"", ".", "format", "(", "\" \"",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
pauli_kraus_map
r""" Generate the Kraus operators corresponding to a pauli channel. :params list|floats probabilities: The 4^num_qubits list of probabilities specifying the desired pauli channel. There should be either 4 or 16 probabilities specified in the order I, X, Y, Z for 1 qubit or II, IX, IY, IZ, XI, XX, XY, e...
pyquil/noise.py
def pauli_kraus_map(probabilities): r""" Generate the Kraus operators corresponding to a pauli channel. :params list|floats probabilities: The 4^num_qubits list of probabilities specifying the desired pauli channel. There should be either 4 or 16 probabilities specified in the order I, X, Y, Z for 1 qu...
def pauli_kraus_map(probabilities): r""" Generate the Kraus operators corresponding to a pauli channel. :params list|floats probabilities: The 4^num_qubits list of probabilities specifying the desired pauli channel. There should be either 4 or 16 probabilities specified in the order I, X, Y, Z for 1 qu...
[ "r", "Generate", "the", "Kraus", "operators", "corresponding", "to", "a", "pauli", "channel", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L231-L262
[ "def", "pauli_kraus_map", "(", "probabilities", ")", ":", "if", "len", "(", "probabilities", ")", "not", "in", "[", "4", ",", "16", "]", ":", "raise", "ValueError", "(", "\"Currently we only support one or two qubits, \"", "\"so the provided list of probabilities must h...
ec98e453084b0037d69d8c3245f6822a5422593d
train
damping_kraus_map
Generate the Kraus operators corresponding to an amplitude damping noise channel. :param float p: The one-step damping probability. :return: A list [k1, k2] of the Kraus operators that parametrize the map. :rtype: list
pyquil/noise.py
def damping_kraus_map(p=0.10): """ Generate the Kraus operators corresponding to an amplitude damping noise channel. :param float p: The one-step damping probability. :return: A list [k1, k2] of the Kraus operators that parametrize the map. :rtype: list """ damping_op = np.sqrt(p) * np....
def damping_kraus_map(p=0.10): """ Generate the Kraus operators corresponding to an amplitude damping noise channel. :param float p: The one-step damping probability. :return: A list [k1, k2] of the Kraus operators that parametrize the map. :rtype: list """ damping_op = np.sqrt(p) * np....
[ "Generate", "the", "Kraus", "operators", "corresponding", "to", "an", "amplitude", "damping", "noise", "channel", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L265-L278
[ "def", "damping_kraus_map", "(", "p", "=", "0.10", ")", ":", "damping_op", "=", "np", ".", "sqrt", "(", "p", ")", "*", "np", ".", "array", "(", "[", "[", "0", ",", "1", "]", ",", "[", "0", ",", "0", "]", "]", ")", "residual_kraus", "=", "np",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
dephasing_kraus_map
Generate the Kraus operators corresponding to a dephasing channel. :params float p: The one-step dephasing probability. :return: A list [k1, k2] of the Kraus operators that parametrize the map. :rtype: list
pyquil/noise.py
def dephasing_kraus_map(p=0.10): """ Generate the Kraus operators corresponding to a dephasing channel. :params float p: The one-step dephasing probability. :return: A list [k1, k2] of the Kraus operators that parametrize the map. :rtype: list """ return [np.sqrt(1 - p) * np.eye(2), np.sqrt...
def dephasing_kraus_map(p=0.10): """ Generate the Kraus operators corresponding to a dephasing channel. :params float p: The one-step dephasing probability. :return: A list [k1, k2] of the Kraus operators that parametrize the map. :rtype: list """ return [np.sqrt(1 - p) * np.eye(2), np.sqrt...
[ "Generate", "the", "Kraus", "operators", "corresponding", "to", "a", "dephasing", "channel", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L281-L289
[ "def", "dephasing_kraus_map", "(", "p", "=", "0.10", ")", ":", "return", "[", "np", ".", "sqrt", "(", "1", "-", "p", ")", "*", "np", ".", "eye", "(", "2", ")", ",", "np", ".", "sqrt", "(", "p", ")", "*", "np", ".", "diag", "(", "[", "1", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
tensor_kraus_maps
Generate the Kraus map corresponding to the composition of two maps on different qubits. :param list k1: The Kraus operators for the first qubit. :param list k2: The Kraus operators for the second qubit. :return: A list of tensored Kraus operators.
pyquil/noise.py
def tensor_kraus_maps(k1, k2): """ Generate the Kraus map corresponding to the composition of two maps on different qubits. :param list k1: The Kraus operators for the first qubit. :param list k2: The Kraus operators for the second qubit. :return: A list of tensored Kraus operators. """ ...
def tensor_kraus_maps(k1, k2): """ Generate the Kraus map corresponding to the composition of two maps on different qubits. :param list k1: The Kraus operators for the first qubit. :param list k2: The Kraus operators for the second qubit. :return: A list of tensored Kraus operators. """ ...
[ "Generate", "the", "Kraus", "map", "corresponding", "to", "the", "composition", "of", "two", "maps", "on", "different", "qubits", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L292-L301
[ "def", "tensor_kraus_maps", "(", "k1", ",", "k2", ")", ":", "return", "[", "np", ".", "kron", "(", "k1j", ",", "k2l", ")", "for", "k1j", "in", "k1", "for", "k2l", "in", "k2", "]" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
combine_kraus_maps
Generate the Kraus map corresponding to the composition of two maps on the same qubits with k1 being applied to the state after k2. :param list k1: The list of Kraus operators that are applied second. :param list k2: The list of Kraus operators that are applied first. :return: A combinatorially gen...
pyquil/noise.py
def combine_kraus_maps(k1, k2): """ Generate the Kraus map corresponding to the composition of two maps on the same qubits with k1 being applied to the state after k2. :param list k1: The list of Kraus operators that are applied second. :param list k2: The list of Kraus operators that are appli...
def combine_kraus_maps(k1, k2): """ Generate the Kraus map corresponding to the composition of two maps on the same qubits with k1 being applied to the state after k2. :param list k1: The list of Kraus operators that are applied second. :param list k2: The list of Kraus operators that are appli...
[ "Generate", "the", "Kraus", "map", "corresponding", "to", "the", "composition", "of", "two", "maps", "on", "the", "same", "qubits", "with", "k1", "being", "applied", "to", "the", "state", "after", "k2", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L304-L314
[ "def", "combine_kraus_maps", "(", "k1", ",", "k2", ")", ":", "return", "[", "np", ".", "dot", "(", "k1j", ",", "k2l", ")", "for", "k1j", "in", "k1", "for", "k2l", "in", "k2", "]" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
damping_after_dephasing
Generate the Kraus map corresponding to the composition of a dephasing channel followed by an amplitude damping channel. :param float T1: The amplitude damping time :param float T2: The dephasing time :param float gate_time: The gate duration. :return: A list of Kraus operators.
pyquil/noise.py
def damping_after_dephasing(T1, T2, gate_time): """ Generate the Kraus map corresponding to the composition of a dephasing channel followed by an amplitude damping channel. :param float T1: The amplitude damping time :param float T2: The dephasing time :param float gate_time: The gate duration....
def damping_after_dephasing(T1, T2, gate_time): """ Generate the Kraus map corresponding to the composition of a dephasing channel followed by an amplitude damping channel. :param float T1: The amplitude damping time :param float T2: The dephasing time :param float gate_time: The gate duration....
[ "Generate", "the", "Kraus", "map", "corresponding", "to", "the", "composition", "of", "a", "dephasing", "channel", "followed", "by", "an", "amplitude", "damping", "channel", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L317-L345
[ "def", "damping_after_dephasing", "(", "T1", ",", "T2", ",", "gate_time", ")", ":", "assert", "T1", ">=", "0", "assert", "T2", ">=", "0", "if", "T1", "!=", "INFINITY", ":", "damping", "=", "damping_kraus_map", "(", "p", "=", "1", "-", "np", ".", "exp...
ec98e453084b0037d69d8c3245f6822a5422593d
train
get_noisy_gate
Look up the numerical gate representation and a proposed 'noisy' name. :param str gate_name: The Quil gate name :param Tuple[float] params: The gate parameters. :return: A tuple (matrix, noisy_name) with the representation of the ideal gate matrix and a proposed name for the noisy version. :rty...
pyquil/noise.py
def get_noisy_gate(gate_name, params): """ Look up the numerical gate representation and a proposed 'noisy' name. :param str gate_name: The Quil gate name :param Tuple[float] params: The gate parameters. :return: A tuple (matrix, noisy_name) with the representation of the ideal gate matrix ...
def get_noisy_gate(gate_name, params): """ Look up the numerical gate representation and a proposed 'noisy' name. :param str gate_name: The Quil gate name :param Tuple[float] params: The gate parameters. :return: A tuple (matrix, noisy_name) with the representation of the ideal gate matrix ...
[ "Look", "up", "the", "numerical", "gate", "representation", "and", "a", "proposed", "noisy", "name", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L358-L395
[ "def", "get_noisy_gate", "(", "gate_name", ",", "params", ")", ":", "params", "=", "tuple", "(", "params", ")", "if", "gate_name", "==", "\"I\"", ":", "assert", "params", "==", "(", ")", "return", "np", ".", "eye", "(", "2", ")", ",", "\"NOISY-I\"", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_get_program_gates
Get all gate applications appearing in prog. :param Program prog: The program :return: A list of all Gates in prog (without duplicates). :rtype: List[Gate]
pyquil/noise.py
def _get_program_gates(prog): """ Get all gate applications appearing in prog. :param Program prog: The program :return: A list of all Gates in prog (without duplicates). :rtype: List[Gate] """ return sorted({i for i in prog if isinstance(i, Gate)}, key=lambda g: g.out())
def _get_program_gates(prog): """ Get all gate applications appearing in prog. :param Program prog: The program :return: A list of all Gates in prog (without duplicates). :rtype: List[Gate] """ return sorted({i for i in prog if isinstance(i, Gate)}, key=lambda g: g.out())
[ "Get", "all", "gate", "applications", "appearing", "in", "prog", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L398-L406
[ "def", "_get_program_gates", "(", "prog", ")", ":", "return", "sorted", "(", "{", "i", "for", "i", "in", "prog", "if", "isinstance", "(", "i", ",", "Gate", ")", "}", ",", "key", "=", "lambda", "g", ":", "g", ".", "out", "(", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
_decoherence_noise_model
The default noise parameters - T1 = 30 us - T2 = 30 us - 1q gate time = 50 ns - 2q gate time = 150 ns are currently typical for near-term devices. This function will define new gates and add Kraus noise to these gates. It will translate the input program to use the noisy version of the ga...
pyquil/noise.py
def _decoherence_noise_model(gates, T1=30e-6, T2=30e-6, gate_time_1q=50e-9, gate_time_2q=150e-09, ro_fidelity=0.95): """ The default noise parameters - T1 = 30 us - T2 = 30 us - 1q gate time = 50 ns - 2q gate time = 150 ns are currently typical for near-term de...
def _decoherence_noise_model(gates, T1=30e-6, T2=30e-6, gate_time_1q=50e-9, gate_time_2q=150e-09, ro_fidelity=0.95): """ The default noise parameters - T1 = 30 us - T2 = 30 us - 1q gate time = 50 ns - 2q gate time = 150 ns are currently typical for near-term de...
[ "The", "default", "noise", "parameters" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L409-L490
[ "def", "_decoherence_noise_model", "(", "gates", ",", "T1", "=", "30e-6", ",", "T2", "=", "30e-6", ",", "gate_time_1q", "=", "50e-9", ",", "gate_time_2q", "=", "150e-09", ",", "ro_fidelity", "=", "0.95", ")", ":", "all_qubits", "=", "set", "(", "sum", "(...
ec98e453084b0037d69d8c3245f6822a5422593d
train
decoherence_noise_with_asymmetric_ro
Similar to :py:func:`_decoherence_noise_model`, but with asymmetric readout. For simplicity, we use the default values for T1, T2, gate times, et al. and only allow the specification of readout fidelities.
pyquil/noise.py
def decoherence_noise_with_asymmetric_ro(gates: Sequence[Gate], p00=0.975, p11=0.911): """Similar to :py:func:`_decoherence_noise_model`, but with asymmetric readout. For simplicity, we use the default values for T1, T2, gate times, et al. and only allow the specification of readout fidelities. """ ...
def decoherence_noise_with_asymmetric_ro(gates: Sequence[Gate], p00=0.975, p11=0.911): """Similar to :py:func:`_decoherence_noise_model`, but with asymmetric readout. For simplicity, we use the default values for T1, T2, gate times, et al. and only allow the specification of readout fidelities. """ ...
[ "Similar", "to", ":", "py", ":", "func", ":", "_decoherence_noise_model", "but", "with", "asymmetric", "readout", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L493-L503
[ "def", "decoherence_noise_with_asymmetric_ro", "(", "gates", ":", "Sequence", "[", "Gate", "]", ",", "p00", "=", "0.975", ",", "p11", "=", "0.911", ")", ":", "noise_model", "=", "_decoherence_noise_model", "(", "gates", ")", "aprobs", "=", "np", ".", "array"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_noise_model_program_header
Generate the header for a pyquil Program that uses ``noise_model`` to overload noisy gates. The program header consists of 3 sections: - The ``DEFGATE`` statements that define the meaning of the newly introduced "noisy" gate names. - The ``PRAGMA ADD-KRAUS`` statements to overload these n...
pyquil/noise.py
def _noise_model_program_header(noise_model): """ Generate the header for a pyquil Program that uses ``noise_model`` to overload noisy gates. The program header consists of 3 sections: - The ``DEFGATE`` statements that define the meaning of the newly introduced "noisy" gate names. ...
def _noise_model_program_header(noise_model): """ Generate the header for a pyquil Program that uses ``noise_model`` to overload noisy gates. The program header consists of 3 sections: - The ``DEFGATE`` statements that define the meaning of the newly introduced "noisy" gate names. ...
[ "Generate", "the", "header", "for", "a", "pyquil", "Program", "that", "uses", "noise_model", "to", "overload", "noisy", "gates", ".", "The", "program", "header", "consists", "of", "3", "sections", ":" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L506-L545
[ "def", "_noise_model_program_header", "(", "noise_model", ")", ":", "from", "pyquil", ".", "quil", "import", "Program", "p", "=", "Program", "(", ")", "defgates", "=", "set", "(", ")", "for", "k", "in", "noise_model", ".", "gates", ":", "# obtain ideal gate ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
apply_noise_model
Apply a noise model to a program and generated a 'noisy-fied' version of the program. :param Program prog: A Quil Program object. :param NoiseModel noise_model: A NoiseModel, either generated from an ISA or from a simple decoherence model. :return: A new program translated to a noisy gateset and wi...
pyquil/noise.py
def apply_noise_model(prog, noise_model): """ Apply a noise model to a program and generated a 'noisy-fied' version of the program. :param Program prog: A Quil Program object. :param NoiseModel noise_model: A NoiseModel, either generated from an ISA or from a simple decoherence model. :retu...
def apply_noise_model(prog, noise_model): """ Apply a noise model to a program and generated a 'noisy-fied' version of the program. :param Program prog: A Quil Program object. :param NoiseModel noise_model: A NoiseModel, either generated from an ISA or from a simple decoherence model. :retu...
[ "Apply", "a", "noise", "model", "to", "a", "program", "and", "generated", "a", "noisy", "-", "fied", "version", "of", "the", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L548-L569
[ "def", "apply_noise_model", "(", "prog", ",", "noise_model", ")", ":", "new_prog", "=", "_noise_model_program_header", "(", "noise_model", ")", "for", "i", "in", "prog", ":", "if", "isinstance", "(", "i", ",", "Gate", ")", ":", "try", ":", "_", ",", "new...
ec98e453084b0037d69d8c3245f6822a5422593d
train
add_decoherence_noise
Add generic damping and dephasing noise to a program. This high-level function is provided as a convenience to investigate the effects of a generic noise model on a program. For more fine-grained control, please investigate the other methods available in the ``pyquil.noise`` module. In an attempt to c...
pyquil/noise.py
def add_decoherence_noise(prog, T1=30e-6, T2=30e-6, gate_time_1q=50e-9, gate_time_2q=150e-09, ro_fidelity=0.95): """ Add generic damping and dephasing noise to a program. This high-level function is provided as a convenience to investigate the effects of a generic noise model ...
def add_decoherence_noise(prog, T1=30e-6, T2=30e-6, gate_time_1q=50e-9, gate_time_2q=150e-09, ro_fidelity=0.95): """ Add generic damping and dephasing noise to a program. This high-level function is provided as a convenience to investigate the effects of a generic noise model ...
[ "Add", "generic", "damping", "and", "dephasing", "noise", "to", "a", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L572-L619
[ "def", "add_decoherence_noise", "(", "prog", ",", "T1", "=", "30e-6", ",", "T2", "=", "30e-6", ",", "gate_time_1q", "=", "50e-9", ",", "gate_time_2q", "=", "150e-09", ",", "ro_fidelity", "=", "0.95", ")", ":", "gates", "=", "_get_program_gates", "(", "prog...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_bitstring_probs_by_qubit
Ensure that an array ``p`` with bitstring probabilities has a separate axis for each qubit such that ``p[i,j,...,k]`` gives the estimated probability of bitstring ``ij...k``. This should not allocate much memory if ``p`` is already in ``C``-contiguous order (row-major). :param np.array p: An array that en...
pyquil/noise.py
def _bitstring_probs_by_qubit(p): """ Ensure that an array ``p`` with bitstring probabilities has a separate axis for each qubit such that ``p[i,j,...,k]`` gives the estimated probability of bitstring ``ij...k``. This should not allocate much memory if ``p`` is already in ``C``-contiguous order (row-ma...
def _bitstring_probs_by_qubit(p): """ Ensure that an array ``p`` with bitstring probabilities has a separate axis for each qubit such that ``p[i,j,...,k]`` gives the estimated probability of bitstring ``ij...k``. This should not allocate much memory if ``p`` is already in ``C``-contiguous order (row-ma...
[ "Ensure", "that", "an", "array", "p", "with", "bitstring", "probabilities", "has", "a", "separate", "axis", "for", "each", "qubit", "such", "that", "p", "[", "i", "j", "...", "k", "]", "gives", "the", "estimated", "probability", "of", "bitstring", "ij", ...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L622-L636
[ "def", "_bitstring_probs_by_qubit", "(", "p", ")", ":", "p", "=", "np", ".", "asarray", "(", "p", ",", "order", "=", "\"C\"", ")", "num_qubits", "=", "int", "(", "round", "(", "np", ".", "log2", "(", "p", ".", "size", ")", ")", ")", "return", "p"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
estimate_bitstring_probs
Given an array of single shot results estimate the probability distribution over all bitstrings. :param np.array results: A 2d array where the outer axis iterates over shots and the inner axis over bits. :return: An array with as many axes as there are qubit and normalized such that it sums to one. ...
pyquil/noise.py
def estimate_bitstring_probs(results): """ Given an array of single shot results estimate the probability distribution over all bitstrings. :param np.array results: A 2d array where the outer axis iterates over shots and the inner axis over bits. :return: An array with as many axes as there are...
def estimate_bitstring_probs(results): """ Given an array of single shot results estimate the probability distribution over all bitstrings. :param np.array results: A 2d array where the outer axis iterates over shots and the inner axis over bits. :return: An array with as many axes as there are...
[ "Given", "an", "array", "of", "single", "shot", "results", "estimate", "the", "probability", "distribution", "over", "all", "bitstrings", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L639-L652
[ "def", "estimate_bitstring_probs", "(", "results", ")", ":", "nshots", ",", "nq", "=", "np", ".", "shape", "(", "results", ")", "outcomes", "=", "np", ".", "array", "(", "[", "int", "(", "\"\"", ".", "join", "(", "map", "(", "str", ",", "r", ")", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_apply_local_transforms
Given a 2d array of single shot results (outer axis iterates over shots, inner axis over bits) and a list of assignment probability matrices (one for each bit in the readout, ordered like the inner axis of results) apply local 2x2 matrices to each bit index. :param np.array p: An array that enumerates a fu...
pyquil/noise.py
def _apply_local_transforms(p, ts): """ Given a 2d array of single shot results (outer axis iterates over shots, inner axis over bits) and a list of assignment probability matrices (one for each bit in the readout, ordered like the inner axis of results) apply local 2x2 matrices to each bit index. ...
def _apply_local_transforms(p, ts): """ Given a 2d array of single shot results (outer axis iterates over shots, inner axis over bits) and a list of assignment probability matrices (one for each bit in the readout, ordered like the inner axis of results) apply local 2x2 matrices to each bit index. ...
[ "Given", "a", "2d", "array", "of", "single", "shot", "results", "(", "outer", "axis", "iterates", "over", "shots", "inner", "axis", "over", "bits", ")", "and", "a", "list", "of", "assignment", "probability", "matrices", "(", "one", "for", "each", "bit", ...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L658-L688
[ "def", "_apply_local_transforms", "(", "p", ",", "ts", ")", ":", "p_corrected", "=", "_bitstring_probs_by_qubit", "(", "p", ")", "nq", "=", "p_corrected", ".", "ndim", "for", "idx", ",", "trafo_idx", "in", "enumerate", "(", "ts", ")", ":", "# this contractio...
ec98e453084b0037d69d8c3245f6822a5422593d
train
correct_bitstring_probs
Given a 2d array of corrupted bitstring probabilities (outer axis iterates over shots, inner axis over bits) and a list of assignment probability matrices (one for each bit in the readout) compute the corrected probabilities. :param np.array p: An array that enumerates bitstring probabilities. When ...
pyquil/noise.py
def correct_bitstring_probs(p, assignment_probabilities): """ Given a 2d array of corrupted bitstring probabilities (outer axis iterates over shots, inner axis over bits) and a list of assignment probability matrices (one for each bit in the readout) compute the corrected probabilities. :param np.a...
def correct_bitstring_probs(p, assignment_probabilities): """ Given a 2d array of corrupted bitstring probabilities (outer axis iterates over shots, inner axis over bits) and a list of assignment probability matrices (one for each bit in the readout) compute the corrected probabilities. :param np.a...
[ "Given", "a", "2d", "array", "of", "corrupted", "bitstring", "probabilities", "(", "outer", "axis", "iterates", "over", "shots", "inner", "axis", "over", "bits", ")", "and", "a", "list", "of", "assignment", "probability", "matrices", "(", "one", "for", "each...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L715-L736
[ "def", "correct_bitstring_probs", "(", "p", ",", "assignment_probabilities", ")", ":", "return", "_apply_local_transforms", "(", "p", ",", "(", "np", ".", "linalg", ".", "inv", "(", "ap", ")", "for", "ap", "in", "assignment_probabilities", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
bitstring_probs_to_z_moments
Convert between bitstring probabilities and joint Z moment expectations. :param np.array p: An array that enumerates bitstring probabilities. When flattened out ``p = [p_00...0, p_00...1, ...,p_11...1]``. The total number of elements must therefore be a power of 2. The canonical shape has a separat...
pyquil/noise.py
def bitstring_probs_to_z_moments(p): """ Convert between bitstring probabilities and joint Z moment expectations. :param np.array p: An array that enumerates bitstring probabilities. When flattened out ``p = [p_00...0, p_00...1, ...,p_11...1]``. The total number of elements must therefore b...
def bitstring_probs_to_z_moments(p): """ Convert between bitstring probabilities and joint Z moment expectations. :param np.array p: An array that enumerates bitstring probabilities. When flattened out ``p = [p_00...0, p_00...1, ...,p_11...1]``. The total number of elements must therefore b...
[ "Convert", "between", "bitstring", "probabilities", "and", "joint", "Z", "moment", "expectations", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L739-L757
[ "def", "bitstring_probs_to_z_moments", "(", "p", ")", ":", "zmat", "=", "np", ".", "array", "(", "[", "[", "1", ",", "1", "]", ",", "[", "1", ",", "-", "1", "]", "]", ")", "return", "_apply_local_transforms", "(", "p", ",", "(", "zmat", "for", "_...
ec98e453084b0037d69d8c3245f6822a5422593d
train
estimate_assignment_probs
Estimate the readout assignment probabilities for a given qubit ``q``. The returned matrix is of the form:: [[p00 p01] [p10 p11]] :param int q: The index of the qubit. :param int trials: The number of samples for each state preparation. :param Union[QVMConnection,QPUConnection...
pyquil/noise.py
def estimate_assignment_probs(q, trials, cxn, p0=None): """ Estimate the readout assignment probabilities for a given qubit ``q``. The returned matrix is of the form:: [[p00 p01] [p10 p11]] :param int q: The index of the qubit. :param int trials: The number of samples for ...
def estimate_assignment_probs(q, trials, cxn, p0=None): """ Estimate the readout assignment probabilities for a given qubit ``q``. The returned matrix is of the form:: [[p00 p01] [p10 p11]] :param int q: The index of the qubit. :param int trials: The number of samples for ...
[ "Estimate", "the", "readout", "assignment", "probabilities", "for", "a", "given", "qubit", "q", ".", "The", "returned", "matrix", "is", "of", "the", "form", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L760-L784
[ "def", "estimate_assignment_probs", "(", "q", ",", "trials", ",", "cxn", ",", "p0", "=", "None", ")", ":", "from", "pyquil", ".", "quil", "import", "Program", "if", "p0", "is", "None", ":", "# pragma no coverage", "p0", "=", "Program", "(", ")", "results...
ec98e453084b0037d69d8c3245f6822a5422593d
train
KrausModel.unpack_kraus_matrix
Helper to optionally unpack a JSON compatible representation of a complex Kraus matrix. :param Union[list,np.array] m: The representation of a Kraus operator. Either a complex square matrix (as numpy array or nested lists) or a JSON-able pair of real matrices (as nested lists) represent...
pyquil/noise.py
def unpack_kraus_matrix(m): """ Helper to optionally unpack a JSON compatible representation of a complex Kraus matrix. :param Union[list,np.array] m: The representation of a Kraus operator. Either a complex square matrix (as numpy array or nested lists) or a JSON-able pair of real ...
def unpack_kraus_matrix(m): """ Helper to optionally unpack a JSON compatible representation of a complex Kraus matrix. :param Union[list,np.array] m: The representation of a Kraus operator. Either a complex square matrix (as numpy array or nested lists) or a JSON-able pair of real ...
[ "Helper", "to", "optionally", "unpack", "a", "JSON", "compatible", "representation", "of", "a", "complex", "Kraus", "matrix", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L50-L67
[ "def", "unpack_kraus_matrix", "(", "m", ")", ":", "m", "=", "np", ".", "asarray", "(", "m", ",", "dtype", "=", "complex", ")", "if", "m", ".", "ndim", "==", "3", ":", "m", "=", "m", "[", "0", "]", "+", "1j", "*", "m", "[", "1", "]", "if", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
KrausModel.to_dict
Create a dictionary representation of a KrausModel. For example:: { "gate": "RX", "params": np.pi, "targets": [0], "kraus_ops": [ # In this example single Kraus op = ideal RX(pi) gate [[[0, 0], ...
pyquil/noise.py
def to_dict(self): """ Create a dictionary representation of a KrausModel. For example:: { "gate": "RX", "params": np.pi, "targets": [0], "kraus_ops": [ # In this example single Kraus op = ideal RX(pi) gate ...
def to_dict(self): """ Create a dictionary representation of a KrausModel. For example:: { "gate": "RX", "params": np.pi, "targets": [0], "kraus_ops": [ # In this example single Kraus op = ideal RX(pi) gate ...
[ "Create", "a", "dictionary", "representation", "of", "a", "KrausModel", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L69-L93
[ "def", "to_dict", "(", "self", ")", ":", "res", "=", "self", ".", "_asdict", "(", ")", "res", "[", "'kraus_ops'", "]", "=", "[", "[", "k", ".", "real", ".", "tolist", "(", ")", ",", "k", ".", "imag", ".", "tolist", "(", ")", "]", "for", "k", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
KrausModel.from_dict
Recreate a KrausModel from the dictionary representation. :param dict d: The dictionary representing the KrausModel. See `to_dict` for an example. :return: The deserialized KrausModel. :rtype: KrausModel
pyquil/noise.py
def from_dict(d): """ Recreate a KrausModel from the dictionary representation. :param dict d: The dictionary representing the KrausModel. See `to_dict` for an example. :return: The deserialized KrausModel. :rtype: KrausModel """ kraus_ops = [KrausMod...
def from_dict(d): """ Recreate a KrausModel from the dictionary representation. :param dict d: The dictionary representing the KrausModel. See `to_dict` for an example. :return: The deserialized KrausModel. :rtype: KrausModel """ kraus_ops = [KrausMod...
[ "Recreate", "a", "KrausModel", "from", "the", "dictionary", "representation", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L96-L106
[ "def", "from_dict", "(", "d", ")", ":", "kraus_ops", "=", "[", "KrausModel", ".", "unpack_kraus_matrix", "(", "k", ")", "for", "k", "in", "d", "[", "'kraus_ops'", "]", "]", "return", "KrausModel", "(", "d", "[", "'gate'", "]", ",", "d", "[", "'params...
ec98e453084b0037d69d8c3245f6822a5422593d
train
NoiseModel.to_dict
Create a JSON serializable representation of the noise model. For example:: { "gates": [ # list of embedded dictionary representations of KrausModels here [...] ] "assignment_probs": { "0": [[.8, .1], ...
pyquil/noise.py
def to_dict(self): """ Create a JSON serializable representation of the noise model. For example:: { "gates": [ # list of embedded dictionary representations of KrausModels here [...] ] "assignment_probs": { ...
def to_dict(self): """ Create a JSON serializable representation of the noise model. For example:: { "gates": [ # list of embedded dictionary representations of KrausModels here [...] ] "assignment_probs": { ...
[ "Create", "a", "JSON", "serializable", "representation", "of", "the", "noise", "model", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L127-L151
[ "def", "to_dict", "(", "self", ")", ":", "return", "{", "\"gates\"", ":", "[", "km", ".", "to_dict", "(", ")", "for", "km", "in", "self", ".", "gates", "]", ",", "\"assignment_probs\"", ":", "{", "str", "(", "qid", ")", ":", "a", ".", "tolist", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
NoiseModel.from_dict
Re-create the noise model from a dictionary representation. :param Dict[str,Any] d: The dictionary representation. :return: The restored noise model. :rtype: NoiseModel
pyquil/noise.py
def from_dict(d): """ Re-create the noise model from a dictionary representation. :param Dict[str,Any] d: The dictionary representation. :return: The restored noise model. :rtype: NoiseModel """ return NoiseModel( gates=[KrausModel.from_dict(t) for t ...
def from_dict(d): """ Re-create the noise model from a dictionary representation. :param Dict[str,Any] d: The dictionary representation. :return: The restored noise model. :rtype: NoiseModel """ return NoiseModel( gates=[KrausModel.from_dict(t) for t ...
[ "Re", "-", "create", "the", "noise", "model", "from", "a", "dictionary", "representation", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L154-L165
[ "def", "from_dict", "(", "d", ")", ":", "return", "NoiseModel", "(", "gates", "=", "[", "KrausModel", ".", "from_dict", "(", "t", ")", "for", "t", "in", "d", "[", "\"gates\"", "]", "]", ",", "assignment_probs", "=", "{", "int", "(", "qid", ")", ":"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
NoiseModel.gates_by_name
Return all defined noisy gates of a particular gate name. :param str name: The gate name. :return: A list of noise models representing that gate. :rtype: Sequence[KrausModel]
pyquil/noise.py
def gates_by_name(self, name): """ Return all defined noisy gates of a particular gate name. :param str name: The gate name. :return: A list of noise models representing that gate. :rtype: Sequence[KrausModel] """ return [g for g in self.gates if g.gate == name]
def gates_by_name(self, name): """ Return all defined noisy gates of a particular gate name. :param str name: The gate name. :return: A list of noise models representing that gate. :rtype: Sequence[KrausModel] """ return [g for g in self.gates if g.gate == name]
[ "Return", "all", "defined", "noisy", "gates", "of", "a", "particular", "gate", "name", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/noise.py#L167-L175
[ "def", "gates_by_name", "(", "self", ",", "name", ")", ":", "return", "[", "g", "for", "g", "in", "self", ".", "gates", "if", "g", ".", "gate", "==", "name", "]" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
_extract_attribute_dictionary_from_program
Collects the attributes from PYQUIL_PROGRAM_PROPERTIES on the Program object program into a dictionary. :param program: Program to collect attributes from. :return: Dictionary of attributes, keyed on the string attribute name.
pyquil/api/_compiler.py
def _extract_attribute_dictionary_from_program(program: Program) -> Dict[str, Any]: """ Collects the attributes from PYQUIL_PROGRAM_PROPERTIES on the Program object program into a dictionary. :param program: Program to collect attributes from. :return: Dictionary of attributes, keyed on the string ...
def _extract_attribute_dictionary_from_program(program: Program) -> Dict[str, Any]: """ Collects the attributes from PYQUIL_PROGRAM_PROPERTIES on the Program object program into a dictionary. :param program: Program to collect attributes from. :return: Dictionary of attributes, keyed on the string ...
[ "Collects", "the", "attributes", "from", "PYQUIL_PROGRAM_PROPERTIES", "on", "the", "Program", "object", "program", "into", "a", "dictionary", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_compiler.py#L41-L52
[ "def", "_extract_attribute_dictionary_from_program", "(", "program", ":", "Program", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "attrs", "=", "{", "}", "for", "prop", "in", "PYQUIL_PROGRAM_PROPERTIES", ":", "attrs", "[", "prop", "]", "=", "getattr"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_extract_program_from_pyquil_executable_response
Unpacks a rpcq PyQuilExecutableResponse object into a pyQuil Program object. :param response: PyQuilExecutableResponse object to be unpacked. :return: Resulting pyQuil Program object.
pyquil/api/_compiler.py
def _extract_program_from_pyquil_executable_response(response: PyQuilExecutableResponse) -> Program: """ Unpacks a rpcq PyQuilExecutableResponse object into a pyQuil Program object. :param response: PyQuilExecutableResponse object to be unpacked. :return: Resulting pyQuil Program object. """ p ...
def _extract_program_from_pyquil_executable_response(response: PyQuilExecutableResponse) -> Program: """ Unpacks a rpcq PyQuilExecutableResponse object into a pyQuil Program object. :param response: PyQuilExecutableResponse object to be unpacked. :return: Resulting pyQuil Program object. """ p ...
[ "Unpacks", "a", "rpcq", "PyQuilExecutableResponse", "object", "into", "a", "pyQuil", "Program", "object", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_compiler.py#L55-L65
[ "def", "_extract_program_from_pyquil_executable_response", "(", "response", ":", "PyQuilExecutableResponse", ")", "->", "Program", ":", "p", "=", "Program", "(", "response", ".", "program", ")", "for", "attr", ",", "val", "in", "response", ".", "attributes", ".", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_collect_classical_memory_write_locations
Collect classical memory locations that are the destination of MEASURE instructions These locations are important for munging output buffers returned from the QPU server to the shape expected by the user. This is secretly stored on BinaryExecutableResponse. We're careful to make sure these objects are...
pyquil/api/_compiler.py
def _collect_classical_memory_write_locations(program: Program) -> List[Optional[Tuple[int, int]]]: """Collect classical memory locations that are the destination of MEASURE instructions These locations are important for munging output buffers returned from the QPU server to the shape expected by the user....
def _collect_classical_memory_write_locations(program: Program) -> List[Optional[Tuple[int, int]]]: """Collect classical memory locations that are the destination of MEASURE instructions These locations are important for munging output buffers returned from the QPU server to the shape expected by the user....
[ "Collect", "classical", "memory", "locations", "that", "are", "the", "destination", "of", "MEASURE", "instructions" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_compiler.py#L68-L112
[ "def", "_collect_classical_memory_write_locations", "(", "program", ":", "Program", ")", "->", "List", "[", "Optional", "[", "Tuple", "[", "int", ",", "int", "]", "]", "]", ":", "ro_size", "=", "None", "for", "instr", "in", "program", ":", "if", "isinstanc...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_collect_memory_descriptors
Collect Declare instructions that are important for building the patch table. This is secretly stored on BinaryExecutableResponse. We're careful to make sure these objects are json serializable. :return: A dictionary of variable names to specs about the declared region.
pyquil/api/_compiler.py
def _collect_memory_descriptors(program: Program) -> Dict[str, ParameterSpec]: """Collect Declare instructions that are important for building the patch table. This is secretly stored on BinaryExecutableResponse. We're careful to make sure these objects are json serializable. :return: A dictionary of ...
def _collect_memory_descriptors(program: Program) -> Dict[str, ParameterSpec]: """Collect Declare instructions that are important for building the patch table. This is secretly stored on BinaryExecutableResponse. We're careful to make sure these objects are json serializable. :return: A dictionary of ...
[ "Collect", "Declare", "instructions", "that", "are", "important", "for", "building", "the", "patch", "table", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_compiler.py#L115-L126
[ "def", "_collect_memory_descriptors", "(", "program", ":", "Program", ")", "->", "Dict", "[", "str", ",", "ParameterSpec", "]", ":", "return", "{", "instr", ".", "name", ":", "ParameterSpec", "(", "type", "=", "instr", ".", "memory_type", ",", "length", "=...
ec98e453084b0037d69d8c3245f6822a5422593d
train
teleport
Teleport a qubit from start to end using an ancilla qubit
examples/teleportation.py
def teleport(start_index, end_index, ancilla_index): """Teleport a qubit from start to end using an ancilla qubit """ program = make_bell_pair(end_index, ancilla_index) ro = program.declare('ro', memory_size=3) # do the teleportation program.inst(CNOT(start_index, ancilla_index)) program.i...
def teleport(start_index, end_index, ancilla_index): """Teleport a qubit from start to end using an ancilla qubit """ program = make_bell_pair(end_index, ancilla_index) ro = program.declare('ro', memory_size=3) # do the teleportation program.inst(CNOT(start_index, ancilla_index)) program.i...
[ "Teleport", "a", "qubit", "from", "start", "to", "end", "using", "an", "ancilla", "qubit" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/teleportation.py#L30-L51
[ "def", "teleport", "(", "start_index", ",", "end_index", ",", "ancilla_index", ")", ":", "program", "=", "make_bell_pair", "(", "end_index", ",", "ancilla_index", ")", "ro", "=", "program", ".", "declare", "(", "'ro'", ",", "memory_size", "=", "3", ")", "#...
ec98e453084b0037d69d8c3245f6822a5422593d
train
die_program
Generate a quantum program to roll a die of n faces.
examples/quantum_die.py
def die_program(number_of_sides): """ Generate a quantum program to roll a die of n faces. """ prog = Program() n_qubits = qubits_needed(number_of_sides) ro = prog.declare('ro', 'BIT', n_qubits) # Hadamard initialize. for q in range(n_qubits): prog.inst(H(q)) # Measure everyt...
def die_program(number_of_sides): """ Generate a quantum program to roll a die of n faces. """ prog = Program() n_qubits = qubits_needed(number_of_sides) ro = prog.declare('ro', 'BIT', n_qubits) # Hadamard initialize. for q in range(n_qubits): prog.inst(H(q)) # Measure everyt...
[ "Generate", "a", "quantum", "program", "to", "roll", "a", "die", "of", "n", "faces", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/quantum_die.py#L39-L52
[ "def", "die_program", "(", "number_of_sides", ")", ":", "prog", "=", "Program", "(", ")", "n_qubits", "=", "qubits_needed", "(", "number_of_sides", ")", "ro", "=", "prog", ".", "declare", "(", "'ro'", ",", "'BIT'", ",", "n_qubits", ")", "# Hadamard initializ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
process_results
Convert n digit binary result from the QVM to a value on a die.
examples/quantum_die.py
def process_results(results): """ Convert n digit binary result from the QVM to a value on a die. """ raw_results = results[0] processing_result = 0 for each_qubit_measurement in raw_results: processing_result = 2*processing_result + each_qubit_measurement # Convert from 0 indexed to...
def process_results(results): """ Convert n digit binary result from the QVM to a value on a die. """ raw_results = results[0] processing_result = 0 for each_qubit_measurement in raw_results: processing_result = 2*processing_result + each_qubit_measurement # Convert from 0 indexed to...
[ "Convert", "n", "digit", "binary", "result", "from", "the", "QVM", "to", "a", "value", "on", "a", "die", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/quantum_die.py#L55-L65
[ "def", "process_results", "(", "results", ")", ":", "raw_results", "=", "results", "[", "0", "]", "processing_result", "=", "0", "for", "each_qubit_measurement", "in", "raw_results", ":", "processing_result", "=", "2", "*", "processing_result", "+", "each_qubit_me...
ec98e453084b0037d69d8c3245f6822a5422593d
train
roll_die
Roll an n-sided quantum die.
examples/quantum_die.py
def roll_die(qvm, number_of_sides): """ Roll an n-sided quantum die. """ die_compiled = qvm.compile(die_program(number_of_sides)) return process_results(qvm.run(die_compiled))
def roll_die(qvm, number_of_sides): """ Roll an n-sided quantum die. """ die_compiled = qvm.compile(die_program(number_of_sides)) return process_results(qvm.run(die_compiled))
[ "Roll", "an", "n", "-", "sided", "quantum", "die", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/quantum_die.py#L68-L73
[ "def", "roll_die", "(", "qvm", ",", "number_of_sides", ")", ":", "die_compiled", "=", "qvm", ".", "compile", "(", "die_program", "(", "number_of_sides", ")", ")", "return", "process_results", "(", "qvm", ".", "run", "(", "die_compiled", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Gate.controlled
Add the CONTROLLED modifier to the gate with the given control qubit.
pyquil/quilbase.py
def controlled(self, control_qubit): """ Add the CONTROLLED modifier to the gate with the given control qubit. """ control_qubit = unpack_qubit(control_qubit) self.modifiers.insert(0, "CONTROLLED") self.qubits.insert(0, control_qubit) return self
def controlled(self, control_qubit): """ Add the CONTROLLED modifier to the gate with the given control qubit. """ control_qubit = unpack_qubit(control_qubit) self.modifiers.insert(0, "CONTROLLED") self.qubits.insert(0, control_qubit) return self
[ "Add", "the", "CONTROLLED", "modifier", "to", "the", "gate", "with", "the", "given", "control", "qubit", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilbase.py#L127-L136
[ "def", "controlled", "(", "self", ",", "control_qubit", ")", ":", "control_qubit", "=", "unpack_qubit", "(", "control_qubit", ")", "self", ".", "modifiers", ".", "insert", "(", "0", ",", "\"CONTROLLED\"", ")", "self", ".", "qubits", ".", "insert", "(", "0"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
DefGate.out
Prints a readable Quil string representation of this gate. :returns: String representation of a gate :rtype: string
pyquil/quilbase.py
def out(self): """ Prints a readable Quil string representation of this gate. :returns: String representation of a gate :rtype: string """ def format_matrix_element(element): """ Formats a parameterized matrix element. :param element:...
def out(self): """ Prints a readable Quil string representation of this gate. :returns: String representation of a gate :rtype: string """ def format_matrix_element(element): """ Formats a parameterized matrix element. :param element:...
[ "Prints", "a", "readable", "Quil", "string", "representation", "of", "this", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilbase.py#L260-L292
[ "def", "out", "(", "self", ")", ":", "def", "format_matrix_element", "(", "element", ")", ":", "\"\"\"\n Formats a parameterized matrix element.\n\n :param element: {int, float, complex, str} The parameterized element to format.\n \"\"\"", "if", "isinstan...
ec98e453084b0037d69d8c3245f6822a5422593d
train
DefGate.get_constructor
:returns: A function that constructs this gate on variable qubit indices. E.g. `mygate.get_constructor()(1) applies the gate to qubit 1.`
pyquil/quilbase.py
def get_constructor(self): """ :returns: A function that constructs this gate on variable qubit indices. E.g. `mygate.get_constructor()(1) applies the gate to qubit 1.` """ if self.parameters: return lambda *params: lambda *qubits: \ Gate(nam...
def get_constructor(self): """ :returns: A function that constructs this gate on variable qubit indices. E.g. `mygate.get_constructor()(1) applies the gate to qubit 1.` """ if self.parameters: return lambda *params: lambda *qubits: \ Gate(nam...
[ ":", "returns", ":", "A", "function", "that", "constructs", "this", "gate", "on", "variable", "qubit", "indices", ".", "E", ".", "g", ".", "mygate", ".", "get_constructor", "()", "(", "1", ")", "applies", "the", "gate", "to", "qubit", "1", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilbase.py#L294-L303
[ "def", "get_constructor", "(", "self", ")", ":", "if", "self", ".", "parameters", ":", "return", "lambda", "*", "params", ":", "lambda", "*", "qubits", ":", "Gate", "(", "name", "=", "self", ".", "name", ",", "params", "=", "list", "(", "params", ")"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
DefGate.num_args
:return: The number of qubit arguments the gate takes. :rtype: int
pyquil/quilbase.py
def num_args(self): """ :return: The number of qubit arguments the gate takes. :rtype: int """ rows = len(self.matrix) return int(np.log2(rows))
def num_args(self): """ :return: The number of qubit arguments the gate takes. :rtype: int """ rows = len(self.matrix) return int(np.log2(rows))
[ ":", "return", ":", "The", "number", "of", "qubit", "arguments", "the", "gate", "takes", ".", ":", "rtype", ":", "int" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilbase.py#L305-L311
[ "def", "num_args", "(", "self", ")", ":", "rows", "=", "len", "(", "self", ".", "matrix", ")", "return", "int", "(", "np", ".", "log2", "(", "rows", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
gates_in_isa
Generate the full gateset associated with an ISA. :param ISA isa: The instruction set architecture for a QPU. :return: A sequence of Gate objects encapsulating all gates compatible with the ISA. :rtype: Sequence[Gate]
pyquil/device.py
def gates_in_isa(isa): """ Generate the full gateset associated with an ISA. :param ISA isa: The instruction set architecture for a QPU. :return: A sequence of Gate objects encapsulating all gates compatible with the ISA. :rtype: Sequence[Gate] """ gates = [] for q in isa.qubits: ...
def gates_in_isa(isa): """ Generate the full gateset associated with an ISA. :param ISA isa: The instruction set architecture for a QPU. :return: A sequence of Gate objects encapsulating all gates compatible with the ISA. :rtype: Sequence[Gate] """ gates = [] for q in isa.qubits: ...
[ "Generate", "the", "full", "gateset", "associated", "with", "an", "ISA", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L130-L167
[ "def", "gates_in_isa", "(", "isa", ")", ":", "gates", "=", "[", "]", "for", "q", "in", "isa", ".", "qubits", ":", "if", "q", ".", "dead", ":", "# TODO: dead qubits may in the future lead to some implicit re-indexing", "continue", "if", "q", ".", "type", "in", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
isa_from_graph
Generate an ISA object from a NetworkX graph. :param graph: The graph :param oneq_type: The type of 1-qubit gate. Currently 'Xhalves' :param twoq_type: The type of 2-qubit gate. One of 'CZ' or 'CPHASE'.
pyquil/device.py
def isa_from_graph(graph: nx.Graph, oneq_type='Xhalves', twoq_type='CZ') -> ISA: """ Generate an ISA object from a NetworkX graph. :param graph: The graph :param oneq_type: The type of 1-qubit gate. Currently 'Xhalves' :param twoq_type: The type of 2-qubit gate. One of 'CZ' or 'CPHASE'. """ ...
def isa_from_graph(graph: nx.Graph, oneq_type='Xhalves', twoq_type='CZ') -> ISA: """ Generate an ISA object from a NetworkX graph. :param graph: The graph :param oneq_type: The type of 1-qubit gate. Currently 'Xhalves' :param twoq_type: The type of 2-qubit gate. One of 'CZ' or 'CPHASE'. """ ...
[ "Generate", "an", "ISA", "object", "from", "a", "NetworkX", "graph", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L354-L365
[ "def", "isa_from_graph", "(", "graph", ":", "nx", ".", "Graph", ",", "oneq_type", "=", "'Xhalves'", ",", "twoq_type", "=", "'CZ'", ")", "->", "ISA", ":", "all_qubits", "=", "list", "(", "range", "(", "max", "(", "graph", ".", "nodes", ")", "+", "1", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
specs_from_graph
Generate a Specs object from a NetworkX graph with placeholder values for the actual specs. :param graph: The graph
pyquil/device.py
def specs_from_graph(graph: nx.Graph): """ Generate a Specs object from a NetworkX graph with placeholder values for the actual specs. :param graph: The graph """ qspecs = [QubitSpecs(id=q, fRO=0.90, f1QRB=0.99, T1=30e-6, T2=30e-6, fActiveReset=0.99) for q in graph.nodes] especs =...
def specs_from_graph(graph: nx.Graph): """ Generate a Specs object from a NetworkX graph with placeholder values for the actual specs. :param graph: The graph """ qspecs = [QubitSpecs(id=q, fRO=0.90, f1QRB=0.99, T1=30e-6, T2=30e-6, fActiveReset=0.99) for q in graph.nodes] especs =...
[ "Generate", "a", "Specs", "object", "from", "a", "NetworkX", "graph", "with", "placeholder", "values", "for", "the", "actual", "specs", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L368-L378
[ "def", "specs_from_graph", "(", "graph", ":", "nx", ".", "Graph", ")", ":", "qspecs", "=", "[", "QubitSpecs", "(", "id", "=", "q", ",", "fRO", "=", "0.90", ",", "f1QRB", "=", "0.99", ",", "T1", "=", "30e-6", ",", "T2", "=", "30e-6", ",", "fActive...
ec98e453084b0037d69d8c3245f6822a5422593d
train
isa_to_graph
Construct a NetworkX qubit topology from an ISA object. This discards information about supported gates. :param isa: The ISA.
pyquil/device.py
def isa_to_graph(isa: ISA) -> nx.Graph: """ Construct a NetworkX qubit topology from an ISA object. This discards information about supported gates. :param isa: The ISA. """ return nx.from_edgelist(e.targets for e in isa.edges if not e.dead)
def isa_to_graph(isa: ISA) -> nx.Graph: """ Construct a NetworkX qubit topology from an ISA object. This discards information about supported gates. :param isa: The ISA. """ return nx.from_edgelist(e.targets for e in isa.edges if not e.dead)
[ "Construct", "a", "NetworkX", "qubit", "topology", "from", "an", "ISA", "object", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L381-L389
[ "def", "isa_to_graph", "(", "isa", ":", "ISA", ")", "->", "nx", ".", "Graph", ":", "return", "nx", ".", "from_edgelist", "(", "e", ".", "targets", "for", "e", "in", "isa", ".", "edges", "if", "not", "e", ".", "dead", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
ISA.to_dict
Create a JSON-serializable representation of the ISA. The dictionary representation is of the form:: { "1Q": { "0": { "type": "Xhalves" }, "1": { "type": "Xhalves", ...
pyquil/device.py
def to_dict(self): """ Create a JSON-serializable representation of the ISA. The dictionary representation is of the form:: { "1Q": { "0": { "type": "Xhalves" }, "1": { ...
def to_dict(self): """ Create a JSON-serializable representation of the ISA. The dictionary representation is of the form:: { "1Q": { "0": { "type": "Xhalves" }, "1": { ...
[ "Create", "a", "JSON", "-", "serializable", "representation", "of", "the", "ISA", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L52-L105
[ "def", "to_dict", "(", "self", ")", ":", "def", "_maybe_configure", "(", "o", ",", "t", ")", ":", "# type: (Union[Qubit,Edge], str) -> dict", "\"\"\"\n Exclude default values from generated dictionary.\n\n :param Union[Qubit,Edge] o: The object to serialize\n ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
ISA.from_dict
Re-create the ISA from a dictionary representation. :param Dict[str,Any] d: The dictionary representation. :return: The restored ISA. :rtype: ISA
pyquil/device.py
def from_dict(d): """ Re-create the ISA from a dictionary representation. :param Dict[str,Any] d: The dictionary representation. :return: The restored ISA. :rtype: ISA """ return ISA( qubits=sorted([Qubit(id=int(qid), ...
def from_dict(d): """ Re-create the ISA from a dictionary representation. :param Dict[str,Any] d: The dictionary representation. :return: The restored ISA. :rtype: ISA """ return ISA( qubits=sorted([Qubit(id=int(qid), ...
[ "Re", "-", "create", "the", "ISA", "from", "a", "dictionary", "representation", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L108-L127
[ "def", "from_dict", "(", "d", ")", ":", "return", "ISA", "(", "qubits", "=", "sorted", "(", "[", "Qubit", "(", "id", "=", "int", "(", "qid", ")", ",", "type", "=", "q", ".", "get", "(", "\"type\"", ",", "DEFAULT_QUBIT_TYPE", ")", ",", "dead", "="...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Specs.fBellStates
Get a dictionary of two-qubit Bell state fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of Bell state fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float]
pyquil/device.py
def fBellStates(self): """ Get a dictionary of two-qubit Bell state fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of Bell state fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ ...
def fBellStates(self): """ Get a dictionary of two-qubit Bell state fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of Bell state fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ ...
[ "Get", "a", "dictionary", "of", "two", "-", "qubit", "Bell", "state", "fidelities", "(", "normalized", "to", "unity", ")", "from", "the", "specs", "keyed", "by", "targets", "(", "qubit", "-", "qubit", "pairs", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L225-L233
[ "def", "fBellStates", "(", "self", ")", ":", "return", "{", "tuple", "(", "es", ".", "targets", ")", ":", "es", ".", "fBellState", "for", "es", "in", "self", ".", "edges_specs", "}" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Specs.fCZs
Get a dictionary of CZ fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CZ fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float]
pyquil/device.py
def fCZs(self): """ Get a dictionary of CZ fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CZ fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ return {tuple(es.targets): es.f...
def fCZs(self): """ Get a dictionary of CZ fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CZ fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ return {tuple(es.targets): es.f...
[ "Get", "a", "dictionary", "of", "CZ", "fidelities", "(", "normalized", "to", "unity", ")", "from", "the", "specs", "keyed", "by", "targets", "(", "qubit", "-", "qubit", "pairs", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L235-L243
[ "def", "fCZs", "(", "self", ")", ":", "return", "{", "tuple", "(", "es", ".", "targets", ")", ":", "es", ".", "fCZ", "for", "es", "in", "self", ".", "edges_specs", "}" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Specs.fCZ_std_errs
Get a dictionary of the standard errors of the CZ fidelities from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CZ fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float]
pyquil/device.py
def fCZ_std_errs(self): """ Get a dictionary of the standard errors of the CZ fidelities from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CZ fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ return {tuple(es.t...
def fCZ_std_errs(self): """ Get a dictionary of the standard errors of the CZ fidelities from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CZ fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ return {tuple(es.t...
[ "Get", "a", "dictionary", "of", "the", "standard", "errors", "of", "the", "CZ", "fidelities", "from", "the", "specs", "keyed", "by", "targets", "(", "qubit", "-", "qubit", "pairs", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L245-L253
[ "def", "fCZ_std_errs", "(", "self", ")", ":", "return", "{", "tuple", "(", "es", ".", "targets", ")", ":", "es", ".", "fCZ_std_err", "for", "es", "in", "self", ".", "edges_specs", "}" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Specs.fCPHASEs
Get a dictionary of CPHASE fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CPHASE fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float]
pyquil/device.py
def fCPHASEs(self): """ Get a dictionary of CPHASE fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CPHASE fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ return {tuple(es.ta...
def fCPHASEs(self): """ Get a dictionary of CPHASE fidelities (normalized to unity) from the specs, keyed by targets (qubit-qubit pairs). :return: A dictionary of CPHASE fidelities, normalized to unity. :rtype: Dict[tuple(int, int), float] """ return {tuple(es.ta...
[ "Get", "a", "dictionary", "of", "CPHASE", "fidelities", "(", "normalized", "to", "unity", ")", "from", "the", "specs", "keyed", "by", "targets", "(", "qubit", "-", "qubit", "pairs", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L255-L263
[ "def", "fCPHASEs", "(", "self", ")", ":", "return", "{", "tuple", "(", "es", ".", "targets", ")", ":", "es", ".", "fCPHASE", "for", "es", "in", "self", ".", "edges_specs", "}" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Specs.to_dict
Create a JSON-serializable representation of the device Specs. The dictionary representation is of the form:: { '1Q': { "0": { "f1QRB": 0.99, "T1": 20e-6, ... }, ...
pyquil/device.py
def to_dict(self): """ Create a JSON-serializable representation of the device Specs. The dictionary representation is of the form:: { '1Q': { "0": { "f1QRB": 0.99, "T1": 20e-6, ...
def to_dict(self): """ Create a JSON-serializable representation of the device Specs. The dictionary representation is of the form:: { '1Q': { "0": { "f1QRB": 0.99, "T1": 20e-6, ...
[ "Create", "a", "JSON", "-", "serializable", "representation", "of", "the", "device", "Specs", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L265-L324
[ "def", "to_dict", "(", "self", ")", ":", "return", "{", "'1Q'", ":", "{", "\"{}\"", ".", "format", "(", "qs", ".", "id", ")", ":", "{", "'f1QRB'", ":", "qs", ".", "f1QRB", ",", "'fRO'", ":", "qs", ".", "fRO", ",", "'T1'", ":", "qs", ".", "T1"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Specs.from_dict
Re-create the Specs from a dictionary representation. :param Dict[str, Any] d: The dictionary representation. :return: The restored Specs. :rtype: Specs
pyquil/device.py
def from_dict(d): """ Re-create the Specs from a dictionary representation. :param Dict[str, Any] d: The dictionary representation. :return: The restored Specs. :rtype: Specs """ return Specs( qubits_specs=sorted([QubitSpecs(id=int(q), ...
def from_dict(d): """ Re-create the Specs from a dictionary representation. :param Dict[str, Any] d: The dictionary representation. :return: The restored Specs. :rtype: Specs """ return Specs( qubits_specs=sorted([QubitSpecs(id=int(q), ...
[ "Re", "-", "create", "the", "Specs", "from", "a", "dictionary", "representation", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L327-L351
[ "def", "from_dict", "(", "d", ")", ":", "return", "Specs", "(", "qubits_specs", "=", "sorted", "(", "[", "QubitSpecs", "(", "id", "=", "int", "(", "q", ")", ",", "fRO", "=", "qspecs", ".", "get", "(", "'fRO'", ")", ",", "f1QRB", "=", "qspecs", "....
ec98e453084b0037d69d8c3245f6822a5422593d
train
Device.get_isa
Construct an ISA suitable for targeting by compilation. This will raise an exception if the requested ISA is not supported by the device. :param oneq_type: The family of one-qubit gates to target :param twoq_type: The family of two-qubit gates to target
pyquil/device.py
def get_isa(self, oneq_type='Xhalves', twoq_type='CZ') -> ISA: """ Construct an ISA suitable for targeting by compilation. This will raise an exception if the requested ISA is not supported by the device. :param oneq_type: The family of one-qubit gates to target :param twoq_typ...
def get_isa(self, oneq_type='Xhalves', twoq_type='CZ') -> ISA: """ Construct an ISA suitable for targeting by compilation. This will raise an exception if the requested ISA is not supported by the device. :param oneq_type: The family of one-qubit gates to target :param twoq_typ...
[ "Construct", "an", "ISA", "suitable", "for", "targeting", "by", "compilation", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/device.py#L467-L478
[ "def", "get_isa", "(", "self", ",", "oneq_type", "=", "'Xhalves'", ",", "twoq_type", "=", "'CZ'", ")", "->", "ISA", ":", "qubits", "=", "[", "Qubit", "(", "id", "=", "q", ".", "id", ",", "type", "=", "oneq_type", ",", "dead", "=", "q", ".", "dead...
ec98e453084b0037d69d8c3245f6822a5422593d
train
QAM.load
Initialize a QAM into a fresh state. :param executable: Load a compiled executable onto the QAM.
pyquil/api/_qam.py
def load(self, executable): """ Initialize a QAM into a fresh state. :param executable: Load a compiled executable onto the QAM. """ if self.status == 'loaded': warnings.warn("Overwriting previously loaded executable.") assert self.status in ['connected', 'do...
def load(self, executable): """ Initialize a QAM into a fresh state. :param executable: Load a compiled executable onto the QAM. """ if self.status == 'loaded': warnings.warn("Overwriting previously loaded executable.") assert self.status in ['connected', 'do...
[ "Initialize", "a", "QAM", "into", "a", "fresh", "state", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qam.py#L45-L59
[ "def", "load", "(", "self", ",", "executable", ")", ":", "if", "self", ".", "status", "==", "'loaded'", ":", "warnings", ".", "warn", "(", "\"Overwriting previously loaded executable.\"", ")", "assert", "self", ".", "status", "in", "[", "'connected'", ",", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
QAM.write_memory
Writes a value into a memory region on the QAM at a specified offset. :param region_name: Name of the declared memory region on the QAM. :param offset: Integer offset into the memory region to write to. :param value: Value to store at the indicated location.
pyquil/api/_qam.py
def write_memory(self, *, region_name: str, offset: int = 0, value=None): """ Writes a value into a memory region on the QAM at a specified offset. :param region_name: Name of the declared memory region on the QAM. :param offset: Integer offset into the memory region to write to. ...
def write_memory(self, *, region_name: str, offset: int = 0, value=None): """ Writes a value into a memory region on the QAM at a specified offset. :param region_name: Name of the declared memory region on the QAM. :param offset: Integer offset into the memory region to write to. ...
[ "Writes", "a", "value", "into", "a", "memory", "region", "on", "the", "QAM", "at", "a", "specified", "offset", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qam.py#L62-L75
[ "def", "write_memory", "(", "self", ",", "*", ",", "region_name", ":", "str", ",", "offset", ":", "int", "=", "0", ",", "value", "=", "None", ")", ":", "assert", "self", ".", "status", "in", "[", "'loaded'", ",", "'done'", "]", "aref", "=", "Parame...
ec98e453084b0037d69d8c3245f6822a5422593d
train
QAM.read_memory
Reads from a memory region named region_name on the QAM. This is a shim over the eventual API and only can return memory from a region named "ro" of type ``BIT``. :param region_name: The string naming the declared memory region. :return: A list of values of the appropriate type.
pyquil/api/_qam.py
def read_memory(self, *, region_name: str): """ Reads from a memory region named region_name on the QAM. This is a shim over the eventual API and only can return memory from a region named "ro" of type ``BIT``. :param region_name: The string naming the declared memory region. ...
def read_memory(self, *, region_name: str): """ Reads from a memory region named region_name on the QAM. This is a shim over the eventual API and only can return memory from a region named "ro" of type ``BIT``. :param region_name: The string naming the declared memory region. ...
[ "Reads", "from", "a", "memory", "region", "named", "region_name", "on", "the", "QAM", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qam.py#L96-L112
[ "def", "read_memory", "(", "self", ",", "*", ",", "region_name", ":", "str", ")", ":", "assert", "self", ".", "status", "==", "'done'", "if", "region_name", "!=", "\"ro\"", ":", "raise", "QAMError", "(", "\"Currently only allowed to read measurement data from ro.\...
ec98e453084b0037d69d8c3245f6822a5422593d
train
QAM.read_from_memory_region
Reads from a memory region named region_name on the QAM. This is a shim over the eventual API and only can return memory from a region named "ro" of type ``BIT``. :param region_name: The string naming the declared memory region. :return: A list of values of the appropriate type.
pyquil/api/_qam.py
def read_from_memory_region(self, *, region_name: str): """ Reads from a memory region named region_name on the QAM. This is a shim over the eventual API and only can return memory from a region named "ro" of type ``BIT``. :param region_name: The string naming the declared memo...
def read_from_memory_region(self, *, region_name: str): """ Reads from a memory region named region_name on the QAM. This is a shim over the eventual API and only can return memory from a region named "ro" of type ``BIT``. :param region_name: The string naming the declared memo...
[ "Reads", "from", "a", "memory", "region", "named", "region_name", "on", "the", "QAM", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qam.py#L115-L134
[ "def", "read_from_memory_region", "(", "self", ",", "*", ",", "region_name", ":", "str", ")", ":", "warnings", ".", "warn", "(", "\"pyquil.api._qam.QAM.read_from_memory_region is deprecated, please use \"", "\"pyquil.api._qam.QAM.read_memory instead.\"", ",", "DeprecationWarnin...
ec98e453084b0037d69d8c3245f6822a5422593d
train
QAM.reset
Reset the Quantum Abstract Machine to its initial state, which is particularly useful when it has gotten into an unwanted state. This can happen, for example, if the QAM is interrupted in the middle of a run.
pyquil/api/_qam.py
def reset(self): """ Reset the Quantum Abstract Machine to its initial state, which is particularly useful when it has gotten into an unwanted state. This can happen, for example, if the QAM is interrupted in the middle of a run. """ self._variables_shim = {} self...
def reset(self): """ Reset the Quantum Abstract Machine to its initial state, which is particularly useful when it has gotten into an unwanted state. This can happen, for example, if the QAM is interrupted in the middle of a run. """ self._variables_shim = {} self...
[ "Reset", "the", "Quantum", "Abstract", "Machine", "to", "its", "initial", "state", "which", "is", "particularly", "useful", "when", "it", "has", "gotten", "into", "an", "unwanted", "state", ".", "This", "can", "happen", "for", "example", "if", "the", "QAM", ...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qam.py#L137-L147
[ "def", "reset", "(", "self", ")", ":", "self", ".", "_variables_shim", "=", "{", "}", "self", ".", "_executable", "=", "None", "self", ".", "_bitstrings", "=", "None", "self", ".", "status", "=", "'connected'" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
meyer_penny_program
Returns the program to simulate the Meyer-Penny Game The full description is available in docs/source/examples.rst :return: pyQuil Program
examples/meyer_penny_game.py
def meyer_penny_program(): """ Returns the program to simulate the Meyer-Penny Game The full description is available in docs/source/examples.rst :return: pyQuil Program """ prog = pq.Program() ro = prog.declare('ro', memory_size=2) picard_register = ro[1] answer_register = ro[0] ...
def meyer_penny_program(): """ Returns the program to simulate the Meyer-Penny Game The full description is available in docs/source/examples.rst :return: pyQuil Program """ prog = pq.Program() ro = prog.declare('ro', memory_size=2) picard_register = ro[1] answer_register = ro[0] ...
[ "Returns", "the", "program", "to", "simulate", "the", "Meyer", "-", "Penny", "Game", "The", "full", "description", "is", "available", "in", "docs", "/", "source", "/", "examples", ".", "rst" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/meyer_penny_game.py#L26-L53
[ "def", "meyer_penny_program", "(", ")", ":", "prog", "=", "pq", ".", "Program", "(", ")", "ro", "=", "prog", ".", "declare", "(", "'ro'", ",", "memory_size", "=", "2", ")", "picard_register", "=", "ro", "[", "1", "]", "answer_register", "=", "ro", "[...
ec98e453084b0037d69d8c3245f6822a5422593d
train
term_with_coeff
Change the coefficient of a PauliTerm. :param PauliTerm term: A PauliTerm object :param Number coeff: The coefficient to set on the PauliTerm :returns: A new PauliTerm that duplicates term but sets coeff :rtype: PauliTerm
pyquil/paulis.py
def term_with_coeff(term, coeff): """ Change the coefficient of a PauliTerm. :param PauliTerm term: A PauliTerm object :param Number coeff: The coefficient to set on the PauliTerm :returns: A new PauliTerm that duplicates term but sets coeff :rtype: PauliTerm """ if not isinstance(coeff...
def term_with_coeff(term, coeff): """ Change the coefficient of a PauliTerm. :param PauliTerm term: A PauliTerm object :param Number coeff: The coefficient to set on the PauliTerm :returns: A new PauliTerm that duplicates term but sets coeff :rtype: PauliTerm """ if not isinstance(coeff...
[ "Change", "the", "coefficient", "of", "a", "PauliTerm", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L472-L486
[ "def", "term_with_coeff", "(", "term", ",", "coeff", ")", ":", "if", "not", "isinstance", "(", "coeff", ",", "Number", ")", ":", "raise", "ValueError", "(", "\"coeff must be a Number\"", ")", "new_pauli", "=", "term", ".", "copy", "(", ")", "# We cast to a c...
ec98e453084b0037d69d8c3245f6822a5422593d
train
simplify_pauli_sum
Simplify the sum of Pauli operators according to Pauli algebra rules.
pyquil/paulis.py
def simplify_pauli_sum(pauli_sum): """Simplify the sum of Pauli operators according to Pauli algebra rules.""" # You might want to use a defaultdict(list) here, but don't because # we want to do our best to preserve the order of terms. like_terms = OrderedDict() for term in pauli_sum.terms: ...
def simplify_pauli_sum(pauli_sum): """Simplify the sum of Pauli operators according to Pauli algebra rules.""" # You might want to use a defaultdict(list) here, but don't because # we want to do our best to preserve the order of terms. like_terms = OrderedDict() for term in pauli_sum.terms: ...
[ "Simplify", "the", "sum", "of", "Pauli", "operators", "according", "to", "Pauli", "algebra", "rules", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L681-L711
[ "def", "simplify_pauli_sum", "(", "pauli_sum", ")", ":", "# You might want to use a defaultdict(list) here, but don't because", "# we want to do our best to preserve the order of terms.", "like_terms", "=", "OrderedDict", "(", ")", "for", "term", "in", "pauli_sum", ".", "terms", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
check_commutation
Check if commuting a PauliTerm commutes with a list of other terms by natural calculation. Uses the result in Section 3 of arXiv:1405.5749v2, modified slightly here to check for the number of anti-coincidences (which must always be even for commuting PauliTerms) instead of the no. of coincidences, as in the...
pyquil/paulis.py
def check_commutation(pauli_list, pauli_two): """ Check if commuting a PauliTerm commutes with a list of other terms by natural calculation. Uses the result in Section 3 of arXiv:1405.5749v2, modified slightly here to check for the number of anti-coincidences (which must always be even for commuting Pau...
def check_commutation(pauli_list, pauli_two): """ Check if commuting a PauliTerm commutes with a list of other terms by natural calculation. Uses the result in Section 3 of arXiv:1405.5749v2, modified slightly here to check for the number of anti-coincidences (which must always be even for commuting Pau...
[ "Check", "if", "commuting", "a", "PauliTerm", "commutes", "with", "a", "list", "of", "other", "terms", "by", "natural", "calculation", ".", "Uses", "the", "result", "in", "Section", "3", "of", "arXiv", ":", "1405", ".", "5749v2", "modified", "slightly", "h...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L714-L739
[ "def", "check_commutation", "(", "pauli_list", ",", "pauli_two", ")", ":", "def", "coincident_parity", "(", "p1", ",", "p2", ")", ":", "non_similar", "=", "0", "p1_indices", "=", "set", "(", "p1", ".", "_ops", ".", "keys", "(", ")", ")", "p2_indices", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
commuting_sets
Gather the Pauli terms of pauli_terms variable into commuting sets Uses algorithm defined in (Raeisi, Wiebe, Sanders, arXiv:1108.4318, 2011) to find commuting sets. Except uses commutation check from arXiv:1405.5749v2 :param PauliSum pauli_terms: A PauliSum object :returns: List of lists where each li...
pyquil/paulis.py
def commuting_sets(pauli_terms): """Gather the Pauli terms of pauli_terms variable into commuting sets Uses algorithm defined in (Raeisi, Wiebe, Sanders, arXiv:1108.4318, 2011) to find commuting sets. Except uses commutation check from arXiv:1405.5749v2 :param PauliSum pauli_terms: A PauliSum object ...
def commuting_sets(pauli_terms): """Gather the Pauli terms of pauli_terms variable into commuting sets Uses algorithm defined in (Raeisi, Wiebe, Sanders, arXiv:1108.4318, 2011) to find commuting sets. Except uses commutation check from arXiv:1405.5749v2 :param PauliSum pauli_terms: A PauliSum object ...
[ "Gather", "the", "Pauli", "terms", "of", "pauli_terms", "variable", "into", "commuting", "sets" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L742-L768
[ "def", "commuting_sets", "(", "pauli_terms", ")", ":", "m_terms", "=", "len", "(", "pauli_terms", ".", "terms", ")", "m_s", "=", "1", "groups", "=", "[", "]", "groups", ".", "append", "(", "[", "pauli_terms", ".", "terms", "[", "0", "]", "]", ")", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
is_identity
Tests to see if a PauliTerm or PauliSum is a scalar multiple of identity :param term: Either a PauliTerm or PauliSum :returns: True if the PauliTerm or PauliSum is a scalar multiple of identity, False otherwise :rtype: bool
pyquil/paulis.py
def is_identity(term): """ Tests to see if a PauliTerm or PauliSum is a scalar multiple of identity :param term: Either a PauliTerm or PauliSum :returns: True if the PauliTerm or PauliSum is a scalar multiple of identity, False otherwise :rtype: bool """ if isinstance(term, PauliTerm): ...
def is_identity(term): """ Tests to see if a PauliTerm or PauliSum is a scalar multiple of identity :param term: Either a PauliTerm or PauliSum :returns: True if the PauliTerm or PauliSum is a scalar multiple of identity, False otherwise :rtype: bool """ if isinstance(term, PauliTerm): ...
[ "Tests", "to", "see", "if", "a", "PauliTerm", "or", "PauliSum", "is", "a", "scalar", "multiple", "of", "identity" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L771-L785
[ "def", "is_identity", "(", "term", ")", ":", "if", "isinstance", "(", "term", ",", "PauliTerm", ")", ":", "return", "(", "len", "(", "term", ")", "==", "0", ")", "and", "(", "not", "np", ".", "isclose", "(", "term", ".", "coefficient", ",", "0", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
exponential_map
Returns a function f(alpha) that constructs the Program corresponding to exp(-1j*alpha*term). :param term: A pauli term to exponentiate :returns: A function that takes an angle parameter and returns a program. :rtype: Function
pyquil/paulis.py
def exponential_map(term): """ Returns a function f(alpha) that constructs the Program corresponding to exp(-1j*alpha*term). :param term: A pauli term to exponentiate :returns: A function that takes an angle parameter and returns a program. :rtype: Function """ if not np.isclose(np.imag(ter...
def exponential_map(term): """ Returns a function f(alpha) that constructs the Program corresponding to exp(-1j*alpha*term). :param term: A pauli term to exponentiate :returns: A function that takes an angle parameter and returns a program. :rtype: Function """ if not np.isclose(np.imag(ter...
[ "Returns", "a", "function", "f", "(", "alpha", ")", "that", "constructs", "the", "Program", "corresponding", "to", "exp", "(", "-", "1j", "*", "alpha", "*", "term", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L799-L826
[ "def", "exponential_map", "(", "term", ")", ":", "if", "not", "np", ".", "isclose", "(", "np", ".", "imag", "(", "term", ".", "coefficient", ")", ",", "0.0", ")", ":", "raise", "TypeError", "(", "\"PauliTerm coefficient must be real\"", ")", "coeff", "=", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
exponentiate_commuting_pauli_sum
Returns a function that maps all substituent PauliTerms and sums them into a program. NOTE: Use this function with care. Substituent PauliTerms should commute. :param PauliSum pauli_sum: PauliSum to exponentiate. :returns: A function that parametrizes the exponential. :rtype: function
pyquil/paulis.py
def exponentiate_commuting_pauli_sum(pauli_sum): """ Returns a function that maps all substituent PauliTerms and sums them into a program. NOTE: Use this function with care. Substituent PauliTerms should commute. :param PauliSum pauli_sum: PauliSum to exponentiate. :returns: A function that paramet...
def exponentiate_commuting_pauli_sum(pauli_sum): """ Returns a function that maps all substituent PauliTerms and sums them into a program. NOTE: Use this function with care. Substituent PauliTerms should commute. :param PauliSum pauli_sum: PauliSum to exponentiate. :returns: A function that paramet...
[ "Returns", "a", "function", "that", "maps", "all", "substituent", "PauliTerms", "and", "sums", "them", "into", "a", "program", ".", "NOTE", ":", "Use", "this", "function", "with", "care", ".", "Substituent", "PauliTerms", "should", "commute", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L829-L846
[ "def", "exponentiate_commuting_pauli_sum", "(", "pauli_sum", ")", ":", "if", "not", "isinstance", "(", "pauli_sum", ",", "PauliSum", ")", ":", "raise", "TypeError", "(", "\"Argument 'pauli_sum' must be a PauliSum.\"", ")", "fns", "=", "[", "exponential_map", "(", "t...
ec98e453084b0037d69d8c3245f6822a5422593d