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 | _exponentiate_general_case | Returns a Quil (Program()) object corresponding to the exponential of
the pauli_term object, i.e. exp[-1.0j * param * pauli_term]
:param PauliTerm pauli_term: A PauliTerm to exponentiate
:param float param: scalar, non-complex, value
:returns: A Quil program object
:rtype: Program | pyquil/paulis.py | def _exponentiate_general_case(pauli_term, param):
"""
Returns a Quil (Program()) object corresponding to the exponential of
the pauli_term object, i.e. exp[-1.0j * param * pauli_term]
:param PauliTerm pauli_term: A PauliTerm to exponentiate
:param float param: scalar, non-complex, value
:retur... | def _exponentiate_general_case(pauli_term, param):
"""
Returns a Quil (Program()) object corresponding to the exponential of
the pauli_term object, i.e. exp[-1.0j * param * pauli_term]
:param PauliTerm pauli_term: A PauliTerm to exponentiate
:param float param: scalar, non-complex, value
:retur... | [
"Returns",
"a",
"Quil",
"(",
"Program",
"()",
")",
"object",
"corresponding",
"to",
"the",
"exponential",
"of",
"the",
"pauli_term",
"object",
"i",
".",
"e",
".",
"exp",
"[",
"-",
"1",
".",
"0j",
"*",
"param",
"*",
"pauli_term",
"]"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L849-L898 | [
"def",
"_exponentiate_general_case",
"(",
"pauli_term",
",",
"param",
")",
":",
"def",
"reverse_hack",
"(",
"p",
")",
":",
"# A hack to produce a *temporary* program which reverses p.",
"revp",
"=",
"Program",
"(",
")",
"revp",
".",
"inst",
"(",
"list",
"(",
"reve... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | suzuki_trotter | Generate trotterization coefficients for a given number of Trotter steps.
U = exp(A + B) is approximated as exp(w1*o1)exp(w2*o2)... This method returns
a list [(w1, o1), (w2, o2), ... , (wm, om)] of tuples where o=0 corresponds
to the A operator, o=1 corresponds to the B operator, and w is the
coeffici... | pyquil/paulis.py | def suzuki_trotter(trotter_order, trotter_steps):
"""
Generate trotterization coefficients for a given number of Trotter steps.
U = exp(A + B) is approximated as exp(w1*o1)exp(w2*o2)... This method returns
a list [(w1, o1), (w2, o2), ... , (wm, om)] of tuples where o=0 corresponds
to the A operator... | def suzuki_trotter(trotter_order, trotter_steps):
"""
Generate trotterization coefficients for a given number of Trotter steps.
U = exp(A + B) is approximated as exp(w1*o1)exp(w2*o2)... This method returns
a list [(w1, o1), (w2, o2), ... , (wm, om)] of tuples where o=0 corresponds
to the A operator... | [
"Generate",
"trotterization",
"coefficients",
"for",
"a",
"given",
"number",
"of",
"Trotter",
"steps",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L901-L933 | [
"def",
"suzuki_trotter",
"(",
"trotter_order",
",",
"trotter_steps",
")",
":",
"p1",
"=",
"p2",
"=",
"p4",
"=",
"p5",
"=",
"1.0",
"/",
"(",
"4",
"-",
"(",
"4",
"**",
"(",
"1.",
"/",
"3",
")",
")",
")",
"p3",
"=",
"1",
"-",
"4",
"*",
"p1",
"... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | is_zero | Tests to see if a PauliTerm or PauliSum is zero.
:param pauli_object: Either a PauliTerm or PauliSum
:returns: True if PauliTerm is zero, False otherwise
:rtype: bool | pyquil/paulis.py | def is_zero(pauli_object):
"""
Tests to see if a PauliTerm or PauliSum is zero.
:param pauli_object: Either a PauliTerm or PauliSum
:returns: True if PauliTerm is zero, False otherwise
:rtype: bool
"""
if isinstance(pauli_object, PauliTerm):
return np.isclose(pauli_object.coefficien... | def is_zero(pauli_object):
"""
Tests to see if a PauliTerm or PauliSum is zero.
:param pauli_object: Either a PauliTerm or PauliSum
:returns: True if PauliTerm is zero, False otherwise
:rtype: bool
"""
if isinstance(pauli_object, PauliTerm):
return np.isclose(pauli_object.coefficien... | [
"Tests",
"to",
"see",
"if",
"a",
"PauliTerm",
"or",
"PauliSum",
"is",
"zero",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L936-L949 | [
"def",
"is_zero",
"(",
"pauli_object",
")",
":",
"if",
"isinstance",
"(",
"pauli_object",
",",
"PauliTerm",
")",
":",
"return",
"np",
".",
"isclose",
"(",
"pauli_object",
".",
"coefficient",
",",
"0",
")",
"elif",
"isinstance",
"(",
"pauli_object",
",",
"P... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | trotterize | Create a Quil program that approximates exp( (A + B)t) where A and B are
PauliTerm operators.
:param PauliTerm first_pauli_term: PauliTerm denoted `A`
:param PauliTerm second_pauli_term: PauliTerm denoted `B`
:param int trotter_order: Optional argument indicating the Suzuki-Trotter
... | pyquil/paulis.py | def trotterize(first_pauli_term, second_pauli_term, trotter_order=1,
trotter_steps=1):
"""
Create a Quil program that approximates exp( (A + B)t) where A and B are
PauliTerm operators.
:param PauliTerm first_pauli_term: PauliTerm denoted `A`
:param PauliTerm second_pauli_term: PauliT... | def trotterize(first_pauli_term, second_pauli_term, trotter_order=1,
trotter_steps=1):
"""
Create a Quil program that approximates exp( (A + B)t) where A and B are
PauliTerm operators.
:param PauliTerm first_pauli_term: PauliTerm denoted `A`
:param PauliTerm second_pauli_term: PauliT... | [
"Create",
"a",
"Quil",
"program",
"that",
"approximates",
"exp",
"(",
"(",
"A",
"+",
"B",
")",
"t",
")",
"where",
"A",
"and",
"B",
"are",
"PauliTerm",
"operators",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L952-L995 | [
"def",
"trotterize",
"(",
"first_pauli_term",
",",
"second_pauli_term",
",",
"trotter_order",
"=",
"1",
",",
"trotter_steps",
"=",
"1",
")",
":",
"if",
"not",
"(",
"1",
"<=",
"trotter_order",
"<",
"5",
")",
":",
"raise",
"ValueError",
"(",
"\"trotterize only... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliTerm.id | Returns an identifier string for the PauliTerm (ignoring the coefficient).
Don't use this to compare terms. This function will not work with qubits that
aren't sortable.
:param sort_ops: Whether to sort operations by qubit. This is True by default for
backwards compatibility but wi... | pyquil/paulis.py | def id(self, sort_ops=True):
"""
Returns an identifier string for the PauliTerm (ignoring the coefficient).
Don't use this to compare terms. This function will not work with qubits that
aren't sortable.
:param sort_ops: Whether to sort operations by qubit. This is True by defau... | def id(self, sort_ops=True):
"""
Returns an identifier string for the PauliTerm (ignoring the coefficient).
Don't use this to compare terms. This function will not work with qubits that
aren't sortable.
:param sort_ops: Whether to sort operations by qubit. This is True by defau... | [
"Returns",
"an",
"identifier",
"string",
"for",
"the",
"PauliTerm",
"(",
"ignoring",
"the",
"coefficient",
")",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L96-L123 | [
"def",
"id",
"(",
"self",
",",
"sort_ops",
"=",
"True",
")",
":",
"if",
"len",
"(",
"self",
".",
"_ops",
")",
"==",
"0",
"and",
"not",
"sort_ops",
":",
"# This is nefariously backwards-compatibility breaking. There's potentially",
"# lots of code floating around that ... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliTerm.copy | Properly creates a new PauliTerm, with a completely new dictionary
of operators | pyquil/paulis.py | def copy(self):
"""
Properly creates a new PauliTerm, with a completely new dictionary
of operators
"""
new_term = PauliTerm("I", 0, 1.0) # create new object
# manually copy all attributes over
for key in self.__dict__.keys():
val = self.__dict__[key]... | def copy(self):
"""
Properly creates a new PauliTerm, with a completely new dictionary
of operators
"""
new_term = PauliTerm("I", 0, 1.0) # create new object
# manually copy all attributes over
for key in self.__dict__.keys():
val = self.__dict__[key]... | [
"Properly",
"creates",
"a",
"new",
"PauliTerm",
"with",
"a",
"completely",
"new",
"dictionary",
"of",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L159-L173 | [
"def",
"copy",
"(",
"self",
")",
":",
"new_term",
"=",
"PauliTerm",
"(",
"\"I\"",
",",
"0",
",",
"1.0",
")",
"# create new object",
"# manually copy all attributes over",
"for",
"key",
"in",
"self",
".",
"__dict__",
".",
"keys",
"(",
")",
":",
"val",
"=",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliTerm.from_list | Allocates a Pauli Term from a list of operators and indices. This is more efficient than
multiplying together individual terms.
:param list terms_list: A list of tuples, e.g. [("X", 0), ("Y", 1)]
:return: PauliTerm | pyquil/paulis.py | def from_list(cls, terms_list, coefficient=1.0):
"""
Allocates a Pauli Term from a list of operators and indices. This is more efficient than
multiplying together individual terms.
:param list terms_list: A list of tuples, e.g. [("X", 0), ("Y", 1)]
:return: PauliTerm
"""... | def from_list(cls, terms_list, coefficient=1.0):
"""
Allocates a Pauli Term from a list of operators and indices. This is more efficient than
multiplying together individual terms.
:param list terms_list: A list of tuples, e.g. [("X", 0), ("Y", 1)]
:return: PauliTerm
"""... | [
"Allocates",
"a",
"Pauli",
"Term",
"from",
"a",
"list",
"of",
"operators",
"and",
"indices",
".",
"This",
"is",
"more",
"efficient",
"than",
"multiplying",
"together",
"individual",
"terms",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L324-L354 | [
"def",
"from_list",
"(",
"cls",
",",
"terms_list",
",",
"coefficient",
"=",
"1.0",
")",
":",
"if",
"not",
"all",
"(",
"[",
"isinstance",
"(",
"op",
",",
"tuple",
")",
"for",
"op",
"in",
"terms_list",
"]",
")",
":",
"raise",
"TypeError",
"(",
"\"The t... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliTerm.from_compact_str | Construct a PauliTerm from the result of str(pauli_term) | pyquil/paulis.py | def from_compact_str(cls, str_pauli_term):
"""Construct a PauliTerm from the result of str(pauli_term)
"""
coef_str, str_pauli_term = str_pauli_term.split('*')
try:
coef = int(coef_str)
except ValueError:
try:
coef = float(coef_str)
... | def from_compact_str(cls, str_pauli_term):
"""Construct a PauliTerm from the result of str(pauli_term)
"""
coef_str, str_pauli_term = str_pauli_term.split('*')
try:
coef = int(coef_str)
except ValueError:
try:
coef = float(coef_str)
... | [
"Construct",
"a",
"PauliTerm",
"from",
"the",
"result",
"of",
"str",
"(",
"pauli_term",
")"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L357-L378 | [
"def",
"from_compact_str",
"(",
"cls",
",",
"str_pauli_term",
")",
":",
"coef_str",
",",
"str_pauli_term",
"=",
"str_pauli_term",
".",
"split",
"(",
"'*'",
")",
"try",
":",
"coef",
"=",
"int",
"(",
"coef_str",
")",
"except",
"ValueError",
":",
"try",
":",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliTerm.pauli_string | Return a string representation of this PauliTerm without its coefficient and with
implicit qubit indices.
If a list of qubits is provided, each character in the resulting string represents
a Pauli operator on the corresponding qubit. If qubit indices are not provided as input,
the retur... | pyquil/paulis.py | def pauli_string(self, qubits=None):
"""
Return a string representation of this PauliTerm without its coefficient and with
implicit qubit indices.
If a list of qubits is provided, each character in the resulting string represents
a Pauli operator on the corresponding qubit. If q... | def pauli_string(self, qubits=None):
"""
Return a string representation of this PauliTerm without its coefficient and with
implicit qubit indices.
If a list of qubits is provided, each character in the resulting string represents
a Pauli operator on the corresponding qubit. If q... | [
"Return",
"a",
"string",
"representation",
"of",
"this",
"PauliTerm",
"without",
"its",
"coefficient",
"and",
"with",
"implicit",
"qubit",
"indices",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L380-L408 | [
"def",
"pauli_string",
"(",
"self",
",",
"qubits",
"=",
"None",
")",
":",
"if",
"qubits",
"is",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"Please provide a list of qubits when using PauliTerm.pauli_string\"",
",",
"DeprecationWarning",
")",
"qubits",
"=",
"self",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliSum.get_qubits | The support of all the operators in the PauliSum object.
:returns: A list of all the qubits in the sum of terms.
:rtype: list | pyquil/paulis.py | def get_qubits(self):
"""
The support of all the operators in the PauliSum object.
:returns: A list of all the qubits in the sum of terms.
:rtype: list
"""
return list(set().union(*[term.get_qubits() for term in self.terms])) | def get_qubits(self):
"""
The support of all the operators in the PauliSum object.
:returns: A list of all the qubits in the sum of terms.
:rtype: list
"""
return list(set().union(*[term.get_qubits() for term in self.terms])) | [
"The",
"support",
"of",
"all",
"the",
"operators",
"in",
"the",
"PauliSum",
"object",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L654-L661 | [
"def",
"get_qubits",
"(",
"self",
")",
":",
"return",
"list",
"(",
"set",
"(",
")",
".",
"union",
"(",
"*",
"[",
"term",
".",
"get_qubits",
"(",
")",
"for",
"term",
"in",
"self",
".",
"terms",
"]",
")",
")"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PauliSum.get_programs | Get a Pyquil Program corresponding to each term in the PauliSum and a coefficient
for each program
:return: (programs, coefficients) | pyquil/paulis.py | def get_programs(self):
"""
Get a Pyquil Program corresponding to each term in the PauliSum and a coefficient
for each program
:return: (programs, coefficients)
"""
programs = [term.program for term in self.terms]
coefficients = np.array([term.coefficient for ter... | def get_programs(self):
"""
Get a Pyquil Program corresponding to each term in the PauliSum and a coefficient
for each program
:return: (programs, coefficients)
"""
programs = [term.program for term in self.terms]
coefficients = np.array([term.coefficient for ter... | [
"Get",
"a",
"Pyquil",
"Program",
"corresponding",
"to",
"each",
"term",
"in",
"the",
"PauliSum",
"and",
"a",
"coefficient",
"for",
"each",
"program"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/paulis.py#L669-L678 | [
"def",
"get_programs",
"(",
"self",
")",
":",
"programs",
"=",
"[",
"term",
".",
"program",
"for",
"term",
"in",
"self",
".",
"terms",
"]",
"coefficients",
"=",
"np",
".",
"array",
"(",
"[",
"term",
".",
"coefficient",
"for",
"term",
"in",
"self",
".... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | get_json | Get JSON from a Forest endpoint. | pyquil/api/_base_connection.py | def get_json(session, url, params: dict = None):
"""
Get JSON from a Forest endpoint.
"""
res = session.get(url, params=params)
if res.status_code >= 400:
raise parse_error(res)
return res.json() | def get_json(session, url, params: dict = None):
"""
Get JSON from a Forest endpoint.
"""
res = session.get(url, params=params)
if res.status_code >= 400:
raise parse_error(res)
return res.json() | [
"Get",
"JSON",
"from",
"a",
"Forest",
"endpoint",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L42-L49 | [
"def",
"get_json",
"(",
"session",
",",
"url",
",",
"params",
":",
"dict",
"=",
"None",
")",
":",
"res",
"=",
"session",
".",
"get",
"(",
"url",
",",
"params",
"=",
"params",
")",
"if",
"res",
".",
"status_code",
">=",
"400",
":",
"raise",
"parse_e... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | post_json | Post JSON to the Forest endpoint. | pyquil/api/_base_connection.py | def post_json(session, url, json):
"""
Post JSON to the Forest endpoint.
"""
res = session.post(url, json=json)
if res.status_code >= 400:
raise parse_error(res)
return res | def post_json(session, url, json):
"""
Post JSON to the Forest endpoint.
"""
res = session.post(url, json=json)
if res.status_code >= 400:
raise parse_error(res)
return res | [
"Post",
"JSON",
"to",
"the",
"Forest",
"endpoint",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L52-L59 | [
"def",
"post_json",
"(",
"session",
",",
"url",
",",
"json",
")",
":",
"res",
"=",
"session",
".",
"post",
"(",
"url",
",",
"json",
"=",
"json",
")",
"if",
"res",
".",
"status_code",
">=",
"400",
":",
"raise",
"parse_error",
"(",
"res",
")",
"retur... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | parse_error | Every server error should contain a "status" field with a human readable explanation of
what went wrong as well as a "error_type" field indicating the kind of error that can be mapped
to a Python type.
There's a fallback error UnknownError for other types of exceptions (network issues, api
gateway prob... | pyquil/api/_base_connection.py | def parse_error(res):
"""
Every server error should contain a "status" field with a human readable explanation of
what went wrong as well as a "error_type" field indicating the kind of error that can be mapped
to a Python type.
There's a fallback error UnknownError for other types of exceptions (ne... | def parse_error(res):
"""
Every server error should contain a "status" field with a human readable explanation of
what went wrong as well as a "error_type" field indicating the kind of error that can be mapped
to a Python type.
There's a fallback error UnknownError for other types of exceptions (ne... | [
"Every",
"server",
"error",
"should",
"contain",
"a",
"status",
"field",
"with",
"a",
"human",
"readable",
"explanation",
"of",
"what",
"went",
"wrong",
"as",
"well",
"as",
"a",
"error_type",
"field",
"indicating",
"the",
"kind",
"of",
"error",
"that",
"can"... | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L62-L86 | [
"def",
"parse_error",
"(",
"res",
")",
":",
"try",
":",
"body",
"=",
"res",
".",
"json",
"(",
")",
"except",
"JSONDecodeError",
":",
"raise",
"UnknownApiError",
"(",
"res",
".",
"text",
")",
"if",
"'error_type'",
"not",
"in",
"body",
":",
"raise",
"Unk... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | get_session | Create a requests session to access the REST API
:return: requests session
:rtype: Session | pyquil/api/_base_connection.py | def get_session():
"""
Create a requests session to access the REST API
:return: requests session
:rtype: Session
"""
config = PyquilConfig()
session = requests.Session()
retry_adapter = HTTPAdapter(max_retries=Retry(total=3,
method_whit... | def get_session():
"""
Create a requests session to access the REST API
:return: requests session
:rtype: Session
"""
config = PyquilConfig()
session = requests.Session()
retry_adapter = HTTPAdapter(max_retries=Retry(total=3,
method_whit... | [
"Create",
"a",
"requests",
"session",
"to",
"access",
"the",
"REST",
"API"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L89-L116 | [
"def",
"get_session",
"(",
")",
":",
"config",
"=",
"PyquilConfig",
"(",
")",
"session",
"=",
"requests",
".",
"Session",
"(",
")",
"retry_adapter",
"=",
"HTTPAdapter",
"(",
"max_retries",
"=",
"Retry",
"(",
"total",
"=",
"3",
",",
"method_whitelist",
"=",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | validate_noise_probabilities | Is noise_parameter a valid specification of noise probabilities for depolarizing noise?
:param list noise_parameter: List of noise parameter values to be validated. | pyquil/api/_base_connection.py | def validate_noise_probabilities(noise_parameter):
"""
Is noise_parameter a valid specification of noise probabilities for depolarizing noise?
:param list noise_parameter: List of noise parameter values to be validated.
"""
if not noise_parameter:
return
if not isinstance(noise_paramete... | def validate_noise_probabilities(noise_parameter):
"""
Is noise_parameter a valid specification of noise probabilities for depolarizing noise?
:param list noise_parameter: List of noise parameter values to be validated.
"""
if not noise_parameter:
return
if not isinstance(noise_paramete... | [
"Is",
"noise_parameter",
"a",
"valid",
"specification",
"of",
"noise",
"probabilities",
"for",
"depolarizing",
"noise?"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L119-L136 | [
"def",
"validate_noise_probabilities",
"(",
"noise_parameter",
")",
":",
"if",
"not",
"noise_parameter",
":",
"return",
"if",
"not",
"isinstance",
"(",
"noise_parameter",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\"noise_parameter must be a list\"",
")",
"i... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | validate_qubit_list | Check the validity of qubits for the payload.
:param list|range qubit_list: List of qubits to be validated. | pyquil/api/_base_connection.py | def validate_qubit_list(qubit_list):
"""
Check the validity of qubits for the payload.
:param list|range qubit_list: List of qubits to be validated.
"""
if not isinstance(qubit_list, (list, range)):
raise TypeError("run_items must be a list")
if any(not isinstance(i, integer_types) or i... | def validate_qubit_list(qubit_list):
"""
Check the validity of qubits for the payload.
:param list|range qubit_list: List of qubits to be validated.
"""
if not isinstance(qubit_list, (list, range)):
raise TypeError("run_items must be a list")
if any(not isinstance(i, integer_types) or i... | [
"Check",
"the",
"validity",
"of",
"qubits",
"for",
"the",
"payload",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L139-L149 | [
"def",
"validate_qubit_list",
"(",
"qubit_list",
")",
":",
"if",
"not",
"isinstance",
"(",
"qubit_list",
",",
"(",
"list",
",",
"range",
")",
")",
":",
"raise",
"TypeError",
"(",
"\"run_items must be a list\"",
")",
"if",
"any",
"(",
"not",
"isinstance",
"("... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | prepare_register_list | Canonicalize classical addresses for the payload and ready MemoryReference instances
for serialization.
This function will cast keys that are iterables of int-likes to a list of Python
ints. This is to support specifying the register offsets as ``range()`` or numpy
arrays. This mutates ``register_dict`... | pyquil/api/_base_connection.py | def prepare_register_list(register_dict: Dict[str, Union[bool, Sequence[int]]]):
"""
Canonicalize classical addresses for the payload and ready MemoryReference instances
for serialization.
This function will cast keys that are iterables of int-likes to a list of Python
ints. This is to support spec... | def prepare_register_list(register_dict: Dict[str, Union[bool, Sequence[int]]]):
"""
Canonicalize classical addresses for the payload and ready MemoryReference instances
for serialization.
This function will cast keys that are iterables of int-likes to a list of Python
ints. This is to support spec... | [
"Canonicalize",
"classical",
"addresses",
"for",
"the",
"payload",
"and",
"ready",
"MemoryReference",
"instances",
"for",
"serialization",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L152-L180 | [
"def",
"prepare_register_list",
"(",
"register_dict",
":",
"Dict",
"[",
"str",
",",
"Union",
"[",
"bool",
",",
"Sequence",
"[",
"int",
"]",
"]",
"]",
")",
":",
"if",
"not",
"isinstance",
"(",
"register_dict",
",",
"dict",
")",
":",
"raise",
"TypeError",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | run_and_measure_payload | REST payload for :py:func:`ForestConnection._run_and_measure` | pyquil/api/_base_connection.py | def run_and_measure_payload(quil_program, qubits, trials, random_seed):
"""REST payload for :py:func:`ForestConnection._run_and_measure`"""
if not quil_program:
raise ValueError("You have attempted to run an empty program."
" Please provide gates or measure instructions to your ... | def run_and_measure_payload(quil_program, qubits, trials, random_seed):
"""REST payload for :py:func:`ForestConnection._run_and_measure`"""
if not quil_program:
raise ValueError("You have attempted to run an empty program."
" Please provide gates or measure instructions to your ... | [
"REST",
"payload",
"for",
":",
"py",
":",
"func",
":",
"ForestConnection",
".",
"_run_and_measure"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L183-L203 | [
"def",
"run_and_measure_payload",
"(",
"quil_program",
",",
"qubits",
",",
"trials",
",",
"random_seed",
")",
":",
"if",
"not",
"quil_program",
":",
"raise",
"ValueError",
"(",
"\"You have attempted to run an empty program.\"",
"\" Please provide gates or measure instructions... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | wavefunction_payload | REST payload for :py:func:`ForestConnection._wavefunction` | pyquil/api/_base_connection.py | def wavefunction_payload(quil_program, random_seed):
"""REST payload for :py:func:`ForestConnection._wavefunction`"""
if not isinstance(quil_program, Program):
raise TypeError("quil_program must be a Quil program object")
payload = {'type': TYPE_WAVEFUNCTION,
'compiled-quil': quil_pr... | def wavefunction_payload(quil_program, random_seed):
"""REST payload for :py:func:`ForestConnection._wavefunction`"""
if not isinstance(quil_program, Program):
raise TypeError("quil_program must be a Quil program object")
payload = {'type': TYPE_WAVEFUNCTION,
'compiled-quil': quil_pr... | [
"REST",
"payload",
"for",
":",
"py",
":",
"func",
":",
"ForestConnection",
".",
"_wavefunction"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L206-L217 | [
"def",
"wavefunction_payload",
"(",
"quil_program",
",",
"random_seed",
")",
":",
"if",
"not",
"isinstance",
"(",
"quil_program",
",",
"Program",
")",
":",
"raise",
"TypeError",
"(",
"\"quil_program must be a Quil program object\"",
")",
"payload",
"=",
"{",
"'type'... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | expectation_payload | REST payload for :py:func:`ForestConnection._expectation` | pyquil/api/_base_connection.py | def expectation_payload(prep_prog, operator_programs, random_seed):
"""REST payload for :py:func:`ForestConnection._expectation`"""
if operator_programs is None:
operator_programs = [Program()]
if not isinstance(prep_prog, Program):
raise TypeError("prep_prog variable must be a Quil program... | def expectation_payload(prep_prog, operator_programs, random_seed):
"""REST payload for :py:func:`ForestConnection._expectation`"""
if operator_programs is None:
operator_programs = [Program()]
if not isinstance(prep_prog, Program):
raise TypeError("prep_prog variable must be a Quil program... | [
"REST",
"payload",
"for",
":",
"py",
":",
"func",
":",
"ForestConnection",
".",
"_expectation"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L220-L235 | [
"def",
"expectation_payload",
"(",
"prep_prog",
",",
"operator_programs",
",",
"random_seed",
")",
":",
"if",
"operator_programs",
"is",
"None",
":",
"operator_programs",
"=",
"[",
"Program",
"(",
")",
"]",
"if",
"not",
"isinstance",
"(",
"prep_prog",
",",
"Pr... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | qvm_run_payload | REST payload for :py:func:`ForestConnection._qvm_run` | pyquil/api/_base_connection.py | def qvm_run_payload(quil_program, classical_addresses, trials,
measurement_noise, gate_noise, random_seed):
"""REST payload for :py:func:`ForestConnection._qvm_run`"""
if not quil_program:
raise ValueError("You have attempted to run an empty program."
" Pleas... | def qvm_run_payload(quil_program, classical_addresses, trials,
measurement_noise, gate_noise, random_seed):
"""REST payload for :py:func:`ForestConnection._qvm_run`"""
if not quil_program:
raise ValueError("You have attempted to run an empty program."
" Pleas... | [
"REST",
"payload",
"for",
":",
"py",
":",
"func",
":",
"ForestConnection",
".",
"_qvm_run"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L238-L262 | [
"def",
"qvm_run_payload",
"(",
"quil_program",
",",
"classical_addresses",
",",
"trials",
",",
"measurement_noise",
",",
"gate_noise",
",",
"random_seed",
")",
":",
"if",
"not",
"quil_program",
":",
"raise",
"ValueError",
"(",
"\"You have attempted to run an empty progr... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | quilc_compile_payload | REST payload for :py:func:`ForestConnection._quilc_compile` | pyquil/api/_base_connection.py | def quilc_compile_payload(quil_program, isa, specs):
"""REST payload for :py:func:`ForestConnection._quilc_compile`"""
if not quil_program:
raise ValueError("You have attempted to compile an empty program."
" Please provide an actual program.")
if not isinstance(quil_program... | def quilc_compile_payload(quil_program, isa, specs):
"""REST payload for :py:func:`ForestConnection._quilc_compile`"""
if not quil_program:
raise ValueError("You have attempted to compile an empty program."
" Please provide an actual program.")
if not isinstance(quil_program... | [
"REST",
"payload",
"for",
":",
"py",
":",
"func",
":",
"ForestConnection",
".",
"_quilc_compile"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L265-L282 | [
"def",
"quilc_compile_payload",
"(",
"quil_program",
",",
"isa",
",",
"specs",
")",
":",
"if",
"not",
"quil_program",
":",
"raise",
"ValueError",
"(",
"\"You have attempted to compile an empty program.\"",
"\" Please provide an actual program.\"",
")",
"if",
"not",
"isins... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ForestConnection._run_and_measure | Run a Forest ``run_and_measure`` job.
Users should use :py:func:`WavefunctionSimulator.run_and_measure` instead of calling
this directly. | pyquil/api/_base_connection.py | def _run_and_measure(self, quil_program, qubits, trials, random_seed) -> np.ndarray:
"""
Run a Forest ``run_and_measure`` job.
Users should use :py:func:`WavefunctionSimulator.run_and_measure` instead of calling
this directly.
"""
payload = run_and_measure_payload(quil_p... | def _run_and_measure(self, quil_program, qubits, trials, random_seed) -> np.ndarray:
"""
Run a Forest ``run_and_measure`` job.
Users should use :py:func:`WavefunctionSimulator.run_and_measure` instead of calling
this directly.
"""
payload = run_and_measure_payload(quil_p... | [
"Run",
"a",
"Forest",
"run_and_measure",
"job",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L311-L320 | [
"def",
"_run_and_measure",
"(",
"self",
",",
"quil_program",
",",
"qubits",
",",
"trials",
",",
"random_seed",
")",
"->",
"np",
".",
"ndarray",
":",
"payload",
"=",
"run_and_measure_payload",
"(",
"quil_program",
",",
"qubits",
",",
"trials",
",",
"random_seed... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ForestConnection._wavefunction | Run a Forest ``wavefunction`` job.
Users should use :py:func:`WavefunctionSimulator.wavefunction` instead of calling
this directly. | pyquil/api/_base_connection.py | def _wavefunction(self, quil_program, random_seed) -> Wavefunction:
"""
Run a Forest ``wavefunction`` job.
Users should use :py:func:`WavefunctionSimulator.wavefunction` instead of calling
this directly.
"""
payload = wavefunction_payload(quil_program, random_seed)
... | def _wavefunction(self, quil_program, random_seed) -> Wavefunction:
"""
Run a Forest ``wavefunction`` job.
Users should use :py:func:`WavefunctionSimulator.wavefunction` instead of calling
this directly.
"""
payload = wavefunction_payload(quil_program, random_seed)
... | [
"Run",
"a",
"Forest",
"wavefunction",
"job",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L323-L333 | [
"def",
"_wavefunction",
"(",
"self",
",",
"quil_program",
",",
"random_seed",
")",
"->",
"Wavefunction",
":",
"payload",
"=",
"wavefunction_payload",
"(",
"quil_program",
",",
"random_seed",
")",
"response",
"=",
"post_json",
"(",
"self",
".",
"session",
",",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ForestConnection._expectation | Run a Forest ``expectation`` job.
Users should use :py:func:`WavefunctionSimulator.expectation` instead of calling
this directly. | pyquil/api/_base_connection.py | def _expectation(self, prep_prog, operator_programs, random_seed) -> np.ndarray:
"""
Run a Forest ``expectation`` job.
Users should use :py:func:`WavefunctionSimulator.expectation` instead of calling
this directly.
"""
if isinstance(operator_programs, Program):
... | def _expectation(self, prep_prog, operator_programs, random_seed) -> np.ndarray:
"""
Run a Forest ``expectation`` job.
Users should use :py:func:`WavefunctionSimulator.expectation` instead of calling
this directly.
"""
if isinstance(operator_programs, Program):
... | [
"Run",
"a",
"Forest",
"expectation",
"job",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L336-L350 | [
"def",
"_expectation",
"(",
"self",
",",
"prep_prog",
",",
"operator_programs",
",",
"random_seed",
")",
"->",
"np",
".",
"ndarray",
":",
"if",
"isinstance",
"(",
"operator_programs",
",",
"Program",
")",
":",
"warnings",
".",
"warn",
"(",
"\"You have provided... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ForestConnection._qvm_run | Run a Forest ``run`` job on a QVM.
Users should use :py:func:`QVM.run` instead of calling this directly. | pyquil/api/_base_connection.py | def _qvm_run(self, quil_program, classical_addresses, trials,
measurement_noise, gate_noise, random_seed) -> np.ndarray:
"""
Run a Forest ``run`` job on a QVM.
Users should use :py:func:`QVM.run` instead of calling this directly.
"""
payload = qvm_run_payload(qu... | def _qvm_run(self, quil_program, classical_addresses, trials,
measurement_noise, gate_noise, random_seed) -> np.ndarray:
"""
Run a Forest ``run`` job on a QVM.
Users should use :py:func:`QVM.run` instead of calling this directly.
"""
payload = qvm_run_payload(qu... | [
"Run",
"a",
"Forest",
"run",
"job",
"on",
"a",
"QVM",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L353-L369 | [
"def",
"_qvm_run",
"(",
"self",
",",
"quil_program",
",",
"classical_addresses",
",",
"trials",
",",
"measurement_noise",
",",
"gate_noise",
",",
"random_seed",
")",
"->",
"np",
".",
"ndarray",
":",
"payload",
"=",
"qvm_run_payload",
"(",
"quil_program",
",",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ForestConnection._qvm_get_version_info | Return version information for the QVM.
:return: String of QVM version | pyquil/api/_base_connection.py | def _qvm_get_version_info(self) -> dict:
"""
Return version information for the QVM.
:return: String of QVM version
"""
response = post_json(self.session, self.sync_endpoint, {'type': 'version'})
split_version_string = response.text.split()
try:
qvm_v... | def _qvm_get_version_info(self) -> dict:
"""
Return version information for the QVM.
:return: String of QVM version
"""
response = post_json(self.session, self.sync_endpoint, {'type': 'version'})
split_version_string = response.text.split()
try:
qvm_v... | [
"Return",
"version",
"information",
"for",
"the",
"QVM",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L372-L384 | [
"def",
"_qvm_get_version_info",
"(",
"self",
")",
"->",
"dict",
":",
"response",
"=",
"post_json",
"(",
"self",
".",
"session",
",",
"self",
".",
"sync_endpoint",
",",
"{",
"'type'",
":",
"'version'",
"}",
")",
"split_version_string",
"=",
"response",
".",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ForestConnection._quilc_compile | Sends a quilc job to Forest.
Users should use :py:func:`LocalCompiler.quil_to_native_quil` instead of calling this
directly. | pyquil/api/_base_connection.py | def _quilc_compile(self, quil_program, isa, specs):
"""
Sends a quilc job to Forest.
Users should use :py:func:`LocalCompiler.quil_to_native_quil` instead of calling this
directly.
"""
payload = quilc_compile_payload(quil_program, isa, specs)
response = post_json... | def _quilc_compile(self, quil_program, isa, specs):
"""
Sends a quilc job to Forest.
Users should use :py:func:`LocalCompiler.quil_to_native_quil` instead of calling this
directly.
"""
payload = quilc_compile_payload(quil_program, isa, specs)
response = post_json... | [
"Sends",
"a",
"quilc",
"job",
"to",
"Forest",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_base_connection.py#L386-L396 | [
"def",
"_quilc_compile",
"(",
"self",
",",
"quil_program",
",",
"isa",
",",
"specs",
")",
":",
"payload",
"=",
"quilc_compile_payload",
"(",
"quil_program",
",",
"isa",
",",
"specs",
")",
"response",
"=",
"post_json",
"(",
"self",
".",
"session",
",",
"sel... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_flipped_protoquil_program | For symmetrization, generate a program where X gates are added before measurement.
Forest is picky about where the measure instructions happen. It has to be at the end! | pyquil/api/_quantum_computer.py | def _get_flipped_protoquil_program(program: Program) -> Program:
"""For symmetrization, generate a program where X gates are added before measurement.
Forest is picky about where the measure instructions happen. It has to be at the end!
"""
program = program.copy()
to_measure = []
while len(pro... | def _get_flipped_protoquil_program(program: Program) -> Program:
"""For symmetrization, generate a program where X gates are added before measurement.
Forest is picky about where the measure instructions happen. It has to be at the end!
"""
program = program.copy()
to_measure = []
while len(pro... | [
"For",
"symmetrization",
"generate",
"a",
"program",
"where",
"X",
"gates",
"are",
"added",
"before",
"measurement",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L47-L70 | [
"def",
"_get_flipped_protoquil_program",
"(",
"program",
":",
"Program",
")",
"->",
"Program",
":",
"program",
"=",
"program",
".",
"copy",
"(",
")",
"to_measure",
"=",
"[",
"]",
"while",
"len",
"(",
"program",
")",
">",
"0",
":",
"inst",
"=",
"program",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | list_quantum_computers | List the names of available quantum computers
:param connection: An optional :py:class:ForestConnection` object. If not specified,
the default values for URL endpoints will be used, and your API key
will be read from ~/.pyquil_config. If you deign to change any
of these parameters, pass you... | pyquil/api/_quantum_computer.py | def list_quantum_computers(connection: ForestConnection = None,
qpus: bool = True,
qvms: bool = True) -> List[str]:
"""
List the names of available quantum computers
:param connection: An optional :py:class:ForestConnection` object. If not specified,
... | def list_quantum_computers(connection: ForestConnection = None,
qpus: bool = True,
qvms: bool = True) -> List[str]:
"""
List the names of available quantum computers
:param connection: An optional :py:class:ForestConnection` object. If not specified,
... | [
"List",
"the",
"names",
"of",
"available",
"quantum",
"computers"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L276-L299 | [
"def",
"list_quantum_computers",
"(",
"connection",
":",
"ForestConnection",
"=",
"None",
",",
"qpus",
":",
"bool",
"=",
"True",
",",
"qvms",
":",
"bool",
"=",
"True",
")",
"->",
"List",
"[",
"str",
"]",
":",
"if",
"connection",
"is",
"None",
":",
"con... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _parse_name | Try to figure out whether we're getting a (noisy) qvm, and the associated qpu name.
See :py:func:`get_qc` for examples of valid names + flags. | pyquil/api/_quantum_computer.py | def _parse_name(name: str, as_qvm: bool, noisy: bool) -> Tuple[str, str, bool]:
"""
Try to figure out whether we're getting a (noisy) qvm, and the associated qpu name.
See :py:func:`get_qc` for examples of valid names + flags.
"""
parts = name.split('-')
if len(parts) >= 2 and parts[-2] == 'noi... | def _parse_name(name: str, as_qvm: bool, noisy: bool) -> Tuple[str, str, bool]:
"""
Try to figure out whether we're getting a (noisy) qvm, and the associated qpu name.
See :py:func:`get_qc` for examples of valid names + flags.
"""
parts = name.split('-')
if len(parts) >= 2 and parts[-2] == 'noi... | [
"Try",
"to",
"figure",
"out",
"whether",
"we",
"re",
"getting",
"a",
"(",
"noisy",
")",
"qvm",
"and",
"the",
"associated",
"qpu",
"name",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L302-L341 | [
"def",
"_parse_name",
"(",
"name",
":",
"str",
",",
"as_qvm",
":",
"bool",
",",
"noisy",
":",
"bool",
")",
"->",
"Tuple",
"[",
"str",
",",
"str",
",",
"bool",
"]",
":",
"parts",
"=",
"name",
".",
"split",
"(",
"'-'",
")",
"if",
"len",
"(",
"par... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _canonicalize_name | Take the output of _parse_name to create a canonical name. | pyquil/api/_quantum_computer.py | def _canonicalize_name(prefix, qvm_type, noisy):
"""Take the output of _parse_name to create a canonical name.
"""
if noisy:
noise_suffix = '-noisy'
else:
noise_suffix = ''
if qvm_type is None:
qvm_suffix = ''
elif qvm_type == 'qvm':
qvm_suffix = '-qvm'
elif ... | def _canonicalize_name(prefix, qvm_type, noisy):
"""Take the output of _parse_name to create a canonical name.
"""
if noisy:
noise_suffix = '-noisy'
else:
noise_suffix = ''
if qvm_type is None:
qvm_suffix = ''
elif qvm_type == 'qvm':
qvm_suffix = '-qvm'
elif ... | [
"Take",
"the",
"output",
"of",
"_parse_name",
"to",
"create",
"a",
"canonical",
"name",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L344-L362 | [
"def",
"_canonicalize_name",
"(",
"prefix",
",",
"qvm_type",
",",
"noisy",
")",
":",
"if",
"noisy",
":",
"noise_suffix",
"=",
"'-noisy'",
"else",
":",
"noise_suffix",
"=",
"''",
"if",
"qvm_type",
"is",
"None",
":",
"qvm_suffix",
"=",
"''",
"elif",
"qvm_typ... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_qvm_qc | Construct a QuantumComputer backed by a QVM.
This is a minimal wrapper over the QuantumComputer, QVM, and QVMCompiler constructors.
:param name: A string identifying this particular quantum computer.
:param qvm_type: The type of QVM. Either qvm or pyqvm.
:param device: A device following the AbstractD... | pyquil/api/_quantum_computer.py | def _get_qvm_qc(name: str, qvm_type: str, device: AbstractDevice, noise_model: NoiseModel = None,
requires_executable: bool = False,
connection: ForestConnection = None) -> QuantumComputer:
"""Construct a QuantumComputer backed by a QVM.
This is a minimal wrapper over the Quantu... | def _get_qvm_qc(name: str, qvm_type: str, device: AbstractDevice, noise_model: NoiseModel = None,
requires_executable: bool = False,
connection: ForestConnection = None) -> QuantumComputer:
"""Construct a QuantumComputer backed by a QVM.
This is a minimal wrapper over the Quantu... | [
"Construct",
"a",
"QuantumComputer",
"backed",
"by",
"a",
"QVM",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L376-L407 | [
"def",
"_get_qvm_qc",
"(",
"name",
":",
"str",
",",
"qvm_type",
":",
"str",
",",
"device",
":",
"AbstractDevice",
",",
"noise_model",
":",
"NoiseModel",
"=",
"None",
",",
"requires_executable",
":",
"bool",
"=",
"False",
",",
"connection",
":",
"ForestConnec... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_qvm_with_topology | Construct a QVM with the provided topology.
:param name: A name for your quantum computer. This field does not affect behavior of the
constructed QuantumComputer.
:param topology: A graph representing the desired qubit connectivity.
:param noisy: Whether to include a generic noise model. If you wan... | pyquil/api/_quantum_computer.py | def _get_qvm_with_topology(name: str, topology: nx.Graph,
noisy: bool = False,
requires_executable: bool = True,
connection: ForestConnection = None,
qvm_type: str = 'qvm') -> QuantumComputer:
"""Construct a ... | def _get_qvm_with_topology(name: str, topology: nx.Graph,
noisy: bool = False,
requires_executable: bool = True,
connection: ForestConnection = None,
qvm_type: str = 'qvm') -> QuantumComputer:
"""Construct a ... | [
"Construct",
"a",
"QVM",
"with",
"the",
"provided",
"topology",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L410-L438 | [
"def",
"_get_qvm_with_topology",
"(",
"name",
":",
"str",
",",
"topology",
":",
"nx",
".",
"Graph",
",",
"noisy",
":",
"bool",
"=",
"False",
",",
"requires_executable",
":",
"bool",
"=",
"True",
",",
"connection",
":",
"ForestConnection",
"=",
"None",
",",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_9q_square_qvm | A nine-qubit 3x3 square lattice.
This uses a "generic" lattice not tied to any specific device. 9 qubits is large enough
to do vaguely interesting algorithms and small enough to simulate quickly.
:param name: The name of this QVM
:param connection: The connection to use to talk to external services
... | pyquil/api/_quantum_computer.py | def _get_9q_square_qvm(name: str, noisy: bool,
connection: ForestConnection = None,
qvm_type: str = 'qvm') -> QuantumComputer:
"""
A nine-qubit 3x3 square lattice.
This uses a "generic" lattice not tied to any specific device. 9 qubits is large enough
to do... | def _get_9q_square_qvm(name: str, noisy: bool,
connection: ForestConnection = None,
qvm_type: str = 'qvm') -> QuantumComputer:
"""
A nine-qubit 3x3 square lattice.
This uses a "generic" lattice not tied to any specific device. 9 qubits is large enough
to do... | [
"A",
"nine",
"-",
"qubit",
"3x3",
"square",
"lattice",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L441-L461 | [
"def",
"_get_9q_square_qvm",
"(",
"name",
":",
"str",
",",
"noisy",
":",
"bool",
",",
"connection",
":",
"ForestConnection",
"=",
"None",
",",
"qvm_type",
":",
"str",
"=",
"'qvm'",
")",
"->",
"QuantumComputer",
":",
"topology",
"=",
"nx",
".",
"convert_nod... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_unrestricted_qvm | A qvm with a fully-connected topology.
This is obviously the least realistic QVM, but who am I to tell users what they want.
:param name: The name of this QVM
:param noisy: Whether to construct a noisy quantum computer
:param n_qubits: 34 qubits ought to be enough for anybody.
:param connection: T... | pyquil/api/_quantum_computer.py | def _get_unrestricted_qvm(name: str, noisy: bool,
n_qubits: int = 34,
connection: ForestConnection = None,
qvm_type: str = 'qvm') -> QuantumComputer:
"""
A qvm with a fully-connected topology.
This is obviously the least realisti... | def _get_unrestricted_qvm(name: str, noisy: bool,
n_qubits: int = 34,
connection: ForestConnection = None,
qvm_type: str = 'qvm') -> QuantumComputer:
"""
A qvm with a fully-connected topology.
This is obviously the least realisti... | [
"A",
"qvm",
"with",
"a",
"fully",
"-",
"connected",
"topology",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L464-L485 | [
"def",
"_get_unrestricted_qvm",
"(",
"name",
":",
"str",
",",
"noisy",
":",
"bool",
",",
"n_qubits",
":",
"int",
"=",
"34",
",",
"connection",
":",
"ForestConnection",
"=",
"None",
",",
"qvm_type",
":",
"str",
"=",
"'qvm'",
")",
"->",
"QuantumComputer",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_qvm_based_on_real_device | A qvm with a based on a real device.
This is the most realistic QVM.
:param name: The full name of this QVM
:param device: The device from :py:func:`get_lattice`.
:param noisy: Whether to construct a noisy quantum computer by using the device's
associated noise model.
:param connection: An... | pyquil/api/_quantum_computer.py | def _get_qvm_based_on_real_device(name: str, device: Device,
noisy: bool, connection: ForestConnection = None,
qvm_type: str = 'qvm'):
"""
A qvm with a based on a real device.
This is the most realistic QVM.
:param name: The full name... | def _get_qvm_based_on_real_device(name: str, device: Device,
noisy: bool, connection: ForestConnection = None,
qvm_type: str = 'qvm'):
"""
A qvm with a based on a real device.
This is the most realistic QVM.
:param name: The full name... | [
"A",
"qvm",
"with",
"a",
"based",
"on",
"a",
"real",
"device",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L488-L510 | [
"def",
"_get_qvm_based_on_real_device",
"(",
"name",
":",
"str",
",",
"device",
":",
"Device",
",",
"noisy",
":",
"bool",
",",
"connection",
":",
"ForestConnection",
"=",
"None",
",",
"qvm_type",
":",
"str",
"=",
"'qvm'",
")",
":",
"if",
"noisy",
":",
"n... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | get_qc | Get a quantum computer.
A quantum computer is an object of type :py:class:`QuantumComputer` and can be backed
either by a QVM simulator ("Quantum/Quil Virtual Machine") or a physical Rigetti QPU ("Quantum
Processing Unit") made of superconducting qubits.
You can choose the quantum computer to target t... | pyquil/api/_quantum_computer.py | def get_qc(name: str, *, as_qvm: bool = None, noisy: bool = None,
connection: ForestConnection = None) -> QuantumComputer:
"""
Get a quantum computer.
A quantum computer is an object of type :py:class:`QuantumComputer` and can be backed
either by a QVM simulator ("Quantum/Quil Virtual Machin... | def get_qc(name: str, *, as_qvm: bool = None, noisy: bool = None,
connection: ForestConnection = None) -> QuantumComputer:
"""
Get a quantum computer.
A quantum computer is an object of type :py:class:`QuantumComputer` and can be backed
either by a QVM simulator ("Quantum/Quil Virtual Machin... | [
"Get",
"a",
"quantum",
"computer",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L514-L628 | [
"def",
"get_qc",
"(",
"name",
":",
"str",
",",
"*",
",",
"as_qvm",
":",
"bool",
"=",
"None",
",",
"noisy",
":",
"bool",
"=",
"None",
",",
"connection",
":",
"ForestConnection",
"=",
"None",
")",
"->",
"QuantumComputer",
":",
"# 1. Parse name, check for red... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | local_qvm | A context manager for the Rigetti local QVM and QUIL compiler.
You must first have installed the `qvm` and `quilc` executables from
the forest SDK. [https://www.rigetti.com/forest]
This context manager will start up external processes for both the
compiler and virtual machine, and then terminate them ... | pyquil/api/_quantum_computer.py | def local_qvm() -> Iterator[Tuple[subprocess.Popen, subprocess.Popen]]:
"""A context manager for the Rigetti local QVM and QUIL compiler.
You must first have installed the `qvm` and `quilc` executables from
the forest SDK. [https://www.rigetti.com/forest]
This context manager will start up external pr... | def local_qvm() -> Iterator[Tuple[subprocess.Popen, subprocess.Popen]]:
"""A context manager for the Rigetti local QVM and QUIL compiler.
You must first have installed the `qvm` and `quilc` executables from
the forest SDK. [https://www.rigetti.com/forest]
This context manager will start up external pr... | [
"A",
"context",
"manager",
"for",
"the",
"Rigetti",
"local",
"QVM",
"and",
"QUIL",
"compiler",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L632-L673 | [
"def",
"local_qvm",
"(",
")",
"->",
"Iterator",
"[",
"Tuple",
"[",
"subprocess",
".",
"Popen",
",",
"subprocess",
".",
"Popen",
"]",
"]",
":",
"# Enter. Acquire resource",
"qvm",
"=",
"subprocess",
".",
"Popen",
"(",
"[",
"'qvm'",
",",
"'-S'",
"]",
",",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QuantumComputer.get_isa | Return a target ISA for this QuantumComputer's device.
See :py:func:`AbstractDevice.get_isa` for more.
:param oneq_type: The family of one-qubit gates to target
:param twoq_type: The family of two-qubit gates to target | pyquil/api/_quantum_computer.py | def get_isa(self, oneq_type: str = 'Xhalves',
twoq_type: str = 'CZ') -> ISA:
"""
Return a target ISA for this QuantumComputer's device.
See :py:func:`AbstractDevice.get_isa` for more.
:param oneq_type: The family of one-qubit gates to target
:param twoq_type: Th... | def get_isa(self, oneq_type: str = 'Xhalves',
twoq_type: str = 'CZ') -> ISA:
"""
Return a target ISA for this QuantumComputer's device.
See :py:func:`AbstractDevice.get_isa` for more.
:param oneq_type: The family of one-qubit gates to target
:param twoq_type: Th... | [
"Return",
"a",
"target",
"ISA",
"for",
"this",
"QuantumComputer",
"s",
"device",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L122-L132 | [
"def",
"get_isa",
"(",
"self",
",",
"oneq_type",
":",
"str",
"=",
"'Xhalves'",
",",
"twoq_type",
":",
"str",
"=",
"'CZ'",
")",
"->",
"ISA",
":",
"return",
"self",
".",
"device",
".",
"get_isa",
"(",
"oneq_type",
"=",
"oneq_type",
",",
"twoq_type",
"=",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QuantumComputer.run | Run a quil executable. If the executable contains declared parameters, then a memory
map must be provided, which defines the runtime values of these parameters.
:param executable: The program to run. You are responsible for compiling this first.
:param memory_map: The mapping of declared parame... | pyquil/api/_quantum_computer.py | def run(self, executable: Executable,
memory_map: Dict[str, List[Union[int, float]]] = None) -> np.ndarray:
"""
Run a quil executable. If the executable contains declared parameters, then a memory
map must be provided, which defines the runtime values of these parameters.
:p... | def run(self, executable: Executable,
memory_map: Dict[str, List[Union[int, float]]] = None) -> np.ndarray:
"""
Run a quil executable. If the executable contains declared parameters, then a memory
map must be provided, which defines the runtime values of these parameters.
:p... | [
"Run",
"a",
"quil",
"executable",
".",
"If",
"the",
"executable",
"contains",
"declared",
"parameters",
"then",
"a",
"memory",
"map",
"must",
"be",
"provided",
"which",
"defines",
"the",
"runtime",
"values",
"of",
"these",
"parameters",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L135-L154 | [
"def",
"run",
"(",
"self",
",",
"executable",
":",
"Executable",
",",
"memory_map",
":",
"Dict",
"[",
"str",
",",
"List",
"[",
"Union",
"[",
"int",
",",
"float",
"]",
"]",
"]",
"=",
"None",
")",
"->",
"np",
".",
"ndarray",
":",
"self",
".",
"qam"... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QuantumComputer.run_symmetrized_readout | Run a quil program in such a way that the readout error is made collectively symmetric
This means the probability of a bitstring ``b`` being mistaken for a bitstring ``c`` is
the same as the probability of ``not(b)`` being mistaken for ``not(c)``
A more general symmetrization would guarantee t... | pyquil/api/_quantum_computer.py | def run_symmetrized_readout(self, program: Program, trials: int) -> np.ndarray:
"""
Run a quil program in such a way that the readout error is made collectively symmetric
This means the probability of a bitstring ``b`` being mistaken for a bitstring ``c`` is
the same as the probability ... | def run_symmetrized_readout(self, program: Program, trials: int) -> np.ndarray:
"""
Run a quil program in such a way that the readout error is made collectively symmetric
This means the probability of a bitstring ``b`` being mistaken for a bitstring ``c`` is
the same as the probability ... | [
"Run",
"a",
"quil",
"program",
"in",
"such",
"a",
"way",
"that",
"the",
"readout",
"error",
"is",
"made",
"collectively",
"symmetric"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L157-L190 | [
"def",
"run_symmetrized_readout",
"(",
"self",
",",
"program",
":",
"Program",
",",
"trials",
":",
"int",
")",
"->",
"np",
".",
"ndarray",
":",
"flipped_program",
"=",
"_get_flipped_protoquil_program",
"(",
"program",
")",
"if",
"trials",
"%",
"2",
"!=",
"0"... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QuantumComputer.run_and_measure | Run the provided state preparation program and measure all qubits.
This will measure all the qubits on this QuantumComputer, not just qubits
that are used in the program.
The returned data is a dictionary keyed by qubit index because qubits for a given
QuantumComputer may be non-contig... | pyquil/api/_quantum_computer.py | def run_and_measure(self, program: Program, trials: int) -> Dict[int, np.ndarray]:
"""
Run the provided state preparation program and measure all qubits.
This will measure all the qubits on this QuantumComputer, not just qubits
that are used in the program.
The returned data is... | def run_and_measure(self, program: Program, trials: int) -> Dict[int, np.ndarray]:
"""
Run the provided state preparation program and measure all qubits.
This will measure all the qubits on this QuantumComputer, not just qubits
that are used in the program.
The returned data is... | [
"Run",
"the",
"provided",
"state",
"preparation",
"program",
"and",
"measure",
"all",
"qubits",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L193-L231 | [
"def",
"run_and_measure",
"(",
"self",
",",
"program",
":",
"Program",
",",
"trials",
":",
"int",
")",
"->",
"Dict",
"[",
"int",
",",
"np",
".",
"ndarray",
"]",
":",
"program",
"=",
"program",
".",
"copy",
"(",
")",
"validate_supported_quil",
"(",
"pro... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QuantumComputer.compile | A high-level interface to program compilation.
Compilation currently consists of two stages. Please see the :py:class:`AbstractCompiler`
docs for more information. This function does all stages of compilation.
Right now both ``to_native_gates`` and ``optimize`` must be either both set or both
... | pyquil/api/_quantum_computer.py | def compile(self, program: Program,
to_native_gates: bool = True,
optimize: bool = True) -> Union[BinaryExecutableResponse, PyQuilExecutableResponse]:
"""
A high-level interface to program compilation.
Compilation currently consists of two stages. Please see the ... | def compile(self, program: Program,
to_native_gates: bool = True,
optimize: bool = True) -> Union[BinaryExecutableResponse, PyQuilExecutableResponse]:
"""
A high-level interface to program compilation.
Compilation currently consists of two stages. Please see the ... | [
"A",
"high",
"-",
"level",
"interface",
"to",
"program",
"compilation",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_quantum_computer.py#L234-L260 | [
"def",
"compile",
"(",
"self",
",",
"program",
":",
"Program",
",",
"to_native_gates",
":",
"bool",
"=",
"True",
",",
"optimize",
":",
"bool",
"=",
"True",
")",
"->",
"Union",
"[",
"BinaryExecutableResponse",
",",
"PyQuilExecutableResponse",
"]",
":",
"flags... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | decode_buffer | Translate a DataBuffer into a numpy array.
:param buffer: Dictionary with 'data' byte array, 'dtype', and 'shape' fields
:return: NumPy array of decoded data | pyquil/api/_qpu.py | def decode_buffer(buffer: dict) -> np.ndarray:
"""
Translate a DataBuffer into a numpy array.
:param buffer: Dictionary with 'data' byte array, 'dtype', and 'shape' fields
:return: NumPy array of decoded data
"""
buf = np.frombuffer(buffer['data'], dtype=buffer['dtype'])
return buf.reshape(... | def decode_buffer(buffer: dict) -> np.ndarray:
"""
Translate a DataBuffer into a numpy array.
:param buffer: Dictionary with 'data' byte array, 'dtype', and 'shape' fields
:return: NumPy array of decoded data
"""
buf = np.frombuffer(buffer['data'], dtype=buffer['dtype'])
return buf.reshape(... | [
"Translate",
"a",
"DataBuffer",
"into",
"a",
"numpy",
"array",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L31-L39 | [
"def",
"decode_buffer",
"(",
"buffer",
":",
"dict",
")",
"->",
"np",
".",
"ndarray",
":",
"buf",
"=",
"np",
".",
"frombuffer",
"(",
"buffer",
"[",
"'data'",
"]",
",",
"dtype",
"=",
"buffer",
"[",
"'dtype'",
"]",
")",
"return",
"buf",
".",
"reshape",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _extract_bitstrings | De-mux qubit readout results and assemble them into the ro-bitstrings in the correct order.
:param ro_sources: Specification of the ro_sources, cf
:py:func:`pyquil.api._compiler._collect_classical_memory_write_locations`.
It is a list whose value ``(q, m)`` at index ``addr`` records that the ``m``-... | pyquil/api/_qpu.py | def _extract_bitstrings(ro_sources: List[Optional[Tuple[int, int]]],
buffers: Dict[str, np.ndarray]
) -> np.ndarray:
"""
De-mux qubit readout results and assemble them into the ro-bitstrings in the correct order.
:param ro_sources: Specification of the ro_sou... | def _extract_bitstrings(ro_sources: List[Optional[Tuple[int, int]]],
buffers: Dict[str, np.ndarray]
) -> np.ndarray:
"""
De-mux qubit readout results and assemble them into the ro-bitstrings in the correct order.
:param ro_sources: Specification of the ro_sou... | [
"De",
"-",
"mux",
"qubit",
"readout",
"results",
"and",
"assemble",
"them",
"into",
"the",
"ro",
"-",
"bitstrings",
"in",
"the",
"correct",
"order",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L42-L67 | [
"def",
"_extract_bitstrings",
"(",
"ro_sources",
":",
"List",
"[",
"Optional",
"[",
"Tuple",
"[",
"int",
",",
"int",
"]",
"]",
"]",
",",
"buffers",
":",
"Dict",
"[",
"str",
",",
"np",
".",
"ndarray",
"]",
")",
"->",
"np",
".",
"ndarray",
":",
"# ha... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QPU.load | Initialize a QAM into a fresh state. Load the executable and parse the expressions
in the recalculation table (if any) into pyQuil Expression objects.
:param executable: Load a compiled executable onto the QAM. | pyquil/api/_qpu.py | def load(self, executable):
"""
Initialize a QAM into a fresh state. Load the executable and parse the expressions
in the recalculation table (if any) into pyQuil Expression objects.
:param executable: Load a compiled executable onto the QAM.
"""
super().load(executable)... | def load(self, executable):
"""
Initialize a QAM into a fresh state. Load the executable and parse the expressions
in the recalculation table (if any) into pyQuil Expression objects.
:param executable: Load a compiled executable onto the QAM.
"""
super().load(executable)... | [
"Initialize",
"a",
"QAM",
"into",
"a",
"fresh",
"state",
".",
"Load",
"the",
"executable",
"and",
"parse",
"the",
"expressions",
"in",
"the",
"recalculation",
"table",
"(",
"if",
"any",
")",
"into",
"pyQuil",
"Expression",
"objects",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L109-L125 | [
"def",
"load",
"(",
"self",
",",
"executable",
")",
":",
"super",
"(",
")",
".",
"load",
"(",
"executable",
")",
"if",
"hasattr",
"(",
"self",
".",
"_executable",
",",
"\"recalculation_table\"",
")",
":",
"recalculation_table",
"=",
"self",
".",
"_executab... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QPU.run | Run a pyquil program on the QPU.
This formats the classified data from the QPU server by stacking measured bits into
an array of shape (trials, classical_addresses). The mapping of qubit to
classical address is backed out from MEASURE instructions in the program, so
only do measurements... | pyquil/api/_qpu.py | def run(self, run_priority: Optional[int] = None):
"""
Run a pyquil program on the QPU.
This formats the classified data from the QPU server by stacking measured bits into
an array of shape (trials, classical_addresses). The mapping of qubit to
classical address is backed out fr... | def run(self, run_priority: Optional[int] = None):
"""
Run a pyquil program on the QPU.
This formats the classified data from the QPU server by stacking measured bits into
an array of shape (trials, classical_addresses). The mapping of qubit to
classical address is backed out fr... | [
"Run",
"a",
"pyquil",
"program",
"on",
"the",
"QPU",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L128-L173 | [
"def",
"run",
"(",
"self",
",",
"run_priority",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
")",
":",
"# This prevents a common error where users expect QVM.run()",
"# and QPU.run() to be interchangeable. QPU.run() needs the",
"# supplied executable to have been compiled, QVM.ru... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QPU._get_buffers | Return the decoded result buffers for particular job_id.
:param job_id: Unique identifier for the job in question
:return: Decoded buffers or throw an error | pyquil/api/_qpu.py | def _get_buffers(self, job_id: str) -> Dict[str, np.ndarray]:
"""
Return the decoded result buffers for particular job_id.
:param job_id: Unique identifier for the job in question
:return: Decoded buffers or throw an error
"""
buffers = self.client.call('get_buffers', jo... | def _get_buffers(self, job_id: str) -> Dict[str, np.ndarray]:
"""
Return the decoded result buffers for particular job_id.
:param job_id: Unique identifier for the job in question
:return: Decoded buffers or throw an error
"""
buffers = self.client.call('get_buffers', jo... | [
"Return",
"the",
"decoded",
"result",
"buffers",
"for",
"particular",
"job_id",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L175-L183 | [
"def",
"_get_buffers",
"(",
"self",
",",
"job_id",
":",
"str",
")",
"->",
"Dict",
"[",
"str",
",",
"np",
".",
"ndarray",
"]",
":",
"buffers",
"=",
"self",
".",
"client",
".",
"call",
"(",
"'get_buffers'",
",",
"job_id",
",",
"wait",
"=",
"True",
")... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QPU._update_variables_shim_with_recalculation_table | Update self._variables_shim with the final values to be patched into the gate parameters,
according to the arithmetic expressions in the original program.
For example:
DECLARE theta REAL
DECLARE beta REAL
RZ(3 * theta) 0
RZ(beta+theta) 0
gets tr... | pyquil/api/_qpu.py | def _update_variables_shim_with_recalculation_table(self):
"""
Update self._variables_shim with the final values to be patched into the gate parameters,
according to the arithmetic expressions in the original program.
For example:
DECLARE theta REAL
DECLARE beta... | def _update_variables_shim_with_recalculation_table(self):
"""
Update self._variables_shim with the final values to be patched into the gate parameters,
according to the arithmetic expressions in the original program.
For example:
DECLARE theta REAL
DECLARE beta... | [
"Update",
"self",
".",
"_variables_shim",
"with",
"the",
"final",
"values",
"to",
"be",
"patched",
"into",
"the",
"gate",
"parameters",
"according",
"to",
"the",
"arithmetic",
"expressions",
"in",
"the",
"original",
"program",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L222-L271 | [
"def",
"_update_variables_shim_with_recalculation_table",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
".",
"_executable",
",",
"\"recalculation_table\"",
")",
":",
"# No recalculation table, no work to be done here.",
"return",
"for",
"memory_reference",
","... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QPU._resolve_memory_references | Traverse the given Expression, and replace any Memory References with whatever values
have been so far provided by the user for those memory spaces. Declared memory defaults
to zero.
:param expression: an Expression | pyquil/api/_qpu.py | def _resolve_memory_references(self, expression: Expression) -> Union[float, int]:
"""
Traverse the given Expression, and replace any Memory References with whatever values
have been so far provided by the user for those memory spaces. Declared memory defaults
to zero.
:param ex... | def _resolve_memory_references(self, expression: Expression) -> Union[float, int]:
"""
Traverse the given Expression, and replace any Memory References with whatever values
have been so far provided by the user for those memory spaces. Declared memory defaults
to zero.
:param ex... | [
"Traverse",
"the",
"given",
"Expression",
"and",
"replace",
"any",
"Memory",
"References",
"with",
"whatever",
"values",
"have",
"been",
"so",
"far",
"provided",
"by",
"the",
"user",
"for",
"those",
"memory",
"spaces",
".",
"Declared",
"memory",
"defaults",
"t... | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qpu.py#L273-L294 | [
"def",
"_resolve_memory_references",
"(",
"self",
",",
"expression",
":",
"Expression",
")",
"->",
"Union",
"[",
"float",
",",
"int",
"]",
":",
"if",
"isinstance",
"(",
"expression",
",",
"BinaryExp",
")",
":",
"left",
"=",
"self",
".",
"_resolve_memory_refe... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | changed_bit_pos | Return the index of the first bit that changed between `a` an `b`.
Return None if there are no changed bits. | examples/pointer.py | def changed_bit_pos(a, b):
"""
Return the index of the first bit that changed between `a` an `b`.
Return None if there are no changed bits.
"""
c = a ^ b
n = 0
while c > 0:
if c & 1 == 1:
return n
c >>= 1
n += 1
return None | def changed_bit_pos(a, b):
"""
Return the index of the first bit that changed between `a` an `b`.
Return None if there are no changed bits.
"""
c = a ^ b
n = 0
while c > 0:
if c & 1 == 1:
return n
c >>= 1
n += 1
return None | [
"Return",
"the",
"index",
"of",
"the",
"first",
"bit",
"that",
"changed",
"between",
"a",
"an",
"b",
".",
"Return",
"None",
"if",
"there",
"are",
"no",
"changed",
"bits",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/pointer.py#L26-L38 | [
"def",
"changed_bit_pos",
"(",
"a",
",",
"b",
")",
":",
"c",
"=",
"a",
"^",
"b",
"n",
"=",
"0",
"while",
"c",
">",
"0",
":",
"if",
"c",
"&",
"1",
"==",
"1",
":",
"return",
"n",
"c",
">>=",
"1",
"n",
"+=",
"1",
"return",
"None"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
train | gray | Generate the Gray code for `num_bits` bits. | examples/pointer.py | def gray(num_bits):
"""
Generate the Gray code for `num_bits` bits.
"""
last = 0
x = 0
n = 1 << num_bits
while n > x:
bit_string = bin(n + x ^ x // 2)[3:]
value = int(bit_string, 2)
yield bit_string, value, changed_bit_pos(last, value)
last = value
x +... | def gray(num_bits):
"""
Generate the Gray code for `num_bits` bits.
"""
last = 0
x = 0
n = 1 << num_bits
while n > x:
bit_string = bin(n + x ^ x // 2)[3:]
value = int(bit_string, 2)
yield bit_string, value, changed_bit_pos(last, value)
last = value
x +... | [
"Generate",
"the",
"Gray",
"code",
"for",
"num_bits",
"bits",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/pointer.py#L41-L53 | [
"def",
"gray",
"(",
"num_bits",
")",
":",
"last",
"=",
"0",
"x",
"=",
"0",
"n",
"=",
"1",
"<<",
"num_bits",
"while",
"n",
">",
"x",
":",
"bit_string",
"=",
"bin",
"(",
"n",
"+",
"x",
"^",
"x",
"//",
"2",
")",
"[",
"3",
":",
"]",
"value",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | controlled | Given a one-qubit gate matrix U, construct a controlled-U on all pointer
qubits. | examples/pointer.py | def controlled(num_ptr_bits, U):
"""
Given a one-qubit gate matrix U, construct a controlled-U on all pointer
qubits.
"""
d = 2 ** (1 + num_ptr_bits)
m = np.eye(d)
m[d - 2:, d - 2:] = U
return m | def controlled(num_ptr_bits, U):
"""
Given a one-qubit gate matrix U, construct a controlled-U on all pointer
qubits.
"""
d = 2 ** (1 + num_ptr_bits)
m = np.eye(d)
m[d - 2:, d - 2:] = U
return m | [
"Given",
"a",
"one",
"-",
"qubit",
"gate",
"matrix",
"U",
"construct",
"a",
"controlled",
"-",
"U",
"on",
"all",
"pointer",
"qubits",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/pointer.py#L56-L64 | [
"def",
"controlled",
"(",
"num_ptr_bits",
",",
"U",
")",
":",
"d",
"=",
"2",
"**",
"(",
"1",
"+",
"num_ptr_bits",
")",
"m",
"=",
"np",
".",
"eye",
"(",
"d",
")",
"m",
"[",
"d",
"-",
"2",
":",
",",
"d",
"-",
"2",
":",
"]",
"=",
"U",
"retur... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | fixup | Flip back the pointer qubits that were previously flipped indicated by
the flags `bits_set`. | examples/pointer.py | def fixup(p, data_bits, ptr_bits, bits_set):
"""
Flip back the pointer qubits that were previously flipped indicated by
the flags `bits_set`.
"""
for i in range(ptr_bits):
if 0 != bits_set & (1 << i):
p.inst(X(data_bits + i)) | def fixup(p, data_bits, ptr_bits, bits_set):
"""
Flip back the pointer qubits that were previously flipped indicated by
the flags `bits_set`.
"""
for i in range(ptr_bits):
if 0 != bits_set & (1 << i):
p.inst(X(data_bits + i)) | [
"Flip",
"back",
"the",
"pointer",
"qubits",
"that",
"were",
"previously",
"flipped",
"indicated",
"by",
"the",
"flags",
"bits_set",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/pointer.py#L67-L74 | [
"def",
"fixup",
"(",
"p",
",",
"data_bits",
",",
"ptr_bits",
",",
"bits_set",
")",
":",
"for",
"i",
"in",
"range",
"(",
"ptr_bits",
")",
":",
"if",
"0",
"!=",
"bits_set",
"&",
"(",
"1",
"<<",
"i",
")",
":",
"p",
".",
"inst",
"(",
"X",
"(",
"d... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | pointer_gate | Make a pointer gate on `num_qubits`. The one-qubit gate U will act on the
qubit addressed by the pointer qubits interpreted as an unsigned binary
integer.
There are P = floor(lg(num_qubits)) pointer qubits, and qubits numbered
N - 1
N - 2
...
N - P
are those reserved t... | examples/pointer.py | def pointer_gate(num_qubits, U):
"""
Make a pointer gate on `num_qubits`. The one-qubit gate U will act on the
qubit addressed by the pointer qubits interpreted as an unsigned binary
integer.
There are P = floor(lg(num_qubits)) pointer qubits, and qubits numbered
N - 1
N - 2
... | def pointer_gate(num_qubits, U):
"""
Make a pointer gate on `num_qubits`. The one-qubit gate U will act on the
qubit addressed by the pointer qubits interpreted as an unsigned binary
integer.
There are P = floor(lg(num_qubits)) pointer qubits, and qubits numbered
N - 1
N - 2
... | [
"Make",
"a",
"pointer",
"gate",
"on",
"num_qubits",
".",
"The",
"one",
"-",
"qubit",
"gate",
"U",
"will",
"act",
"on",
"the",
"qubit",
"addressed",
"by",
"the",
"pointer",
"qubits",
"interpreted",
"as",
"an",
"unsigned",
"binary",
"integer",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/pointer.py#L77-L116 | [
"def",
"pointer_gate",
"(",
"num_qubits",
",",
"U",
")",
":",
"ptr_bits",
"=",
"int",
"(",
"floor",
"(",
"np",
".",
"log2",
"(",
"num_qubits",
")",
")",
")",
"data_bits",
"=",
"num_qubits",
"-",
"ptr_bits",
"ptr_state",
"=",
"0",
"assert",
"ptr_bits",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | relaxation_operators | Return the amplitude damping Kraus operators | pyquil/gate_matrices.py | def relaxation_operators(p):
"""
Return the amplitude damping Kraus operators
"""
k0 = np.array([[1.0, 0.0], [0.0, np.sqrt(1 - p)]])
k1 = np.array([[0.0, np.sqrt(p)], [0.0, 0.0]])
return k0, k1 | def relaxation_operators(p):
"""
Return the amplitude damping Kraus operators
"""
k0 = np.array([[1.0, 0.0], [0.0, np.sqrt(1 - p)]])
k1 = np.array([[0.0, np.sqrt(p)], [0.0, 0.0]])
return k0, k1 | [
"Return",
"the",
"amplitude",
"damping",
"Kraus",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L225-L231 | [
"def",
"relaxation_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"1.0",
",",
"0.0",
"]",
",",
"[",
"0.0",
",",
"np",
".",
"sqrt",
"(",
"1",
"-",
"p",
")",
"]",
"]",
")",
"k1",
"=",
"np",
".",
"array",
"(",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | dephasing_operators | Return the phase damping Kraus operators | pyquil/gate_matrices.py | def dephasing_operators(p):
"""
Return the phase damping Kraus operators
"""
k0 = np.eye(2) * np.sqrt(1 - p / 2)
k1 = np.sqrt(p / 2) * Z
return k0, k1 | def dephasing_operators(p):
"""
Return the phase damping Kraus operators
"""
k0 = np.eye(2) * np.sqrt(1 - p / 2)
k1 = np.sqrt(p / 2) * Z
return k0, k1 | [
"Return",
"the",
"phase",
"damping",
"Kraus",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L234-L240 | [
"def",
"dephasing_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"eye",
"(",
"2",
")",
"*",
"np",
".",
"sqrt",
"(",
"1",
"-",
"p",
"/",
"2",
")",
"k1",
"=",
"np",
".",
"sqrt",
"(",
"p",
"/",
"2",
")",
"*",
"Z",
"return",
"k0",
",",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | depolarizing_operators | Return the phase damping Kraus operators | pyquil/gate_matrices.py | def depolarizing_operators(p):
"""
Return the phase damping Kraus operators
"""
k0 = np.sqrt(1.0 - p) * I
k1 = np.sqrt(p / 3.0) * X
k2 = np.sqrt(p / 3.0) * Y
k3 = np.sqrt(p / 3.0) * Z
return k0, k1, k2, k3 | def depolarizing_operators(p):
"""
Return the phase damping Kraus operators
"""
k0 = np.sqrt(1.0 - p) * I
k1 = np.sqrt(p / 3.0) * X
k2 = np.sqrt(p / 3.0) * Y
k3 = np.sqrt(p / 3.0) * Z
return k0, k1, k2, k3 | [
"Return",
"the",
"phase",
"damping",
"Kraus",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L243-L251 | [
"def",
"depolarizing_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"sqrt",
"(",
"1.0",
"-",
"p",
")",
"*",
"I",
"k1",
"=",
"np",
".",
"sqrt",
"(",
"p",
"/",
"3.0",
")",
"*",
"X",
"k2",
"=",
"np",
".",
"sqrt",
"(",
"p",
"/",
"3.0",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | phase_flip_operators | Return the phase flip kraus operators | pyquil/gate_matrices.py | def phase_flip_operators(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p) * I
k1 = np.sqrt(p) * Z
return k0, k1 | def phase_flip_operators(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p) * I
k1 = np.sqrt(p) * Z
return k0, k1 | [
"Return",
"the",
"phase",
"flip",
"kraus",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L254-L260 | [
"def",
"phase_flip_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"sqrt",
"(",
"1",
"-",
"p",
")",
"*",
"I",
"k1",
"=",
"np",
".",
"sqrt",
"(",
"p",
")",
"*",
"Z",
"return",
"k0",
",",
"k1"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
train | bit_flip_operators | Return the phase flip kraus operators | pyquil/gate_matrices.py | def bit_flip_operators(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p) * I
k1 = np.sqrt(p) * X
return k0, k1 | def bit_flip_operators(p):
"""
Return the phase flip kraus operators
"""
k0 = np.sqrt(1 - p) * I
k1 = np.sqrt(p) * X
return k0, k1 | [
"Return",
"the",
"phase",
"flip",
"kraus",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L263-L269 | [
"def",
"bit_flip_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"sqrt",
"(",
"1",
"-",
"p",
")",
"*",
"I",
"k1",
"=",
"np",
".",
"sqrt",
"(",
"p",
")",
"*",
"X",
"return",
"k0",
",",
"k1"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
train | bitphase_flip_operators | Return the bitphase flip kraus operators | pyquil/gate_matrices.py | def bitphase_flip_operators(p):
"""
Return the bitphase flip kraus operators
"""
k0 = np.sqrt(1 - p) * I
k1 = np.sqrt(p) * Y
return k0, k1 | def bitphase_flip_operators(p):
"""
Return the bitphase flip kraus operators
"""
k0 = np.sqrt(1 - p) * I
k1 = np.sqrt(p) * Y
return k0, k1 | [
"Return",
"the",
"bitphase",
"flip",
"kraus",
"operators"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gate_matrices.py#L272-L278 | [
"def",
"bitphase_flip_operators",
"(",
"p",
")",
":",
"k0",
"=",
"np",
".",
"sqrt",
"(",
"1",
"-",
"p",
")",
"*",
"I",
"k1",
"=",
"np",
".",
"sqrt",
"(",
"p",
")",
"*",
"Y",
"return",
"k0",
",",
"k1"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVMConnection.run | Run a Quil program multiple times, accumulating the values deposited in
a list of classical addresses.
:param Program quil_program: A Quil program.
:param classical_addresses: The classical memory to retrieve. Specified as a list of
integers that index into a readout register named ... | pyquil/api/_qvm.py | def run(self, quil_program, classical_addresses: List[int] = None,
trials=1):
"""
Run a Quil program multiple times, accumulating the values deposited in
a list of classical addresses.
:param Program quil_program: A Quil program.
:param classical_addresses: The class... | def run(self, quil_program, classical_addresses: List[int] = None,
trials=1):
"""
Run a Quil program multiple times, accumulating the values deposited in
a list of classical addresses.
:param Program quil_program: A Quil program.
:param classical_addresses: The class... | [
"Run",
"a",
"Quil",
"program",
"multiple",
"times",
"accumulating",
"the",
"values",
"deposited",
"in",
"a",
"list",
"of",
"classical",
"addresses",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qvm.py#L119-L151 | [
"def",
"run",
"(",
"self",
",",
"quil_program",
",",
"classical_addresses",
":",
"List",
"[",
"int",
"]",
"=",
"None",
",",
"trials",
"=",
"1",
")",
":",
"if",
"classical_addresses",
"is",
"None",
":",
"caddresses",
"=",
"get_classical_addresses_from_program",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVMConnection.run_and_measure | Run a Quil program once to determine the final wavefunction, and measure multiple times.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates, then the final wavefunction from which the
returned bitstrings are... | pyquil/api/_qvm.py | def run_and_measure(self, quil_program, qubits, trials=1):
"""
Run a Quil program once to determine the final wavefunction, and measure multiple times.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates,... | def run_and_measure(self, quil_program, qubits, trials=1):
"""
Run a Quil program once to determine the final wavefunction, and measure multiple times.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates,... | [
"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/_qvm.py#L154-L177 | [
"def",
"run_and_measure",
"(",
"self",
",",
"quil_program",
",",
"qubits",
",",
"trials",
"=",
"1",
")",
":",
"# Developer note: This code is for backwards compatibility. It can't be replaced with",
"# ForestConnection._run_and_measure because we've turned off the ability to set",
"#... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVMConnection.wavefunction | Simulate a Quil program and get the wavefunction back.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates, then the final wavefunction from which the
returned bitstrings are sampled itself only represents a ... | pyquil/api/_qvm.py | def wavefunction(self, quil_program):
"""
Simulate a Quil program and get the wavefunction back.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates, then the final wavefunction from which the
... | def wavefunction(self, quil_program):
"""
Simulate a Quil program and get the wavefunction back.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates, then the final wavefunction from which the
... | [
"Simulate",
"a",
"Quil",
"program",
"and",
"get",
"the",
"wavefunction",
"back",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qvm.py#L206-L227 | [
"def",
"wavefunction",
"(",
"self",
",",
"quil_program",
")",
":",
"# Developer note: This code is for backwards compatibility. It can't be replaced with",
"# ForestConnection._wavefunction because we've turned off the ability to set",
"# `needs_compilation` (that usually indicates the user is d... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVMConnection.expectation | Calculate the expectation value of operators given a state prepared by
prep_program.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gates, then the final wavefunction from which the
expectation values ... | pyquil/api/_qvm.py | def expectation(self, prep_prog, operator_programs=None):
"""
Calculate the expectation value of operators given a state prepared by
prep_program.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gat... | def expectation(self, prep_prog, operator_programs=None):
"""
Calculate the expectation value of operators given a state prepared by
prep_program.
:note: If the execution of ``quil_program`` is **non-deterministic**, i.e., if it includes
measurements and/or noisy quantum gat... | [
"Calculate",
"the",
"expectation",
"value",
"of",
"operators",
"given",
"a",
"state",
"prepared",
"by",
"prep_program",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qvm.py#L247-L283 | [
"def",
"expectation",
"(",
"self",
",",
"prep_prog",
",",
"operator_programs",
"=",
"None",
")",
":",
"# Developer note: This code is for backwards compatibility. It can't be replaced with",
"# ForestConnection._expectation because we've turned off the ability to set",
"# `needs_compilat... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVMConnection.pauli_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 a list of ``float``s, one for each ``PauliTerm`` in the
list.
:note: If the exe... | pyquil/api/_qvm.py | def pauli_expectation(self, prep_prog, pauli_terms):
"""
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 a list of ``float``s, o... | def pauli_expectation(self, prep_prog, pauli_terms):
"""
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 a list of ``float``s, o... | [
"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/_qvm.py#L286-L319 | [
"def",
"pauli_expectation",
"(",
"self",
",",
"prep_prog",
",",
"pauli_terms",
")",
":",
"is_pauli_sum",
"=",
"False",
"if",
"isinstance",
"(",
"pauli_terms",
",",
"PauliSum",
")",
":",
"progs",
",",
"coeffs",
"=",
"pauli_terms",
".",
"get_programs",
"(",
")... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVMConnection._maybe_add_noise_to_payload | Set the gate noise and measurement noise of a payload. | pyquil/api/_qvm.py | def _maybe_add_noise_to_payload(self, payload):
"""
Set the gate noise and measurement noise of a payload.
"""
if self.measurement_noise is not None:
payload["measurement-noise"] = self.measurement_noise
if self.gate_noise is not None:
payload["gate-noise"... | def _maybe_add_noise_to_payload(self, payload):
"""
Set the gate noise and measurement noise of a payload.
"""
if self.measurement_noise is not None:
payload["measurement-noise"] = self.measurement_noise
if self.gate_noise is not None:
payload["gate-noise"... | [
"Set",
"the",
"gate",
"noise",
"and",
"measurement",
"noise",
"of",
"a",
"payload",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qvm.py#L336-L343 | [
"def",
"_maybe_add_noise_to_payload",
"(",
"self",
",",
"payload",
")",
":",
"if",
"self",
".",
"measurement_noise",
"is",
"not",
"None",
":",
"payload",
"[",
"\"measurement-noise\"",
"]",
"=",
"self",
".",
"measurement_noise",
"if",
"self",
".",
"gate_noise",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVM.load | Initialize a QAM and load a program to be executed with a call to :py:func:`run`.
If ``QVM.requires_executable`` is set to ``True``, this function will only load
:py:class:`PyQuilExecutableResponse` executables. This more closely follows the behavior
of :py:class:`QPU`. However, the quantum sim... | pyquil/api/_qvm.py | def load(self, executable):
"""
Initialize a QAM and load a program to be executed with a call to :py:func:`run`.
If ``QVM.requires_executable`` is set to ``True``, this function will only load
:py:class:`PyQuilExecutableResponse` executables. This more closely follows the behavior
... | def load(self, executable):
"""
Initialize a QAM and load a program to be executed with a call to :py:func:`run`.
If ``QVM.requires_executable`` is set to ``True``, this function will only load
:py:class:`PyQuilExecutableResponse` executables. This more closely follows the behavior
... | [
"Initialize",
"a",
"QAM",
"and",
"load",
"a",
"program",
"to",
"be",
"executed",
"with",
"a",
"call",
"to",
":",
"py",
":",
"func",
":",
"run",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qvm.py#L419-L449 | [
"def",
"load",
"(",
"self",
",",
"executable",
")",
":",
"if",
"self",
".",
"requires_executable",
":",
"if",
"isinstance",
"(",
"executable",
",",
"PyQuilExecutableResponse",
")",
":",
"executable",
"=",
"_extract_program_from_pyquil_executable_response",
"(",
"exe... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | QVM.run | Run a Quil program on the QVM multiple times and return the values stored in the
classical registers designated by the classical_addresses parameter.
:return: An array of bitstrings of shape ``(trials, len(classical_addresses))`` | pyquil/api/_qvm.py | def run(self):
"""
Run a Quil program on the QVM multiple times and return the values stored in the
classical registers designated by the classical_addresses parameter.
:return: An array of bitstrings of shape ``(trials, len(classical_addresses))``
"""
super().run()
... | def run(self):
"""
Run a Quil program on the QVM multiple times and return the values stored in the
classical registers designated by the classical_addresses parameter.
:return: An array of bitstrings of shape ``(trials, len(classical_addresses))``
"""
super().run()
... | [
"Run",
"a",
"Quil",
"program",
"on",
"the",
"QVM",
"multiple",
"times",
"and",
"return",
"the",
"values",
"stored",
"in",
"the",
"classical",
"registers",
"designated",
"by",
"the",
"classical_addresses",
"parameter",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_qvm.py#L452-L488 | [
"def",
"run",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"run",
"(",
")",
"if",
"not",
"isinstance",
"(",
"self",
".",
"_executable",
",",
"Program",
")",
":",
"# This should really never happen",
"# unless a user monkeys with `self.status` and `self._executable... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | Job.result | The result of the job if available
throws ValueError is result is not available yet
throws ApiError if server returned an error indicating program execution was not successful
or if the job was cancelled | pyquil/api/_job.py | def result(self):
"""
The result of the job if available
throws ValueError is result is not available yet
throws ApiError if server returned an error indicating program execution was not successful
or if the job was cancelled
"""
if not self.is_done():
... | def result(self):
"""
The result of the job if available
throws ValueError is result is not available yet
throws ApiError if server returned an error indicating program execution was not successful
or if the job was cancelled
"""
if not self.is_done():
... | [
"The",
"result",
"of",
"the",
"job",
"if",
"available",
"throws",
"ValueError",
"is",
"result",
"is",
"not",
"available",
"yet",
"throws",
"ApiError",
"if",
"server",
"returned",
"an",
"error",
"indicating",
"program",
"execution",
"was",
"not",
"successful",
... | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_job.py#L54-L82 | [
"def",
"result",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_done",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Cannot get a result for a program that isn't completed.\"",
")",
"if",
"self",
".",
"_raw",
"[",
"'status'",
"]",
"==",
"'CANCELLED'",
":... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | Job.running_time | For how long was the job running?
:return: Running time, seconds
:rtype: Optional[float] | pyquil/api/_job.py | def running_time(self):
"""
For how long was the job running?
:return: Running time, seconds
:rtype: Optional[float]
"""
if not self.is_done():
raise ValueError("Cannot get running time for a program that isn't completed.")
try:
running_tim... | def running_time(self):
"""
For how long was the job running?
:return: Running time, seconds
:rtype: Optional[float]
"""
if not self.is_done():
raise ValueError("Cannot get running time for a program that isn't completed.")
try:
running_tim... | [
"For",
"how",
"long",
"was",
"the",
"job",
"running?",
":",
"return",
":",
"Running",
"time",
"seconds",
":",
"rtype",
":",
"Optional",
"[",
"float",
"]"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_job.py#L124-L136 | [
"def",
"running_time",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_done",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Cannot get running time for a program that isn't completed.\"",
")",
"try",
":",
"running_time",
"=",
"float",
"(",
"self",
".",
"_ra... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | Job._get_metadata | If the server returned a metadata dictionary, retrieve a particular key from it. If no
metadata exists, or the key does not exist, return None.
:param key: Metadata key, e.g., "gate_depth"
:return: The associated metadata.
:rtype: Optional[Any] | pyquil/api/_job.py | def _get_metadata(self, key):
"""
If the server returned a metadata dictionary, retrieve a particular key from it. If no
metadata exists, or the key does not exist, return None.
:param key: Metadata key, e.g., "gate_depth"
:return: The associated metadata.
:rtype: Option... | def _get_metadata(self, key):
"""
If the server returned a metadata dictionary, retrieve a particular key from it. If no
metadata exists, or the key does not exist, return None.
:param key: Metadata key, e.g., "gate_depth"
:return: The associated metadata.
:rtype: Option... | [
"If",
"the",
"server",
"returned",
"a",
"metadata",
"dictionary",
"retrieve",
"a",
"particular",
"key",
"from",
"it",
".",
"If",
"no",
"metadata",
"exists",
"or",
"the",
"key",
"does",
"not",
"exist",
"return",
"None",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_job.py#L162-L174 | [
"def",
"_get_metadata",
"(",
"self",
",",
"key",
")",
":",
"if",
"not",
"self",
".",
"is_done",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Cannot get metadata for a program that isn't completed.\"",
")",
"return",
"self",
".",
"_raw",
".",
"get",
"(",
"\"me... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | Job.compiled_quil | If the Quil program associated with the Job was compiled (e.g., to translate it to the
QPU's natural gateset) return this compiled program.
:rtype: Optional[Program] | pyquil/api/_job.py | def compiled_quil(self):
"""
If the Quil program associated with the Job was compiled (e.g., to translate it to the
QPU's natural gateset) return this compiled program.
:rtype: Optional[Program]
"""
prog = self._raw.get("program", {}).get("compiled-quil", None)
i... | def compiled_quil(self):
"""
If the Quil program associated with the Job was compiled (e.g., to translate it to the
QPU's natural gateset) return this compiled program.
:rtype: Optional[Program]
"""
prog = self._raw.get("program", {}).get("compiled-quil", None)
i... | [
"If",
"the",
"Quil",
"program",
"associated",
"with",
"the",
"Job",
"was",
"compiled",
"(",
"e",
".",
"g",
".",
"to",
"translate",
"it",
"to",
"the",
"QPU",
"s",
"natural",
"gateset",
")",
"return",
"this",
"compiled",
"program",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_job.py#L197-L211 | [
"def",
"compiled_quil",
"(",
"self",
")",
":",
"prog",
"=",
"self",
".",
"_raw",
".",
"get",
"(",
"\"program\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"\"compiled-quil\"",
",",
"None",
")",
"if",
"prog",
"is",
"not",
"None",
":",
"return",
"parse_prog... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | targeted_einsum | Left-multiplies the given axes of the wf tensor by the given gate matrix.
Note that the matrix must have a compatible tensor structure.
For example, if you have an 6-qubit state vector ``wf`` with shape
(2, 2, 2, 2, 2, 2), and a 2-qubit unitary operation ``op`` with shape
(2, 2, 2, 2), and you want to ... | pyquil/numpy_simulator.py | def targeted_einsum(gate: np.ndarray,
wf: np.ndarray,
wf_target_inds: List[int]
) -> np.ndarray:
"""Left-multiplies the given axes of the wf tensor by the given gate matrix.
Note that the matrix must have a compatible tensor structure.
For example... | def targeted_einsum(gate: np.ndarray,
wf: np.ndarray,
wf_target_inds: List[int]
) -> np.ndarray:
"""Left-multiplies the given axes of the wf tensor by the given gate matrix.
Note that the matrix must have a compatible tensor structure.
For example... | [
"Left",
"-",
"multiplies",
"the",
"given",
"axes",
"of",
"the",
"wf",
"tensor",
"by",
"the",
"given",
"gate",
"matrix",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L47-L92 | [
"def",
"targeted_einsum",
"(",
"gate",
":",
"np",
".",
"ndarray",
",",
"wf",
":",
"np",
".",
"ndarray",
",",
"wf_target_inds",
":",
"List",
"[",
"int",
"]",
")",
"->",
"np",
".",
"ndarray",
":",
"k",
"=",
"len",
"(",
"wf_target_inds",
")",
"d",
"="... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | targeted_tensordot | Left-multiplies the given axes of the wf tensor by the given gate matrix.
Compare with :py:func:`targeted_einsum`. The semantics of these two functions should be
identical, except this uses ``np.tensordot`` instead of ``np.einsum``.
:param gate: What to left-multiply the target tensor by.
:param wf: A... | pyquil/numpy_simulator.py | def targeted_tensordot(gate: np.ndarray,
wf: np.ndarray,
wf_target_inds: Sequence[int]
) -> np.ndarray:
"""Left-multiplies the given axes of the wf tensor by the given gate matrix.
Compare with :py:func:`targeted_einsum`. The semantics of the... | def targeted_tensordot(gate: np.ndarray,
wf: np.ndarray,
wf_target_inds: Sequence[int]
) -> np.ndarray:
"""Left-multiplies the given axes of the wf tensor by the given gate matrix.
Compare with :py:func:`targeted_einsum`. The semantics of the... | [
"Left",
"-",
"multiplies",
"the",
"given",
"axes",
"of",
"the",
"wf",
"tensor",
"by",
"the",
"given",
"gate",
"matrix",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L95-L136 | [
"def",
"targeted_tensordot",
"(",
"gate",
":",
"np",
".",
"ndarray",
",",
"wf",
":",
"np",
".",
"ndarray",
",",
"wf_target_inds",
":",
"Sequence",
"[",
"int",
"]",
")",
"->",
"np",
".",
"ndarray",
":",
"gate_n_qubits",
"=",
"gate",
".",
"ndim",
"//",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | get_measure_probabilities | Get the probabilities of measuring a qubit.
:param wf: The statevector with a dimension for each qubit
:param qubit: The qubit to measure. We will sum over every axis except this one.
:return: A vector of classical probabilities. | pyquil/numpy_simulator.py | def get_measure_probabilities(wf, qubit):
"""
Get the probabilities of measuring a qubit.
:param wf: The statevector with a dimension for each qubit
:param qubit: The qubit to measure. We will sum over every axis except this one.
:return: A vector of classical probabilities.
"""
n_qubits = ... | def get_measure_probabilities(wf, qubit):
"""
Get the probabilities of measuring a qubit.
:param wf: The statevector with a dimension for each qubit
:param qubit: The qubit to measure. We will sum over every axis except this one.
:return: A vector of classical probabilities.
"""
n_qubits = ... | [
"Get",
"the",
"probabilities",
"of",
"measuring",
"a",
"qubit",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L139-L152 | [
"def",
"get_measure_probabilities",
"(",
"wf",
",",
"qubit",
")",
":",
"n_qubits",
"=",
"len",
"(",
"wf",
".",
"shape",
")",
"all_inds",
"=",
"list",
"(",
"range",
"(",
"n_qubits",
")",
")",
"return",
"np",
".",
"einsum",
"(",
"np",
".",
"conj",
"(",... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _get_gate_tensor_and_qubits | Given a gate ``Instruction``, turn it into a matrix and extract qubit indices.
:param gate: the instruction
:return: tensor, qubit_inds. | pyquil/numpy_simulator.py | def _get_gate_tensor_and_qubits(gate: Gate):
"""Given a gate ``Instruction``, turn it into a matrix and extract qubit indices.
:param gate: the instruction
:return: tensor, qubit_inds.
"""
if len(gate.params) > 0:
matrix = QUANTUM_GATES[gate.name](*gate.params)
else:
matrix = QU... | def _get_gate_tensor_and_qubits(gate: Gate):
"""Given a gate ``Instruction``, turn it into a matrix and extract qubit indices.
:param gate: the instruction
:return: tensor, qubit_inds.
"""
if len(gate.params) > 0:
matrix = QUANTUM_GATES[gate.name](*gate.params)
else:
matrix = QU... | [
"Given",
"a",
"gate",
"Instruction",
"turn",
"it",
"into",
"a",
"matrix",
"and",
"extract",
"qubit",
"indices",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L155-L171 | [
"def",
"_get_gate_tensor_and_qubits",
"(",
"gate",
":",
"Gate",
")",
":",
"if",
"len",
"(",
"gate",
".",
"params",
")",
">",
"0",
":",
"matrix",
"=",
"QUANTUM_GATES",
"[",
"gate",
".",
"name",
"]",
"(",
"*",
"gate",
".",
"params",
")",
"else",
":",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | NumpyWavefunctionSimulator.sample_bitstrings | Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits) | pyquil/numpy_simulator.py | def sample_bitstrings(self, n_samples):
"""
Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits)
"""
if self.rs is ... | def sample_bitstrings(self, n_samples):
"""
Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits)
"""
if self.rs is ... | [
"Sample",
"bitstrings",
"from",
"the",
"distribution",
"defined",
"by",
"the",
"wavefunction",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L210-L229 | [
"def",
"sample_bitstrings",
"(",
"self",
",",
"n_samples",
")",
":",
"if",
"self",
".",
"rs",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"You have tried to perform a stochastic operation without setting the \"",
"\"random state of the simulator. Might I suggest using a Py... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | NumpyWavefunctionSimulator.do_measurement | Measure a qubit, collapse the wavefunction, and return the measurement result.
:param qubit: Index of the qubit to measure.
:return: measured bit | pyquil/numpy_simulator.py | def do_measurement(self, qubit: int) -> int:
"""
Measure a qubit, collapse the wavefunction, and return the measurement result.
:param qubit: Index of the qubit to measure.
:return: measured bit
"""
if self.rs is None:
raise ValueError("You have tried to perf... | def do_measurement(self, qubit: int) -> int:
"""
Measure a qubit, collapse the wavefunction, and return the measurement result.
:param qubit: Index of the qubit to measure.
:return: measured bit
"""
if self.rs is None:
raise ValueError("You have tried to perf... | [
"Measure",
"a",
"qubit",
"collapse",
"the",
"wavefunction",
"and",
"return",
"the",
"measurement",
"result",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L231-L260 | [
"def",
"do_measurement",
"(",
"self",
",",
"qubit",
":",
"int",
")",
"->",
"int",
":",
"if",
"self",
".",
"rs",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"You have tried to perform a stochastic operation without setting the \"",
"\"random state of the simulator. ... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | NumpyWavefunctionSimulator.do_gate | Perform a gate.
:return: ``self`` to support method chaining. | pyquil/numpy_simulator.py | def do_gate(self, gate: Gate):
"""
Perform a gate.
:return: ``self`` to support method chaining.
"""
gate_matrix, qubit_inds = _get_gate_tensor_and_qubits(gate=gate)
# Note to developers: you can use either einsum- or tensordot- based functions.
# tensordot seems... | def do_gate(self, gate: Gate):
"""
Perform a gate.
:return: ``self`` to support method chaining.
"""
gate_matrix, qubit_inds = _get_gate_tensor_and_qubits(gate=gate)
# Note to developers: you can use either einsum- or tensordot- based functions.
# tensordot seems... | [
"Perform",
"a",
"gate",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L262-L273 | [
"def",
"do_gate",
"(",
"self",
",",
"gate",
":",
"Gate",
")",
":",
"gate_matrix",
",",
"qubit_inds",
"=",
"_get_gate_tensor_and_qubits",
"(",
"gate",
"=",
"gate",
")",
"# Note to developers: you can use either einsum- or tensordot- based functions.",
"# tensordot seems a li... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | NumpyWavefunctionSimulator.do_gate_matrix | Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done
:param qubits: A list of qubits to apply the unitary to.
:return: ``self`` to support method chaining. | pyquil/numpy_simulator.py | def do_gate_matrix(self, matrix: np.ndarray,
qubits: Sequence[int]) -> 'AbstractQuantumSimulator':
"""
Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done
:param qubits: A list of qubits to apply... | def do_gate_matrix(self, matrix: np.ndarray,
qubits: Sequence[int]) -> 'AbstractQuantumSimulator':
"""
Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done
:param qubits: A list of qubits to apply... | [
"Apply",
"an",
"arbitrary",
"unitary",
";",
"not",
"necessarily",
"a",
"named",
"gate",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L275-L291 | [
"def",
"do_gate_matrix",
"(",
"self",
",",
"matrix",
":",
"np",
".",
"ndarray",
",",
"qubits",
":",
"Sequence",
"[",
"int",
"]",
")",
"->",
"'AbstractQuantumSimulator'",
":",
"# e.g. 2-qubit matrix is 4x4; turns into (2,2,2,2) tensor.",
"tensor",
"=",
"np",
".",
"... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | NumpyWavefunctionSimulator.reset | Reset the wavefunction to the |000...00> state.
:return: ``self`` to support method chaining. | pyquil/numpy_simulator.py | def reset(self):
"""
Reset the wavefunction to the |000...00> state.
:return: ``self`` to support method chaining.
"""
self.wf.fill(0)
self.wf[(0,) * self.n_qubits] = complex(1.0, 0)
return self | def reset(self):
"""
Reset the wavefunction to the |000...00> state.
:return: ``self`` to support method chaining.
"""
self.wf.fill(0)
self.wf[(0,) * self.n_qubits] = complex(1.0, 0)
return self | [
"Reset",
"the",
"wavefunction",
"to",
"the",
"|000",
"...",
"00",
">",
"state",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/numpy_simulator.py#L305-L313 | [
"def",
"reset",
"(",
"self",
")",
":",
"self",
".",
"wf",
".",
"fill",
"(",
"0",
")",
"self",
".",
"wf",
"[",
"(",
"0",
",",
")",
"*",
"self",
".",
"n_qubits",
"]",
"=",
"complex",
"(",
"1.0",
",",
"0",
")",
"return",
"self"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceWavefunctionSimulator.sample_bitstrings | Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits) | pyquil/reference_simulator.py | def sample_bitstrings(self, n_samples):
"""
Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits)
"""
if self.rs is ... | def sample_bitstrings(self, n_samples):
"""
Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits)
"""
if self.rs is ... | [
"Sample",
"bitstrings",
"from",
"the",
"distribution",
"defined",
"by",
"the",
"wavefunction",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L51-L68 | [
"def",
"sample_bitstrings",
"(",
"self",
",",
"n_samples",
")",
":",
"if",
"self",
".",
"rs",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"You have tried to perform a stochastic operation without setting the \"",
"\"random state of the simulator. Might I suggest using a Py... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceWavefunctionSimulator.do_gate | Perform a gate.
:return: ``self`` to support method chaining. | pyquil/reference_simulator.py | def do_gate(self, gate: Gate):
"""
Perform a gate.
:return: ``self`` to support method chaining.
"""
unitary = lifted_gate(gate=gate, n_qubits=self.n_qubits)
self.wf = unitary.dot(self.wf)
return self | def do_gate(self, gate: Gate):
"""
Perform a gate.
:return: ``self`` to support method chaining.
"""
unitary = lifted_gate(gate=gate, n_qubits=self.n_qubits)
self.wf = unitary.dot(self.wf)
return self | [
"Perform",
"a",
"gate",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L70-L78 | [
"def",
"do_gate",
"(",
"self",
",",
"gate",
":",
"Gate",
")",
":",
"unitary",
"=",
"lifted_gate",
"(",
"gate",
"=",
"gate",
",",
"n_qubits",
"=",
"self",
".",
"n_qubits",
")",
"self",
".",
"wf",
"=",
"unitary",
".",
"dot",
"(",
"self",
".",
"wf",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceWavefunctionSimulator.do_gate_matrix | Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done.
:param qubits: The qubits to apply the unitary to.
:return: ``self`` to support method chaining. | pyquil/reference_simulator.py | def do_gate_matrix(self, matrix: np.ndarray, qubits: Sequence[int]):
"""
Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done.
:param qubits: The qubits to apply the unitary to.
:return: ``self`` to support meth... | def do_gate_matrix(self, matrix: np.ndarray, qubits: Sequence[int]):
"""
Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done.
:param qubits: The qubits to apply the unitary to.
:return: ``self`` to support meth... | [
"Apply",
"an",
"arbitrary",
"unitary",
";",
"not",
"necessarily",
"a",
"named",
"gate",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L80-L90 | [
"def",
"do_gate_matrix",
"(",
"self",
",",
"matrix",
":",
"np",
".",
"ndarray",
",",
"qubits",
":",
"Sequence",
"[",
"int",
"]",
")",
":",
"unitary",
"=",
"lifted_gate_matrix",
"(",
"matrix",
",",
"list",
"(",
"qubits",
")",
",",
"n_qubits",
"=",
"self... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceWavefunctionSimulator.expectation | Compute the expectation of an operator.
:param operator: The operator
:return: The operator's expectation value | pyquil/reference_simulator.py | def expectation(self, operator: Union[PauliTerm, PauliSum]):
"""
Compute the expectation of an operator.
:param operator: The operator
:return: The operator's expectation value
"""
if not isinstance(operator, PauliSum):
operator = PauliSum([operator])
... | def expectation(self, operator: Union[PauliTerm, PauliSum]):
"""
Compute the expectation of an operator.
:param operator: The operator
:return: The operator's expectation value
"""
if not isinstance(operator, PauliSum):
operator = PauliSum([operator])
... | [
"Compute",
"the",
"expectation",
"of",
"an",
"operator",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L120-L130 | [
"def",
"expectation",
"(",
"self",
",",
"operator",
":",
"Union",
"[",
"PauliTerm",
",",
"PauliSum",
"]",
")",
":",
"if",
"not",
"isinstance",
"(",
"operator",
",",
"PauliSum",
")",
":",
"operator",
"=",
"PauliSum",
"(",
"[",
"operator",
"]",
")",
"ret... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceDensitySimulator.sample_bitstrings | Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits) | pyquil/reference_simulator.py | def sample_bitstrings(self, n_samples):
"""
Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits)
"""
if self.rs is ... | def sample_bitstrings(self, n_samples):
"""
Sample bitstrings from the distribution defined by the wavefunction.
Qubit 0 is at ``out[:, 0]``.
:param n_samples: The number of bitstrings to sample
:return: An array of shape (n_samples, n_qubits)
"""
if self.rs is ... | [
"Sample",
"bitstrings",
"from",
"the",
"distribution",
"defined",
"by",
"the",
"wavefunction",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L169-L186 | [
"def",
"sample_bitstrings",
"(",
"self",
",",
"n_samples",
")",
":",
"if",
"self",
".",
"rs",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"You have tried to perform a stochastic operation without setting the \"",
"\"random state of the simulator. Might I suggest using a Py... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceDensitySimulator.do_gate | Perform a gate.
:return: ``self`` to support method chaining. | pyquil/reference_simulator.py | def do_gate(self, gate: Gate) -> 'AbstractQuantumSimulator':
"""
Perform a gate.
:return: ``self`` to support method chaining.
"""
unitary = lifted_gate(gate=gate, n_qubits=self.n_qubits)
self.density = unitary.dot(self.density).dot(np.conj(unitary).T)
return sel... | def do_gate(self, gate: Gate) -> 'AbstractQuantumSimulator':
"""
Perform a gate.
:return: ``self`` to support method chaining.
"""
unitary = lifted_gate(gate=gate, n_qubits=self.n_qubits)
self.density = unitary.dot(self.density).dot(np.conj(unitary).T)
return sel... | [
"Perform",
"a",
"gate",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L188-L196 | [
"def",
"do_gate",
"(",
"self",
",",
"gate",
":",
"Gate",
")",
"->",
"'AbstractQuantumSimulator'",
":",
"unitary",
"=",
"lifted_gate",
"(",
"gate",
"=",
"gate",
",",
"n_qubits",
"=",
"self",
".",
"n_qubits",
")",
"self",
".",
"density",
"=",
"unitary",
".... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceDensitySimulator.do_gate_matrix | Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done
:param qubits: A list of qubits to apply the unitary to.
:return: ``self`` to support method chaining. | pyquil/reference_simulator.py | def do_gate_matrix(self, matrix: np.ndarray,
qubits: Sequence[int]) -> 'AbstractQuantumSimulator':
"""
Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done
:param qubits: A list of qubits to apply... | def do_gate_matrix(self, matrix: np.ndarray,
qubits: Sequence[int]) -> 'AbstractQuantumSimulator':
"""
Apply an arbitrary unitary; not necessarily a named gate.
:param matrix: The unitary matrix to apply. No checks are done
:param qubits: A list of qubits to apply... | [
"Apply",
"an",
"arbitrary",
"unitary",
";",
"not",
"necessarily",
"a",
"named",
"gate",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L198-L209 | [
"def",
"do_gate_matrix",
"(",
"self",
",",
"matrix",
":",
"np",
".",
"ndarray",
",",
"qubits",
":",
"Sequence",
"[",
"int",
"]",
")",
"->",
"'AbstractQuantumSimulator'",
":",
"unitary",
"=",
"lifted_gate_matrix",
"(",
"matrix",
"=",
"matrix",
",",
"qubit_ind... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | ReferenceDensitySimulator.do_measurement | Measure a qubit and collapse the wavefunction
:return: The measurement result. A 1 or a 0. | pyquil/reference_simulator.py | def do_measurement(self, qubit: int) -> int:
"""
Measure a qubit and collapse the wavefunction
:return: The measurement result. A 1 or a 0.
"""
if self.rs is None:
raise ValueError("You have tried to perform a stochastic operation without setting the "
... | def do_measurement(self, qubit: int) -> int:
"""
Measure a qubit and collapse the wavefunction
:return: The measurement result. A 1 or a 0.
"""
if self.rs is None:
raise ValueError("You have tried to perform a stochastic operation without setting the "
... | [
"Measure",
"a",
"qubit",
"and",
"collapse",
"the",
"wavefunction"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L211-L233 | [
"def",
"do_measurement",
"(",
"self",
",",
"qubit",
":",
"int",
")",
"->",
"int",
":",
"if",
"self",
".",
"rs",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"You have tried to perform a stochastic operation without setting the \"",
"\"random state of the simulator. ... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | run_parser | Run the ANTLR parser.
:param str quil: a single or multiline Quil program
:return: list of instructions that were parsed | pyquil/_parser/PyQuilListener.py | def run_parser(quil):
# type: (str) -> List[AbstractInstruction]
"""
Run the ANTLR parser.
:param str quil: a single or multiline Quil program
:return: list of instructions that were parsed
"""
# Step 1: Run the Lexer
input_stream = InputStream(quil)
lexer = QuilLexer(input_stream)
... | def run_parser(quil):
# type: (str) -> List[AbstractInstruction]
"""
Run the ANTLR parser.
:param str quil: a single or multiline Quil program
:return: list of instructions that were parsed
"""
# Step 1: Run the Lexer
input_stream = InputStream(quil)
lexer = QuilLexer(input_stream)
... | [
"Run",
"the",
"ANTLR",
"parser",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/_parser/PyQuilListener.py#L50-L74 | [
"def",
"run_parser",
"(",
"quil",
")",
":",
"# type: (str) -> List[AbstractInstruction]",
"# Step 1: Run the Lexer",
"input_stream",
"=",
"InputStream",
"(",
"quil",
")",
"lexer",
"=",
"QuilLexer",
"(",
"input_stream",
")",
"stream",
"=",
"CommonTokenStream",
"(",
"le... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _expression | NB: Order of operations is already dealt with by the grammar. Here we can simply match on the type. | pyquil/_parser/PyQuilListener.py | def _expression(expression):
# type: (QuilParser.ExpressionContext) -> Any
"""
NB: Order of operations is already dealt with by the grammar. Here we can simply match on the type.
"""
if isinstance(expression, QuilParser.ParenthesisExpContext):
return _expression(expression.expression())
... | def _expression(expression):
# type: (QuilParser.ExpressionContext) -> Any
"""
NB: Order of operations is already dealt with by the grammar. Here we can simply match on the type.
"""
if isinstance(expression, QuilParser.ParenthesisExpContext):
return _expression(expression.expression())
... | [
"NB",
":",
"Order",
"of",
"operations",
"is",
"already",
"dealt",
"with",
"by",
"the",
"grammar",
".",
"Here",
"we",
"can",
"simply",
"match",
"on",
"the",
"type",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/_parser/PyQuilListener.py#L414-L448 | [
"def",
"_expression",
"(",
"expression",
")",
":",
"# type: (QuilParser.ExpressionContext) -> Any",
"if",
"isinstance",
"(",
"expression",
",",
"QuilParser",
".",
"ParenthesisExpContext",
")",
":",
"return",
"_expression",
"(",
"expression",
".",
"expression",
"(",
")... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | _binary_exp | Apply an operator to two expressions. Start by evaluating both sides of the operator. | pyquil/_parser/PyQuilListener.py | def _binary_exp(expression, op):
# type: (QuilParser.ExpressionContext, Callable) -> Number
"""
Apply an operator to two expressions. Start by evaluating both sides of the operator.
"""
[arg1, arg2] = expression.expression()
return op(_expression(arg1), _expression(arg2)) | def _binary_exp(expression, op):
# type: (QuilParser.ExpressionContext, Callable) -> Number
"""
Apply an operator to two expressions. Start by evaluating both sides of the operator.
"""
[arg1, arg2] = expression.expression()
return op(_expression(arg1), _expression(arg2)) | [
"Apply",
"an",
"operator",
"to",
"two",
"expressions",
".",
"Start",
"by",
"evaluating",
"both",
"sides",
"of",
"the",
"operator",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/_parser/PyQuilListener.py#L451-L457 | [
"def",
"_binary_exp",
"(",
"expression",
",",
"op",
")",
":",
"# type: (QuilParser.ExpressionContext, Callable) -> Number",
"[",
"arg1",
",",
"arg2",
"]",
"=",
"expression",
".",
"expression",
"(",
")",
"return",
"op",
"(",
"_expression",
"(",
"arg1",
")",
",",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | CustomErrorListener.get_expected_tokens | Like the default getExpectedTokens method except that it will fallback to the rule name if the token isn't a
literal. For instance, instead of <INVALID> for integer it will return the rule name: INT | pyquil/_parser/PyQuilListener.py | def get_expected_tokens(self, parser, interval_set):
# type: (QuilParser, IntervalSet) -> Iterator
"""
Like the default getExpectedTokens method except that it will fallback to the rule name if the token isn't a
literal. For instance, instead of <INVALID> for integer it will return the ... | def get_expected_tokens(self, parser, interval_set):
# type: (QuilParser, IntervalSet) -> Iterator
"""
Like the default getExpectedTokens method except that it will fallback to the rule name if the token isn't a
literal. For instance, instead of <INVALID> for integer it will return the ... | [
"Like",
"the",
"default",
"getExpectedTokens",
"method",
"except",
"that",
"it",
"will",
"fallback",
"to",
"the",
"rule",
"name",
"if",
"the",
"token",
"isn",
"t",
"a",
"literal",
".",
"For",
"instance",
"instead",
"of",
"<INVALID",
">",
"for",
"integer",
... | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/_parser/PyQuilListener.py#L87-L100 | [
"def",
"get_expected_tokens",
"(",
"self",
",",
"parser",
",",
"interval_set",
")",
":",
"# type: (QuilParser, IntervalSet) -> Iterator",
"for",
"tok",
"in",
"interval_set",
":",
"literal_name",
"=",
"parser",
".",
"literalNames",
"[",
"tok",
"]",
"symbolic_name",
"... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | PyQuilListener.exitCircuitGate | PyQuil has no constructs yet for representing gate instructions within a DEFCIRCUIT (ie. gates where the qubits
are inputs to the call to the circuit). Therefore we parse them as a raw instructions. | pyquil/_parser/PyQuilListener.py | def exitCircuitGate(self, ctx: QuilParser.CircuitGateContext):
"""
PyQuil has no constructs yet for representing gate instructions within a DEFCIRCUIT (ie. gates where the qubits
are inputs to the call to the circuit). Therefore we parse them as a raw instructions.
"""
gate_name ... | def exitCircuitGate(self, ctx: QuilParser.CircuitGateContext):
"""
PyQuil has no constructs yet for representing gate instructions within a DEFCIRCUIT (ie. gates where the qubits
are inputs to the call to the circuit). Therefore we parse them as a raw instructions.
"""
gate_name ... | [
"PyQuil",
"has",
"no",
"constructs",
"yet",
"for",
"representing",
"gate",
"instructions",
"within",
"a",
"DEFCIRCUIT",
"(",
"ie",
".",
"gates",
"where",
"the",
"qubits",
"are",
"inputs",
"to",
"the",
"call",
"to",
"the",
"circuit",
")",
".",
"Therefore",
... | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/_parser/PyQuilListener.py#L173-L184 | [
"def",
"exitCircuitGate",
"(",
"self",
",",
"ctx",
":",
"QuilParser",
".",
"CircuitGateContext",
")",
":",
"gate_name",
"=",
"ctx",
".",
"name",
"(",
")",
".",
"getText",
"(",
")",
"params",
"=",
"[",
"param",
".",
"getText",
"(",
")",
"for",
"param",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | unpack_reg_val_pair | Helper function for typechecking / type-coercing arguments to constructors for binary classical operators.
:param classical_reg1: Specifier for the classical memory address to be modified.
:param classical_reg2: Specifier for the second argument: a classical memory address or an immediate value.
:return: A... | pyquil/gates.py | def unpack_reg_val_pair(classical_reg1, classical_reg2):
"""
Helper function for typechecking / type-coercing arguments to constructors for binary classical operators.
:param classical_reg1: Specifier for the classical memory address to be modified.
:param classical_reg2: Specifier for the second argum... | def unpack_reg_val_pair(classical_reg1, classical_reg2):
"""
Helper function for typechecking / type-coercing arguments to constructors for binary classical operators.
:param classical_reg1: Specifier for the classical memory address to be modified.
:param classical_reg2: Specifier for the second argum... | [
"Helper",
"function",
"for",
"typechecking",
"/",
"type",
"-",
"coercing",
"arguments",
"to",
"constructors",
"for",
"binary",
"classical",
"operators",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L29-L43 | [
"def",
"unpack_reg_val_pair",
"(",
"classical_reg1",
",",
"classical_reg2",
")",
":",
"left",
"=",
"unpack_classical_reg",
"(",
"classical_reg1",
")",
"if",
"isinstance",
"(",
"classical_reg2",
",",
"int",
")",
"or",
"isinstance",
"(",
"classical_reg2",
",",
"floa... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | prepare_ternary_operands | Helper function for typechecking / type-coercing arguments to constructors for ternary classical operators.
:param classical_reg1: Specifier for the classical memory address to be modified.
:param classical_reg2: Specifier for the left operand: a classical memory address.
:param classical_reg3: Specifier f... | pyquil/gates.py | def prepare_ternary_operands(classical_reg1, classical_reg2, classical_reg3):
"""
Helper function for typechecking / type-coercing arguments to constructors for ternary classical operators.
:param classical_reg1: Specifier for the classical memory address to be modified.
:param classical_reg2: Specifie... | def prepare_ternary_operands(classical_reg1, classical_reg2, classical_reg3):
"""
Helper function for typechecking / type-coercing arguments to constructors for ternary classical operators.
:param classical_reg1: Specifier for the classical memory address to be modified.
:param classical_reg2: Specifie... | [
"Helper",
"function",
"for",
"typechecking",
"/",
"type",
"-",
"coercing",
"arguments",
"to",
"constructors",
"for",
"ternary",
"classical",
"operators",
"."
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L46-L64 | [
"def",
"prepare_ternary_operands",
"(",
"classical_reg1",
",",
"classical_reg2",
",",
"classical_reg3",
")",
":",
"if",
"isinstance",
"(",
"classical_reg1",
",",
"int",
")",
":",
"raise",
"TypeError",
"(",
"\"Target operand of comparison must be a memory address\"",
")",
... | ec98e453084b0037d69d8c3245f6822a5422593d |
train | RX | Produces the RX gate::
RX(phi) = [[cos(phi / 2), -1j * sin(phi / 2)],
[-1j * sin(phi / 2), cos(phi / 2)]]
This gate is a single qubit X-rotation.
:param angle: The angle to rotate around the x-axis on the bloch sphere.
:param qubit: The qubit apply the gate to.
:returns: A ... | pyquil/gates.py | def RX(angle, qubit):
"""Produces the RX gate::
RX(phi) = [[cos(phi / 2), -1j * sin(phi / 2)],
[-1j * sin(phi / 2), cos(phi / 2)]]
This gate is a single qubit X-rotation.
:param angle: The angle to rotate around the x-axis on the bloch sphere.
:param qubit: The qubit apply ... | def RX(angle, qubit):
"""Produces the RX gate::
RX(phi) = [[cos(phi / 2), -1j * sin(phi / 2)],
[-1j * sin(phi / 2), cos(phi / 2)]]
This gate is a single qubit X-rotation.
:param angle: The angle to rotate around the x-axis on the bloch sphere.
:param qubit: The qubit apply ... | [
"Produces",
"the",
"RX",
"gate",
"::"
] | rigetti/pyquil | python | https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L168-L180 | [
"def",
"RX",
"(",
"angle",
",",
"qubit",
")",
":",
"return",
"Gate",
"(",
"name",
"=",
"\"RX\"",
",",
"params",
"=",
"[",
"angle",
"]",
",",
"qubits",
"=",
"[",
"unpack_qubit",
"(",
"qubit",
")",
"]",
")"
] | ec98e453084b0037d69d8c3245f6822a5422593d |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.