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
RY
Produces the RY gate:: RY(phi) = [[cos(phi / 2), -sin(phi / 2)], [sin(phi / 2), cos(phi / 2)]] This gate is a single qubit Y-rotation. :param angle: The angle to rotate around the y-axis on the bloch sphere. :param qubit: The qubit apply the gate to. :returns: A Gate object...
pyquil/gates.py
def RY(angle, qubit): """Produces the RY gate:: RY(phi) = [[cos(phi / 2), -sin(phi / 2)], [sin(phi / 2), cos(phi / 2)]] This gate is a single qubit Y-rotation. :param angle: The angle to rotate around the y-axis on the bloch sphere. :param qubit: The qubit apply the gate to...
def RY(angle, qubit): """Produces the RY gate:: RY(phi) = [[cos(phi / 2), -sin(phi / 2)], [sin(phi / 2), cos(phi / 2)]] This gate is a single qubit Y-rotation. :param angle: The angle to rotate around the y-axis on the bloch sphere. :param qubit: The qubit apply the gate to...
[ "Produces", "the", "RY", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L183-L195
[ "def", "RY", "(", "angle", ",", "qubit", ")", ":", "return", "Gate", "(", "name", "=", "\"RY\"", ",", "params", "=", "[", "angle", "]", ",", "qubits", "=", "[", "unpack_qubit", "(", "qubit", ")", "]", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
RZ
Produces the RZ gate:: RZ(phi) = [[cos(phi / 2) - 1j * sin(phi / 2), 0] [0, cos(phi / 2) + 1j * sin(phi / 2)]] This gate is a single qubit Z-rotation. :param angle: The angle to rotate around the z-axis on the bloch sphere. :param qubit: The qubit apply the gate to. :return...
pyquil/gates.py
def RZ(angle, qubit): """Produces the RZ gate:: RZ(phi) = [[cos(phi / 2) - 1j * sin(phi / 2), 0] [0, cos(phi / 2) + 1j * sin(phi / 2)]] This gate is a single qubit Z-rotation. :param angle: The angle to rotate around the z-axis on the bloch sphere. :param qubit: The qubit a...
def RZ(angle, qubit): """Produces the RZ gate:: RZ(phi) = [[cos(phi / 2) - 1j * sin(phi / 2), 0] [0, cos(phi / 2) + 1j * sin(phi / 2)]] This gate is a single qubit Z-rotation. :param angle: The angle to rotate around the z-axis on the bloch sphere. :param qubit: The qubit a...
[ "Produces", "the", "RZ", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L198-L210
[ "def", "RZ", "(", "angle", ",", "qubit", ")", ":", "return", "Gate", "(", "name", "=", "\"RZ\"", ",", "params", "=", "[", "angle", "]", ",", "qubits", "=", "[", "unpack_qubit", "(", "qubit", ")", "]", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
PHASE
Produces the PHASE gate:: PHASE(phi) = [[1, 0], [0, exp(1j * phi)]] This is the same as the RZ gate. :param angle: The angle to rotate around the z-axis on the bloch sphere. :param qubit: The qubit apply the gate to. :returns: A Gate object.
pyquil/gates.py
def PHASE(angle, qubit): """Produces the PHASE gate:: PHASE(phi) = [[1, 0], [0, exp(1j * phi)]] This is the same as the RZ gate. :param angle: The angle to rotate around the z-axis on the bloch sphere. :param qubit: The qubit apply the gate to. :returns: A Gate objec...
def PHASE(angle, qubit): """Produces the PHASE gate:: PHASE(phi) = [[1, 0], [0, exp(1j * phi)]] This is the same as the RZ gate. :param angle: The angle to rotate around the z-axis on the bloch sphere. :param qubit: The qubit apply the gate to. :returns: A Gate objec...
[ "Produces", "the", "PHASE", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L213-L225
[ "def", "PHASE", "(", "angle", ",", "qubit", ")", ":", "return", "Gate", "(", "name", "=", "\"PHASE\"", ",", "params", "=", "[", "angle", "]", ",", "qubits", "=", "[", "unpack_qubit", "(", "qubit", ")", "]", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
CNOT
Produces a controlled-NOT (controlled-X) gate:: CNOT = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]] This gate applies to two qubit arguments to produce the controlled-not gate instruction. :param control: The control qubit. :param target...
pyquil/gates.py
def CNOT(control, target): """Produces a controlled-NOT (controlled-X) gate:: CNOT = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]] This gate applies to two qubit arguments to produce the controlled-not gate instruction. :param control: Th...
def CNOT(control, target): """Produces a controlled-NOT (controlled-X) gate:: CNOT = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]] This gate applies to two qubit arguments to produce the controlled-not gate instruction. :param control: Th...
[ "Produces", "a", "controlled", "-", "NOT", "(", "controlled", "-", "X", ")", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L247-L262
[ "def", "CNOT", "(", "control", ",", "target", ")", ":", "return", "Gate", "(", "name", "=", "\"CNOT\"", ",", "params", "=", "[", "]", ",", "qubits", "=", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "(", "control", ",", "target", ")", "]...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CCNOT
Produces a doubly-controlled NOT gate:: CCNOT = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, ...
pyquil/gates.py
def CCNOT(control1, control2, target): """Produces a doubly-controlled NOT gate:: CCNOT = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [...
def CCNOT(control1, control2, target): """Produces a doubly-controlled NOT gate:: CCNOT = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [...
[ "Produces", "a", "doubly", "-", "controlled", "NOT", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L265-L287
[ "def", "CCNOT", "(", "control1", ",", "control2", ",", "target", ")", ":", "qubits", "=", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "(", "control1", ",", "control2", ",", "target", ")", "]", "return", "Gate", "(", "name", "=", "\"CCNOT\""...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CPHASE00
Produces a controlled-phase gate that phases the ``|00>`` state:: CPHASE00(phi) = diag([exp(1j * phi), 1, 1, 1]) This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 00. :param angle: The input phase angle to apply when both qu...
pyquil/gates.py
def CPHASE00(angle, control, target): """Produces a controlled-phase gate that phases the ``|00>`` state:: CPHASE00(phi) = diag([exp(1j * phi), 1, 1, 1]) This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 00. :param angle...
def CPHASE00(angle, control, target): """Produces a controlled-phase gate that phases the ``|00>`` state:: CPHASE00(phi) = diag([exp(1j * phi), 1, 1, 1]) This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 00. :param angle...
[ "Produces", "a", "controlled", "-", "phase", "gate", "that", "phases", "the", "|00", ">", "state", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L290-L304
[ "def", "CPHASE00", "(", "angle", ",", "control", ",", "target", ")", ":", "qubits", "=", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "(", "control", ",", "target", ")", "]", "return", "Gate", "(", "name", "=", "\"CPHASE00\"", ",", "params",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
CSWAP
Produces a controlled-SWAP gate. This gate conditionally swaps the state of two qubits:: CSWAP = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], ...
pyquil/gates.py
def CSWAP(control, target_1, target_2): """Produces a controlled-SWAP gate. This gate conditionally swaps the state of two qubits:: CSWAP = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], ...
def CSWAP(control, target_1, target_2): """Produces a controlled-SWAP gate. This gate conditionally swaps the state of two qubits:: CSWAP = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], ...
[ "Produces", "a", "controlled", "-", "SWAP", "gate", ".", "This", "gate", "conditionally", "swaps", "the", "state", "of", "two", "qubits", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L379-L398
[ "def", "CSWAP", "(", "control", ",", "target_1", ",", "target_2", ")", ":", "qubits", "=", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "(", "control", ",", "target_1", ",", "target_2", ")", "]", "return", "Gate", "(", "name", "=", "\"CSWAP\...
ec98e453084b0037d69d8c3245f6822a5422593d
train
ISWAP
Produces an ISWAP gate:: ISWAP = [[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0], [0, 0, 0, 1]] This gate swaps the state of two qubits, applying a -i phase to q1 when it is in the 1 state and a -i phase to q2 when it is in the 0 state. :param ...
pyquil/gates.py
def ISWAP(q1, q2): """Produces an ISWAP gate:: ISWAP = [[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0], [0, 0, 0, 1]] This gate swaps the state of two qubits, applying a -i phase to q1 when it is in the 1 state and a -i phase to q2 when it is in...
def ISWAP(q1, q2): """Produces an ISWAP gate:: ISWAP = [[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0], [0, 0, 0, 1]] This gate swaps the state of two qubits, applying a -i phase to q1 when it is in the 1 state and a -i phase to q2 when it is in...
[ "Produces", "an", "ISWAP", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L401-L416
[ "def", "ISWAP", "(", "q1", ",", "q2", ")", ":", "return", "Gate", "(", "name", "=", "\"ISWAP\"", ",", "params", "=", "[", "]", ",", "qubits", "=", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "(", "q1", ",", "q2", ")", "]", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
PSWAP
Produces a parameterized SWAP gate:: PSWAP(phi) = [[1, 0, 0, 0], [0, 0, exp(1j * phi), 0], [0, exp(1j * phi), 0, 0], [0, 0, 0, 1]] :param angle: The angle of the phase...
pyquil/gates.py
def PSWAP(angle, q1, q2): """Produces a parameterized SWAP gate:: PSWAP(phi) = [[1, 0, 0, 0], [0, 0, exp(1j * phi), 0], [0, exp(1j * phi), 0, 0], [0, 0, 0, 1]] :pa...
def PSWAP(angle, q1, q2): """Produces a parameterized SWAP gate:: PSWAP(phi) = [[1, 0, 0, 0], [0, 0, exp(1j * phi), 0], [0, exp(1j * phi), 0, 0], [0, 0, 0, 1]] :pa...
[ "Produces", "a", "parameterized", "SWAP", "gate", "::" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L419-L434
[ "def", "PSWAP", "(", "angle", ",", "q1", ",", "q2", ")", ":", "return", "Gate", "(", "name", "=", "\"PSWAP\"", ",", "params", "=", "[", "angle", "]", ",", "qubits", "=", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "(", "q1", ",", "q2"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
MEASURE
Produce a MEASURE instruction. :param qubit: The qubit to measure. :param classical_reg: The classical register to measure into, or None. :return: A Measurement instance.
pyquil/gates.py
def MEASURE(qubit, classical_reg): """ Produce a MEASURE instruction. :param qubit: The qubit to measure. :param classical_reg: The classical register to measure into, or None. :return: A Measurement instance. """ qubit = unpack_qubit(qubit) if classical_reg is None: address = N...
def MEASURE(qubit, classical_reg): """ Produce a MEASURE instruction. :param qubit: The qubit to measure. :param classical_reg: The classical register to measure into, or None. :return: A Measurement instance. """ qubit = unpack_qubit(qubit) if classical_reg is None: address = N...
[ "Produce", "a", "MEASURE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L477-L494
[ "def", "MEASURE", "(", "qubit", ",", "classical_reg", ")", ":", "qubit", "=", "unpack_qubit", "(", "qubit", ")", "if", "classical_reg", "is", "None", ":", "address", "=", "None", "elif", "isinstance", "(", "classical_reg", ",", "int", ")", ":", "warn", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
TRUE
Produce a TRUE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE.
pyquil/gates.py
def TRUE(classical_reg): """ Produce a TRUE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE. """ warn("`TRUE a` has been deprecated. Use `MOVE a 1` instead.") if isinstance(classical_reg, int): classi...
def TRUE(classical_reg): """ Produce a TRUE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE. """ warn("`TRUE a` has been deprecated. Use `MOVE a 1` instead.") if isinstance(classical_reg, int): classi...
[ "Produce", "a", "TRUE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L497-L507
[ "def", "TRUE", "(", "classical_reg", ")", ":", "warn", "(", "\"`TRUE a` has been deprecated. Use `MOVE a 1` instead.\"", ")", "if", "isinstance", "(", "classical_reg", ",", "int", ")", ":", "classical_reg", "=", "Addr", "(", "classical_reg", ")", "return", "MOVE", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
FALSE
Produce a FALSE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE.
pyquil/gates.py
def FALSE(classical_reg): """ Produce a FALSE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE. """ warn("`FALSE a` has been deprecated. Use `MOVE a 0` instead.") if isinstance(classical_reg, int): cla...
def FALSE(classical_reg): """ Produce a FALSE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE. """ warn("`FALSE a` has been deprecated. Use `MOVE a 0` instead.") if isinstance(classical_reg, int): cla...
[ "Produce", "a", "FALSE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L510-L520
[ "def", "FALSE", "(", "classical_reg", ")", ":", "warn", "(", "\"`FALSE a` has been deprecated. Use `MOVE a 0` instead.\"", ")", "if", "isinstance", "(", "classical_reg", ",", "int", ")", ":", "classical_reg", "=", "Addr", "(", "classical_reg", ")", "return", "MOVE",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
AND
Produce an AND instruction. NOTE: The order of operands was reversed in pyQuil <=1.9 . :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalAnd instance.
pyquil/gates.py
def AND(classical_reg1, classical_reg2): """ Produce an AND instruction. NOTE: The order of operands was reversed in pyQuil <=1.9 . :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A Clas...
def AND(classical_reg1, classical_reg2): """ Produce an AND instruction. NOTE: The order of operands was reversed in pyQuil <=1.9 . :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A Clas...
[ "Produce", "an", "AND", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L543-L554
[ "def", "AND", "(", "classical_reg1", ",", "classical_reg2", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg1", ",", "classical_reg2", ")", "return", "ClassicalAnd", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
IOR
Produce an inclusive OR instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalOr instance.
pyquil/gates.py
def IOR(classical_reg1, classical_reg2): """ Produce an inclusive OR instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalOr instance. """ left, right = unpack_reg_...
def IOR(classical_reg1, classical_reg2): """ Produce an inclusive OR instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalOr instance. """ left, right = unpack_reg_...
[ "Produce", "an", "inclusive", "OR", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L571-L580
[ "def", "IOR", "(", "classical_reg1", ",", "classical_reg2", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg1", ",", "classical_reg2", ")", "return", "ClassicalInclusiveOr", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
XOR
Produce an exclusive OR instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalOr instance.
pyquil/gates.py
def XOR(classical_reg1, classical_reg2): """ Produce an exclusive OR instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalOr instance. """ left, right = unpack_reg_...
def XOR(classical_reg1, classical_reg2): """ Produce an exclusive OR instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalOr instance. """ left, right = unpack_reg_...
[ "Produce", "an", "exclusive", "OR", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L583-L592
[ "def", "XOR", "(", "classical_reg1", ",", "classical_reg2", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg1", ",", "classical_reg2", ")", "return", "ClassicalExclusiveOr", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
MOVE
Produce a MOVE instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalMove instance.
pyquil/gates.py
def MOVE(classical_reg1, classical_reg2): """ Produce a MOVE instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalMove instance. """ left, right = unpack_reg_val_pa...
def MOVE(classical_reg1, classical_reg2): """ Produce a MOVE instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register or immediate value. :return: A ClassicalMove instance. """ left, right = unpack_reg_val_pa...
[ "Produce", "a", "MOVE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L595-L604
[ "def", "MOVE", "(", "classical_reg1", ",", "classical_reg2", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg1", ",", "classical_reg2", ")", "return", "ClassicalMove", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
EXCHANGE
Produce an EXCHANGE instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register, which gets modified. :return: A ClassicalExchange instance.
pyquil/gates.py
def EXCHANGE(classical_reg1, classical_reg2): """ Produce an EXCHANGE instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register, which gets modified. :return: A ClassicalExchange instance. """ left = unpack_cl...
def EXCHANGE(classical_reg1, classical_reg2): """ Produce an EXCHANGE instruction. :param classical_reg1: The first classical register, which gets modified. :param classical_reg2: The second classical register, which gets modified. :return: A ClassicalExchange instance. """ left = unpack_cl...
[ "Produce", "an", "EXCHANGE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L607-L617
[ "def", "EXCHANGE", "(", "classical_reg1", ",", "classical_reg2", ")", ":", "left", "=", "unpack_classical_reg", "(", "classical_reg1", ")", "right", "=", "unpack_classical_reg", "(", "classical_reg2", ")", "return", "ClassicalExchange", "(", "left", ",", "right", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
LOAD
Produce a LOAD instruction. :param target_reg: LOAD storage target. :param region_name: Named region of memory to load from. :param offset_reg: Offset into region of memory to load from. Must be a MemoryReference. :return: A ClassicalLoad instance.
pyquil/gates.py
def LOAD(target_reg, region_name, offset_reg): """ Produce a LOAD instruction. :param target_reg: LOAD storage target. :param region_name: Named region of memory to load from. :param offset_reg: Offset into region of memory to load from. Must be a MemoryReference. :return: A ClassicalLoad insta...
def LOAD(target_reg, region_name, offset_reg): """ Produce a LOAD instruction. :param target_reg: LOAD storage target. :param region_name: Named region of memory to load from. :param offset_reg: Offset into region of memory to load from. Must be a MemoryReference. :return: A ClassicalLoad insta...
[ "Produce", "a", "LOAD", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L620-L629
[ "def", "LOAD", "(", "target_reg", ",", "region_name", ",", "offset_reg", ")", ":", "return", "ClassicalLoad", "(", "unpack_classical_reg", "(", "target_reg", ")", ",", "region_name", ",", "unpack_classical_reg", "(", "offset_reg", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
ADD
Produce an ADD instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalAdd instance.
pyquil/gates.py
def ADD(classical_reg, right): """ Produce an ADD instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalAdd instance. """ left, right = unpack_reg_val_pair(...
def ADD(classical_reg, right): """ Produce an ADD instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalAdd instance. """ left, right = unpack_reg_val_pair(...
[ "Produce", "an", "ADD", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L655-L664
[ "def", "ADD", "(", "classical_reg", ",", "right", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg", ",", "right", ")", "return", "ClassicalAdd", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
SUB
Produce a SUB instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalSub instance.
pyquil/gates.py
def SUB(classical_reg, right): """ Produce a SUB instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalSub instance. """ left, right = unpack_reg_val_pair(c...
def SUB(classical_reg, right): """ Produce a SUB instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalSub instance. """ left, right = unpack_reg_val_pair(c...
[ "Produce", "a", "SUB", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L667-L676
[ "def", "SUB", "(", "classical_reg", ",", "right", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg", ",", "right", ")", "return", "ClassicalSub", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
MUL
Produce a MUL instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalMul instance.
pyquil/gates.py
def MUL(classical_reg, right): """ Produce a MUL instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalMul instance. """ left, right = unpack_reg_val_pair(c...
def MUL(classical_reg, right): """ Produce a MUL instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalMul instance. """ left, right = unpack_reg_val_pair(c...
[ "Produce", "a", "MUL", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L679-L688
[ "def", "MUL", "(", "classical_reg", ",", "right", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg", ",", "right", ")", "return", "ClassicalMul", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
DIV
Produce an DIV instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalDiv instance.
pyquil/gates.py
def DIV(classical_reg, right): """ Produce an DIV instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalDiv instance. """ left, right = unpack_reg_val_pair(...
def DIV(classical_reg, right): """ Produce an DIV instruction. :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target. :param right: Right operand for the arithmetic operation. :return: A ClassicalDiv instance. """ left, right = unpack_reg_val_pair(...
[ "Produce", "an", "DIV", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L691-L700
[ "def", "DIV", "(", "classical_reg", ",", "right", ")", ":", "left", ",", "right", "=", "unpack_reg_val_pair", "(", "classical_reg", ",", "right", ")", "return", "ClassicalDiv", "(", "left", ",", "right", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
EQ
Produce an EQ instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalEqual instance.
pyquil/gates.py
def EQ(classical_reg1, classical_reg2, classical_reg3): """ Produce an EQ instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalEqual instan...
def EQ(classical_reg1, classical_reg2, classical_reg3): """ Produce an EQ instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalEqual instan...
[ "Produce", "an", "EQ", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L703-L716
[ "def", "EQ", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", ":", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", "=", "prepare_ternary_operands", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", "retu...
ec98e453084b0037d69d8c3245f6822a5422593d
train
LT
Produce an LT instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalLessThan instance.
pyquil/gates.py
def LT(classical_reg1, classical_reg2, classical_reg3): """ Produce an LT instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalLessThan ins...
def LT(classical_reg1, classical_reg2, classical_reg3): """ Produce an LT instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalLessThan ins...
[ "Produce", "an", "LT", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L719-L731
[ "def", "LT", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", ":", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", "=", "prepare_ternary_operands", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", "retu...
ec98e453084b0037d69d8c3245f6822a5422593d
train
LE
Produce an LE instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalLessEqual instance.
pyquil/gates.py
def LE(classical_reg1, classical_reg2, classical_reg3): """ Produce an LE instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalLessEqual in...
def LE(classical_reg1, classical_reg2, classical_reg3): """ Produce an LE instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalLessEqual in...
[ "Produce", "an", "LE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L734-L746
[ "def", "LE", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", ":", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", "=", "prepare_ternary_operands", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", "retu...
ec98e453084b0037d69d8c3245f6822a5422593d
train
GT
Produce an GT instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalGreaterThan instance.
pyquil/gates.py
def GT(classical_reg1, classical_reg2, classical_reg3): """ Produce an GT instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalGreaterThan ...
def GT(classical_reg1, classical_reg2, classical_reg3): """ Produce an GT instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalGreaterThan ...
[ "Produce", "an", "GT", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L749-L761
[ "def", "GT", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", ":", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", "=", "prepare_ternary_operands", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", "retu...
ec98e453084b0037d69d8c3245f6822a5422593d
train
GE
Produce an GE instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalGreaterEqual instance.
pyquil/gates.py
def GE(classical_reg1, classical_reg2, classical_reg3): """ Produce an GE instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalGreaterEqual...
def GE(classical_reg1, classical_reg2, classical_reg3): """ Produce an GE instruction. :param classical_reg1: Memory address to which to store the comparison result. :param classical_reg2: Left comparison operand. :param classical_reg3: Right comparison operand. :return: A ClassicalGreaterEqual...
[ "Produce", "an", "GE", "instruction", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/gates.py#L764-L776
[ "def", "GE", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", ":", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", "=", "prepare_ternary_operands", "(", "classical_reg1", ",", "classical_reg2", ",", "classical_reg3", ")", "retu...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_if_statement
Evaluate an if statement within a @magicquil block. If the test value is a Quil Addr then unwind it into quil code equivalent to an if then statement using jumps. Both sides of the if statement need to be evaluated and placed into separate Programs, which is why we create new program contexts for their eva...
pyquil/magic.py
def _if_statement(test, if_function, else_function) -> None: """ Evaluate an if statement within a @magicquil block. If the test value is a Quil Addr then unwind it into quil code equivalent to an if then statement using jumps. Both sides of the if statement need to be evaluated and placed into separat...
def _if_statement(test, if_function, else_function) -> None: """ Evaluate an if statement within a @magicquil block. If the test value is a Quil Addr then unwind it into quil code equivalent to an if then statement using jumps. Both sides of the if statement need to be evaluated and placed into separat...
[ "Evaluate", "an", "if", "statement", "within", "a", "@magicquil", "block", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/magic.py#L64-L102
[ "def", "_if_statement", "(", "test", ",", "if_function", ",", "else_function", ")", "->", "None", ":", "if", "isinstance", "(", "test", ",", "Addr", ")", ":", "token", "=", "_program_context", ".", "set", "(", "Program", "(", ")", ")", "if_function", "("...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_rewrite_function
Rewrite a function so that any if/else branches are intercepted and their behavior can be overridden. This is accomplished using 3 steps: 1. Get the source of the function and then rewrite the AST using _IfTransformer 2. Do some small fixups to the tree to make sure a) the function doesn't have the...
pyquil/magic.py
def _rewrite_function(f): """ Rewrite a function so that any if/else branches are intercepted and their behavior can be overridden. This is accomplished using 3 steps: 1. Get the source of the function and then rewrite the AST using _IfTransformer 2. Do some small fixups to the tree to make sure ...
def _rewrite_function(f): """ Rewrite a function so that any if/else branches are intercepted and their behavior can be overridden. This is accomplished using 3 steps: 1. Get the source of the function and then rewrite the AST using _IfTransformer 2. Do some small fixups to the tree to make sure ...
[ "Rewrite", "a", "function", "so", "that", "any", "if", "/", "else", "branches", "are", "intercepted", "and", "their", "behavior", "can", "be", "overridden", ".", "This", "is", "accomplished", "using", "3", "steps", ":" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/magic.py#L157-L187
[ "def", "_rewrite_function", "(", "f", ")", ":", "source", "=", "inspect", ".", "getsource", "(", "f", ")", "tree", "=", "ast", ".", "parse", "(", "source", ")", "_IfTransformer", "(", ")", ".", "visit", "(", "tree", ")", "ast", ".", "fix_missing_locati...
ec98e453084b0037d69d8c3245f6822a5422593d
train
magicquil
Decorator to enable a more convenient syntax for writing quil programs. With this decorator there is no need to keep track of a Program object and regular Python if/else branches can be used for classical control flow. Example usage: @magicquil def fast_reset(q1): reg1 = MEASURE(q1...
pyquil/magic.py
def magicquil(f): """ Decorator to enable a more convenient syntax for writing quil programs. With this decorator there is no need to keep track of a Program object and regular Python if/else branches can be used for classical control flow. Example usage: @magicquil def fast_reset(q1):...
def magicquil(f): """ Decorator to enable a more convenient syntax for writing quil programs. With this decorator there is no need to keep track of a Program object and regular Python if/else branches can be used for classical control flow. Example usage: @magicquil def fast_reset(q1):...
[ "Decorator", "to", "enable", "a", "more", "convenient", "syntax", "for", "writing", "quil", "programs", ".", "With", "this", "decorator", "there", "is", "no", "need", "to", "keep", "track", "of", "a", "Program", "object", "and", "regular", "Python", "if", ...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/magic.py#L190-L221
[ "def", "magicquil", "(", "f", ")", ":", "rewritten_function", "=", "_rewrite_function", "(", "f", ")", "@", "functools", ".", "wraps", "(", "f", ")", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "_program_context", ".", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_what_type_of_qubit_does_it_use
Helper function to peruse through a program's qubits. This function will also enforce the condition that a Program uses either all placeholders or all instantiated qubits to avoid accidentally mixing the two. This function will warn if your program doesn't use any qubits. :return: tuple of (whether th...
pyquil/quil.py
def _what_type_of_qubit_does_it_use(program): """Helper function to peruse through a program's qubits. This function will also enforce the condition that a Program uses either all placeholders or all instantiated qubits to avoid accidentally mixing the two. This function will warn if your program doesn...
def _what_type_of_qubit_does_it_use(program): """Helper function to peruse through a program's qubits. This function will also enforce the condition that a Program uses either all placeholders or all instantiated qubits to avoid accidentally mixing the two. This function will warn if your program doesn...
[ "Helper", "function", "to", "peruse", "through", "a", "program", "s", "qubits", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L684-L734
[ "def", "_what_type_of_qubit_does_it_use", "(", "program", ")", ":", "has_placeholders", "=", "False", "has_real_qubits", "=", "False", "# We probably want to index qubits in the order they are encountered in the program", "# so an ordered set would be nice. Python doesn't *have* an ordered...
ec98e453084b0037d69d8c3245f6822a5422593d
train
get_default_qubit_mapping
Takes a program which contains qubit placeholders and provides a mapping to the integers 0 through N-1. The output of this function is suitable for input to :py:func:`address_qubits`. :param program: A program containing qubit placeholders :return: A dictionary mapping qubit placeholder to an addresse...
pyquil/quil.py
def get_default_qubit_mapping(program): """ Takes a program which contains qubit placeholders and provides a mapping to the integers 0 through N-1. The output of this function is suitable for input to :py:func:`address_qubits`. :param program: A program containing qubit placeholders :return: A...
def get_default_qubit_mapping(program): """ Takes a program which contains qubit placeholders and provides a mapping to the integers 0 through N-1. The output of this function is suitable for input to :py:func:`address_qubits`. :param program: A program containing qubit placeholders :return: A...
[ "Takes", "a", "program", "which", "contains", "qubit", "placeholders", "and", "provides", "a", "mapping", "to", "the", "integers", "0", "through", "N", "-", "1", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L737-L752
[ "def", "get_default_qubit_mapping", "(", "program", ")", ":", "fake_qubits", ",", "real_qubits", ",", "qubits", "=", "_what_type_of_qubit_does_it_use", "(", "program", ")", "if", "real_qubits", ":", "warnings", ".", "warn", "(", "\"This program contains integer qubits, ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
address_qubits
Takes a program which contains placeholders and assigns them all defined values. Either all qubits must be defined or all undefined. If qubits are undefined, you may provide a qubit mapping to specify how placeholders get mapped to actual qubits. If a mapping is not provided, integers 0 through N are used....
pyquil/quil.py
def address_qubits(program, qubit_mapping=None): """ Takes a program which contains placeholders and assigns them all defined values. Either all qubits must be defined or all undefined. If qubits are undefined, you may provide a qubit mapping to specify how placeholders get mapped to actual qubits....
def address_qubits(program, qubit_mapping=None): """ Takes a program which contains placeholders and assigns them all defined values. Either all qubits must be defined or all undefined. If qubits are undefined, you may provide a qubit mapping to specify how placeholders get mapped to actual qubits....
[ "Takes", "a", "program", "which", "contains", "placeholders", "and", "assigns", "them", "all", "defined", "values", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L755-L812
[ "def", "address_qubits", "(", "program", ",", "qubit_mapping", "=", "None", ")", ":", "fake_qubits", ",", "real_qubits", ",", "qubits", "=", "_what_type_of_qubit_does_it_use", "(", "program", ")", "if", "real_qubits", ":", "if", "qubit_mapping", "is", "not", "No...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_get_label
Helper function to either get the appropriate label for a given placeholder or generate a new label and update the mapping. See :py:func:`instantiate_labels` for usage.
pyquil/quil.py
def _get_label(placeholder, label_mapping, label_i): """Helper function to either get the appropriate label for a given placeholder or generate a new label and update the mapping. See :py:func:`instantiate_labels` for usage. """ if placeholder in label_mapping: return label_mapping[placehol...
def _get_label(placeholder, label_mapping, label_i): """Helper function to either get the appropriate label for a given placeholder or generate a new label and update the mapping. See :py:func:`instantiate_labels` for usage. """ if placeholder in label_mapping: return label_mapping[placehol...
[ "Helper", "function", "to", "either", "get", "the", "appropriate", "label", "for", "a", "given", "placeholder", "or", "generate", "a", "new", "label", "and", "update", "the", "mapping", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L815-L827
[ "def", "_get_label", "(", "placeholder", ",", "label_mapping", ",", "label_i", ")", ":", "if", "placeholder", "in", "label_mapping", ":", "return", "label_mapping", "[", "placeholder", "]", ",", "label_mapping", ",", "label_i", "new_target", "=", "Label", "(", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
instantiate_labels
Takes an iterable of instructions which may contain label placeholders and assigns them all defined values. :return: list of instructions with all label placeholders assigned to real labels.
pyquil/quil.py
def instantiate_labels(instructions): """ Takes an iterable of instructions which may contain label placeholders and assigns them all defined values. :return: list of instructions with all label placeholders assigned to real labels. """ label_i = 1 result = [] label_mapping = dict() ...
def instantiate_labels(instructions): """ Takes an iterable of instructions which may contain label placeholders and assigns them all defined values. :return: list of instructions with all label placeholders assigned to real labels. """ label_i = 1 result = [] label_mapping = dict() ...
[ "Takes", "an", "iterable", "of", "instructions", "which", "may", "contain", "label", "placeholders", "and", "assigns", "them", "all", "defined", "values", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L830-L854
[ "def", "instantiate_labels", "(", "instructions", ")", ":", "label_i", "=", "1", "result", "=", "[", "]", "label_mapping", "=", "dict", "(", ")", "for", "instr", "in", "instructions", ":", "if", "isinstance", "(", "instr", ",", "Jump", ")", "and", "isins...
ec98e453084b0037d69d8c3245f6822a5422593d
train
implicitly_declare_ro
Implicitly declare a register named ``ro`` for backwards compatibility with Quil 1. There used to be one un-named hunk of classical memory. Now there are variables with declarations. Instead of:: MEASURE 0 [0] You must now measure into a named register, idiomatically:: MEASURE 0 ro[0] ...
pyquil/quil.py
def implicitly_declare_ro(instructions: List[AbstractInstruction]): """ Implicitly declare a register named ``ro`` for backwards compatibility with Quil 1. There used to be one un-named hunk of classical memory. Now there are variables with declarations. Instead of:: MEASURE 0 [0] You mus...
def implicitly_declare_ro(instructions: List[AbstractInstruction]): """ Implicitly declare a register named ``ro`` for backwards compatibility with Quil 1. There used to be one un-named hunk of classical memory. Now there are variables with declarations. Instead of:: MEASURE 0 [0] You mus...
[ "Implicitly", "declare", "a", "register", "named", "ro", "for", "backwards", "compatibility", "with", "Quil", "1", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L857-L910
[ "def", "implicitly_declare_ro", "(", "instructions", ":", "List", "[", "AbstractInstruction", "]", ")", ":", "ro_addrs", ":", "List", "[", "int", "]", "=", "[", "]", "for", "instr", "in", "instructions", ":", "if", "isinstance", "(", "instr", ",", "Declare...
ec98e453084b0037d69d8c3245f6822a5422593d
train
merge_with_pauli_noise
Insert pauli noise channels between each item in the list of programs. This noise channel is implemented as a single noisy identity gate acting on the provided qubits. This method does not rely on merge_programs and so avoids the inclusion of redundant Kraus Pragmas that would occur if merge_programs was ca...
pyquil/quil.py
def merge_with_pauli_noise(prog_list: Iterable, probabilities: List, qubits: List): """ Insert pauli noise channels between each item in the list of programs. This noise channel is implemented as a single noisy identity gate acting on the provided qubits. This method does not rely on merge_programs and ...
def merge_with_pauli_noise(prog_list: Iterable, probabilities: List, qubits: List): """ Insert pauli noise channels between each item in the list of programs. This noise channel is implemented as a single noisy identity gate acting on the provided qubits. This method does not rely on merge_programs and ...
[ "Insert", "pauli", "noise", "channels", "between", "each", "item", "in", "the", "list", "of", "programs", ".", "This", "noise", "channel", "is", "implemented", "as", "a", "single", "noisy", "identity", "gate", "acting", "on", "the", "provided", "qubits", "."...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L913-L938
[ "def", "merge_with_pauli_noise", "(", "prog_list", ":", "Iterable", ",", "probabilities", ":", "List", ",", "qubits", ":", "List", ")", ":", "p", "=", "Program", "(", ")", "p", ".", "defgate", "(", "\"pauli_noise\"", ",", "np", ".", "eye", "(", "2", "*...
ec98e453084b0037d69d8c3245f6822a5422593d
train
merge_programs
Merges a list of pyQuil programs into a single one by appending them in sequence. If multiple programs in the list contain the same gate and/or noisy gate definition with identical name, this definition will only be applied once. If different definitions with the same name appear multiple times in the progr...
pyquil/quil.py
def merge_programs(prog_list): """ Merges a list of pyQuil programs into a single one by appending them in sequence. If multiple programs in the list contain the same gate and/or noisy gate definition with identical name, this definition will only be applied once. If different definitions with the s...
def merge_programs(prog_list): """ Merges a list of pyQuil programs into a single one by appending them in sequence. If multiple programs in the list contain the same gate and/or noisy gate definition with identical name, this definition will only be applied once. If different definitions with the s...
[ "Merges", "a", "list", "of", "pyQuil", "programs", "into", "a", "single", "one", "by", "appending", "them", "in", "sequence", ".", "If", "multiple", "programs", "in", "the", "list", "contain", "the", "same", "gate", "and", "/", "or", "noisy", "gate", "de...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L941-L974
[ "def", "merge_programs", "(", "prog_list", ")", ":", "definitions", "=", "[", "gate", "for", "prog", "in", "prog_list", "for", "gate", "in", "Program", "(", "prog", ")", ".", "defined_gates", "]", "seen", "=", "{", "}", "# Collect definitions in reverse order ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
get_classical_addresses_from_program
Returns a sorted list of classical addresses found in the MEASURE instructions in the program. :param Program program: The program from which to get the classical addresses. :return: A mapping from memory region names to lists of offsets appearing in the program.
pyquil/quil.py
def get_classical_addresses_from_program(program) -> Dict[str, List[int]]: """ Returns a sorted list of classical addresses found in the MEASURE instructions in the program. :param Program program: The program from which to get the classical addresses. :return: A mapping from memory region names to lis...
def get_classical_addresses_from_program(program) -> Dict[str, List[int]]: """ Returns a sorted list of classical addresses found in the MEASURE instructions in the program. :param Program program: The program from which to get the classical addresses. :return: A mapping from memory region names to lis...
[ "Returns", "a", "sorted", "list", "of", "classical", "addresses", "found", "in", "the", "MEASURE", "instructions", "in", "the", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L977-L999
[ "def", "get_classical_addresses_from_program", "(", "program", ")", "->", "Dict", "[", "str", ",", "List", "[", "int", "]", "]", ":", "addresses", ":", "Dict", "[", "str", ",", "List", "[", "int", "]", "]", "=", "defaultdict", "(", "list", ")", "flatte...
ec98e453084b0037d69d8c3245f6822a5422593d
train
percolate_declares
Move all the DECLARE statements to the top of the program. Return a fresh obejct. :param program: Perhaps jumbled program. :return: Program with DECLAREs all at the top and otherwise the same sorted contents.
pyquil/quil.py
def percolate_declares(program: Program) -> Program: """ Move all the DECLARE statements to the top of the program. Return a fresh obejct. :param program: Perhaps jumbled program. :return: Program with DECLAREs all at the top and otherwise the same sorted contents. """ declare_program = Program...
def percolate_declares(program: Program) -> Program: """ Move all the DECLARE statements to the top of the program. Return a fresh obejct. :param program: Perhaps jumbled program. :return: Program with DECLAREs all at the top and otherwise the same sorted contents. """ declare_program = Program...
[ "Move", "all", "the", "DECLARE", "statements", "to", "the", "top", "of", "the", "program", ".", "Return", "a", "fresh", "obejct", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L1002-L1021
[ "def", "percolate_declares", "(", "program", ":", "Program", ")", "->", "Program", ":", "declare_program", "=", "Program", "(", ")", "instrs_program", "=", "Program", "(", ")", "for", "instr", "in", "program", ":", "if", "isinstance", "(", "instr", ",", "D...
ec98e453084b0037d69d8c3245f6822a5422593d
train
validate_protoquil
Ensure that a program is valid ProtoQuil, otherwise raise a ValueError. Protoquil is a subset of Quil which excludes control flow and classical instructions. :param program: The Quil program to validate.
pyquil/quil.py
def validate_protoquil(program: Program) -> None: """ Ensure that a program is valid ProtoQuil, otherwise raise a ValueError. Protoquil is a subset of Quil which excludes control flow and classical instructions. :param program: The Quil program to validate. """ valid_instruction_types = tuple([...
def validate_protoquil(program: Program) -> None: """ Ensure that a program is valid ProtoQuil, otherwise raise a ValueError. Protoquil is a subset of Quil which excludes control flow and classical instructions. :param program: The Quil program to validate. """ valid_instruction_types = tuple([...
[ "Ensure", "that", "a", "program", "is", "valid", "ProtoQuil", "otherwise", "raise", "a", "ValueError", ".", "Protoquil", "is", "a", "subset", "of", "Quil", "which", "excludes", "control", "flow", "and", "classical", "instructions", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L1024-L1035
[ "def", "validate_protoquil", "(", "program", ":", "Program", ")", "->", "None", ":", "valid_instruction_types", "=", "tuple", "(", "[", "Pragma", ",", "Declare", ",", "Halt", ",", "Gate", ",", "Reset", ",", "ResetQubit", ",", "Measurement", "]", ")", "for"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
validate_supported_quil
Ensure that a program is supported Quil which can run on any QPU, otherwise raise a ValueError. We support a global RESET before any gates, and MEASUREs on each qubit after any gates on that qubit. PRAGMAs and DECLAREs are always allowed, and a final HALT instruction is allowed. :param program: The Quil pr...
pyquil/quil.py
def validate_supported_quil(program: Program) -> None: """ Ensure that a program is supported Quil which can run on any QPU, otherwise raise a ValueError. We support a global RESET before any gates, and MEASUREs on each qubit after any gates on that qubit. PRAGMAs and DECLAREs are always allowed, and a ...
def validate_supported_quil(program: Program) -> None: """ Ensure that a program is supported Quil which can run on any QPU, otherwise raise a ValueError. We support a global RESET before any gates, and MEASUREs on each qubit after any gates on that qubit. PRAGMAs and DECLAREs are always allowed, and a ...
[ "Ensure", "that", "a", "program", "is", "supported", "Quil", "which", "can", "run", "on", "any", "QPU", "otherwise", "raise", "a", "ValueError", ".", "We", "support", "a", "global", "RESET", "before", "any", "gates", "and", "MEASUREs", "on", "each", "qubit...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L1038-L1068
[ "def", "validate_supported_quil", "(", "program", ":", "Program", ")", "->", "None", ":", "gates_seen", "=", "False", "measured_qubits", ":", "Set", "[", "int", "]", "=", "set", "(", ")", "for", "i", ",", "instr", "in", "enumerate", "(", "program", ".", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.copy_everything_except_instructions
Copy all the members that live on a Program object. :return: a new Program
pyquil/quil.py
def copy_everything_except_instructions(self): """ Copy all the members that live on a Program object. :return: a new Program """ new_prog = Program() new_prog._defined_gates = self._defined_gates.copy() if self.native_quil_metadata is not None: new_p...
def copy_everything_except_instructions(self): """ Copy all the members that live on a Program object. :return: a new Program """ new_prog = Program() new_prog._defined_gates = self._defined_gates.copy() if self.native_quil_metadata is not None: new_p...
[ "Copy", "all", "the", "members", "that", "live", "on", "a", "Program", "object", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L75-L86
[ "def", "copy_everything_except_instructions", "(", "self", ")", ":", "new_prog", "=", "Program", "(", ")", "new_prog", ".", "_defined_gates", "=", "self", ".", "_defined_gates", ".", "copy", "(", ")", "if", "self", ".", "native_quil_metadata", "is", "not", "No...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.copy
Perform a shallow copy of this program. QuilAtom and AbstractInstruction objects should be treated as immutable to avoid strange behavior when performing a copy. :return: a new Program
pyquil/quil.py
def copy(self): """ Perform a shallow copy of this program. QuilAtom and AbstractInstruction objects should be treated as immutable to avoid strange behavior when performing a copy. :return: a new Program """ new_prog = self.copy_everything_except_instructions()...
def copy(self): """ Perform a shallow copy of this program. QuilAtom and AbstractInstruction objects should be treated as immutable to avoid strange behavior when performing a copy. :return: a new Program """ new_prog = self.copy_everything_except_instructions()...
[ "Perform", "a", "shallow", "copy", "of", "this", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L88-L99
[ "def", "copy", "(", "self", ")", ":", "new_prog", "=", "self", ".", "copy_everything_except_instructions", "(", ")", "new_prog", ".", "_instructions", "=", "self", ".", "_instructions", ".", "copy", "(", ")", "return", "new_prog" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.inst
Mutates the Program object by appending new instructions. This function accepts a number of different valid forms, e.g. >>> p = Program() >>> p.inst(H(0)) # A single instruction >>> p.inst(H(0), H(1)) # Multiple instructions >>> p.inst([H(0), H(1)]) # A list of ...
pyquil/quil.py
def inst(self, *instructions): """ Mutates the Program object by appending new instructions. This function accepts a number of different valid forms, e.g. >>> p = Program() >>> p.inst(H(0)) # A single instruction >>> p.inst(H(0), H(1)) # Multiple instruction...
def inst(self, *instructions): """ Mutates the Program object by appending new instructions. This function accepts a number of different valid forms, e.g. >>> p = Program() >>> p.inst(H(0)) # A single instruction >>> p.inst(H(0), H(1)) # Multiple instruction...
[ "Mutates", "the", "Program", "object", "by", "appending", "new", "instructions", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L118-L192
[ "def", "inst", "(", "self", ",", "*", "instructions", ")", ":", "for", "instruction", "in", "instructions", ":", "if", "isinstance", "(", "instruction", ",", "list", ")", ":", "self", ".", "inst", "(", "*", "instruction", ")", "elif", "isinstance", "(", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.gate
Add a gate to the program. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, i.e., for qubits 0 and 1 the bitstring ``01`` indicates that ...
pyquil/quil.py
def gate(self, name, params, qubits): """ Add a gate to the program. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, i.e...
def gate(self, name, params, qubits): """ Add a gate to the program. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, i.e...
[ "Add", "a", "gate", "to", "the", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L194-L211
[ "def", "gate", "(", "self", ",", "name", ",", "params", ",", "qubits", ")", ":", "return", "self", ".", "inst", "(", "Gate", "(", "name", ",", "params", ",", "[", "unpack_qubit", "(", "q", ")", "for", "q", "in", "qubits", "]", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.defgate
Define a new static gate. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, i.e., for qubits 0 and 1 the bitstring ``01`` indicates that q...
pyquil/quil.py
def defgate(self, name, matrix, parameters=None): """ Define a new static gate. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, ...
def defgate(self, name, matrix, parameters=None): """ Define a new static gate. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, ...
[ "Define", "a", "new", "static", "gate", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L213-L231
[ "def", "defgate", "(", "self", ",", "name", ",", "matrix", ",", "parameters", "=", "None", ")", ":", "return", "self", ".", "inst", "(", "DefGate", "(", "name", ",", "matrix", ",", "parameters", ")", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.define_noisy_gate
Overload a static ideal gate with a noisy one defined in terms of a Kraus map. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where the the bits **are ordered in reverse** by the qubit index, i.e., for...
pyquil/quil.py
def define_noisy_gate(self, name, qubit_indices, kraus_ops): """ Overload a static ideal gate with a noisy one defined in terms of a Kraus map. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where ...
def define_noisy_gate(self, name, qubit_indices, kraus_ops): """ Overload a static ideal gate with a noisy one defined in terms of a Kraus map. .. note:: The matrix elements along each axis are ordered by bitstring. For two qubits the order is ``00, 01, 10, 11``, where ...
[ "Overload", "a", "static", "ideal", "gate", "with", "a", "noisy", "one", "defined", "in", "terms", "of", "a", "Kraus", "map", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L233-L253
[ "def", "define_noisy_gate", "(", "self", ",", "name", ",", "qubit_indices", ",", "kraus_ops", ")", ":", "kraus_ops", "=", "[", "np", ".", "asarray", "(", "k", ",", "dtype", "=", "np", ".", "complex128", ")", "for", "k", "in", "kraus_ops", "]", "_check_...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.define_noisy_readout
For this program define a classical bit flip readout error channel parametrized by ``p00`` and ``p11``. This models the effect of thermal noise that corrupts the readout signal **after** it has interrogated the qubit. :param int|QubitPlaceholder qubit: The qubit with noisy readout. :par...
pyquil/quil.py
def define_noisy_readout(self, qubit, p00, p11): """ For this program define a classical bit flip readout error channel parametrized by ``p00`` and ``p11``. This models the effect of thermal noise that corrupts the readout signal **after** it has interrogated the qubit. :param i...
def define_noisy_readout(self, qubit, p00, p11): """ For this program define a classical bit flip readout error channel parametrized by ``p00`` and ``p11``. This models the effect of thermal noise that corrupts the readout signal **after** it has interrogated the qubit. :param i...
[ "For", "this", "program", "define", "a", "classical", "bit", "flip", "readout", "error", "channel", "parametrized", "by", "p00", "and", "p11", ".", "This", "models", "the", "effect", "of", "thermal", "noise", "that", "corrupts", "the", "readout", "signal", "...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L255-L282
[ "def", "define_noisy_readout", "(", "self", ",", "qubit", ",", "p00", ",", "p11", ")", ":", "if", "not", "0.", "<=", "p00", "<=", "1.", ":", "raise", "ValueError", "(", "\"p00 must be in the interval [0,1].\"", ")", "if", "not", "0.", "<=", "p11", "<=", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.measure_all
Measures many qubits into their specified classical bits, in the order they were entered. If no qubit/register pairs are provided, measure all qubits present in the program into classical addresses of the same index. :param Tuple qubit_reg_pairs: Tuples of qubit indices paired with classical bi...
pyquil/quil.py
def measure_all(self, *qubit_reg_pairs): """ Measures many qubits into their specified classical bits, in the order they were entered. If no qubit/register pairs are provided, measure all qubits present in the program into classical addresses of the same index. :param Tuple qubi...
def measure_all(self, *qubit_reg_pairs): """ Measures many qubits into their specified classical bits, in the order they were entered. If no qubit/register pairs are provided, measure all qubits present in the program into classical addresses of the same index. :param Tuple qubi...
[ "Measures", "many", "qubits", "into", "their", "specified", "classical", "bits", "in", "the", "order", "they", "were", "entered", ".", "If", "no", "qubit", "/", "register", "pairs", "are", "provided", "measure", "all", "qubits", "present", "in", "the", "prog...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L318-L345
[ "def", "measure_all", "(", "self", ",", "*", "qubit_reg_pairs", ")", ":", "if", "qubit_reg_pairs", "==", "(", ")", ":", "qubit_inds", "=", "self", ".", "get_qubits", "(", "indices", "=", "True", ")", "if", "len", "(", "qubit_inds", ")", "==", "0", ":",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.while_do
While a classical register at index classical_reg is 1, loop q_program Equivalent to the following construction: .. code:: WHILE [c]: instr... => LABEL @START JUMP-UNLESS @END [c] instr... JUMP @START ...
pyquil/quil.py
def while_do(self, classical_reg, q_program): """ While a classical register at index classical_reg is 1, loop q_program Equivalent to the following construction: .. code:: WHILE [c]: instr... => LABEL @START JUMP-UNLE...
def while_do(self, classical_reg, q_program): """ While a classical register at index classical_reg is 1, loop q_program Equivalent to the following construction: .. code:: WHILE [c]: instr... => LABEL @START JUMP-UNLE...
[ "While", "a", "classical", "register", "at", "index", "classical_reg", "is", "1", "loop", "q_program" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L347-L376
[ "def", "while_do", "(", "self", ",", "classical_reg", ",", "q_program", ")", ":", "label_start", "=", "LabelPlaceholder", "(", "\"START\"", ")", "label_end", "=", "LabelPlaceholder", "(", "\"END\"", ")", "self", ".", "inst", "(", "JumpTarget", "(", "label_star...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.if_then
If the classical register at index classical reg is 1, run if_program, else run else_program. Equivalent to the following construction: .. code:: IF [c]: instrA... ELSE: instrB... => JUMP-WHEN @THEN [c] ...
pyquil/quil.py
def if_then(self, classical_reg, if_program, else_program=None): """ If the classical register at index classical reg is 1, run if_program, else run else_program. Equivalent to the following construction: .. code:: IF [c]: instrA... ELSE:...
def if_then(self, classical_reg, if_program, else_program=None): """ If the classical register at index classical reg is 1, run if_program, else run else_program. Equivalent to the following construction: .. code:: IF [c]: instrA... ELSE:...
[ "If", "the", "classical", "register", "at", "index", "classical", "reg", "is", "1", "run", "if_program", "else", "run", "else_program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L378-L416
[ "def", "if_then", "(", "self", ",", "classical_reg", ",", "if_program", ",", "else_program", "=", "None", ")", ":", "else_program", "=", "else_program", "if", "else_program", "is", "not", "None", "else", "Program", "(", ")", "label_then", "=", "LabelPlaceholde...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.declare
DECLARE a quil variable This adds the declaration to the current program and returns a MemoryReference to the base (offset = 0) of the declared memory. .. note:: This function returns a MemoryReference and cannot be chained like some of the other Program methods. Consid...
pyquil/quil.py
def declare(self, name, memory_type='BIT', memory_size=1, shared_region=None, offsets=None): """DECLARE a quil variable This adds the declaration to the current program and returns a MemoryReference to the base (offset = 0) of the declared memory. .. note:: This function re...
def declare(self, name, memory_type='BIT', memory_size=1, shared_region=None, offsets=None): """DECLARE a quil variable This adds the declaration to the current program and returns a MemoryReference to the base (offset = 0) of the declared memory. .. note:: This function re...
[ "DECLARE", "a", "quil", "variable" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L429-L458
[ "def", "declare", "(", "self", ",", "name", ",", "memory_type", "=", "'BIT'", ",", "memory_size", "=", "1", ",", "shared_region", "=", "None", ",", "offsets", "=", "None", ")", ":", "self", ".", "inst", "(", "Declare", "(", "name", "=", "name", ",", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program._out
Converts the Quil program to a readable string. :param allow_placeholders: Whether to complain if the program contains placeholders.
pyquil/quil.py
def _out(self, allow_placeholders): """ Converts the Quil program to a readable string. :param allow_placeholders: Whether to complain if the program contains placeholders. """ return '\n'.join(itertools.chain( (dg.out() for dg in self._defined_gates), (i...
def _out(self, allow_placeholders): """ Converts the Quil program to a readable string. :param allow_placeholders: Whether to complain if the program contains placeholders. """ return '\n'.join(itertools.chain( (dg.out() for dg in self._defined_gates), (i...
[ "Converts", "the", "Quil", "program", "to", "a", "readable", "string", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L472-L482
[ "def", "_out", "(", "self", ",", "allow_placeholders", ")", ":", "return", "'\\n'", ".", "join", "(", "itertools", ".", "chain", "(", "(", "dg", ".", "out", "(", ")", "for", "dg", "in", "self", ".", "_defined_gates", ")", ",", "(", "instr", ".", "o...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.get_qubits
Returns all of the qubit indices used in this program, including gate applications and allocated qubits. e.g. >>> p = Program() >>> p.inst(("H", 1)) >>> p.get_qubits() {1} >>> q = p.alloc() >>> p.inst(H(q)) >>> len(p.get_qubits...
pyquil/quil.py
def get_qubits(self, indices=True): """ Returns all of the qubit indices used in this program, including gate applications and allocated qubits. e.g. >>> p = Program() >>> p.inst(("H", 1)) >>> p.get_qubits() {1} >>> q = p.alloc() ...
def get_qubits(self, indices=True): """ Returns all of the qubit indices used in this program, including gate applications and allocated qubits. e.g. >>> p = Program() >>> p.inst(("H", 1)) >>> p.get_qubits() {1} >>> q = p.alloc() ...
[ "Returns", "all", "of", "the", "qubit", "indices", "used", "in", "this", "program", "including", "gate", "applications", "and", "allocated", "qubits", ".", "e", ".", "g", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L494-L517
[ "def", "get_qubits", "(", "self", ",", "indices", "=", "True", ")", ":", "qubits", "=", "set", "(", ")", "for", "instr", "in", "self", ".", "instructions", ":", "if", "isinstance", "(", "instr", ",", "(", "Gate", ",", "Measurement", ")", ")", ":", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program.dagger
Creates the conjugate transpose of the Quil program. The program must not contain any irreversible actions (measurement, control flow, qubit allocation). :return: The Quil program's inverse :rtype: Program
pyquil/quil.py
def dagger(self, inv_dict=None, suffix="-INV"): """ Creates the conjugate transpose of the Quil program. The program must not contain any irreversible actions (measurement, control flow, qubit allocation). :return: The Quil program's inverse :rtype: Program """ ...
def dagger(self, inv_dict=None, suffix="-INV"): """ Creates the conjugate transpose of the Quil program. The program must not contain any irreversible actions (measurement, control flow, qubit allocation). :return: The Quil program's inverse :rtype: Program """ ...
[ "Creates", "the", "conjugate", "transpose", "of", "the", "Quil", "program", ".", "The", "program", "must", "not", "contain", "any", "irreversible", "actions", "(", "measurement", "control", "flow", "qubit", "allocation", ")", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L558-L597
[ "def", "dagger", "(", "self", ",", "inv_dict", "=", "None", ",", "suffix", "=", "\"-INV\"", ")", ":", "if", "not", "self", ".", "is_protoquil", "(", ")", ":", "raise", "ValueError", "(", "\"Program must be valid Protoquil\"", ")", "daggered", "=", "Program",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
Program._synthesize
Assigns all placeholder labels to actual values and implicitly declares the ``ro`` register for backwards compatibility. Changed in 1.9: Either all qubits must be defined or all undefined. If qubits are undefined, this method will not help you. You must explicitly call `address_qubits` ...
pyquil/quil.py
def _synthesize(self): """ Assigns all placeholder labels to actual values and implicitly declares the ``ro`` register for backwards compatibility. Changed in 1.9: Either all qubits must be defined or all undefined. If qubits are undefined, this method will not help you. You mus...
def _synthesize(self): """ Assigns all placeholder labels to actual values and implicitly declares the ``ro`` register for backwards compatibility. Changed in 1.9: Either all qubits must be defined or all undefined. If qubits are undefined, this method will not help you. You mus...
[ "Assigns", "all", "placeholder", "labels", "to", "actual", "values", "and", "implicitly", "declares", "the", "ro", "register", "for", "backwards", "compatibility", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quil.py#L599-L619
[ "def", "_synthesize", "(", "self", ")", ":", "self", ".", "_synthesized_instructions", "=", "instantiate_labels", "(", "self", ".", "_instructions", ")", "self", ".", "_synthesized_instructions", "=", "implicitly_declare_ro", "(", "self", ".", "_synthesized_instructio...
ec98e453084b0037d69d8c3245f6822a5422593d
train
pyquil_protect
A decorator that sets up an error context, captures errors, and tears down the context.
pyquil/api/_error_reporting.py
def pyquil_protect(func, log_filename="pyquil_error.log"): """ A decorator that sets up an error context, captures errors, and tears down the context. """ def pyquil_protect_wrapper(*args, **kwargs): global global_error_context old_error_context = global_error_context global_er...
def pyquil_protect(func, log_filename="pyquil_error.log"): """ A decorator that sets up an error context, captures errors, and tears down the context. """ def pyquil_protect_wrapper(*args, **kwargs): global global_error_context old_error_context = global_error_context global_er...
[ "A", "decorator", "that", "sets", "up", "an", "error", "context", "captures", "errors", "and", "tears", "down", "the", "context", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_error_reporting.py#L192-L213
[ "def", "pyquil_protect", "(", "func", ",", "log_filename", "=", "\"pyquil_error.log\"", ")", ":", "def", "pyquil_protect_wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "global", "global_error_context", "old_error_context", "=", "global_error_context"...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_record_call
A decorator that logs a call into the global error context. This is probably for internal use only.
pyquil/api/_error_reporting.py
def _record_call(func): """ A decorator that logs a call into the global error context. This is probably for internal use only. """ @wraps(func) def wrapper(*args, **kwargs): global global_error_context # log a call as about to take place if global_error_context is not...
def _record_call(func): """ A decorator that logs a call into the global error context. This is probably for internal use only. """ @wraps(func) def wrapper(*args, **kwargs): global global_error_context # log a call as about to take place if global_error_context is not...
[ "A", "decorator", "that", "logs", "a", "call", "into", "the", "global", "error", "context", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_error_reporting.py#L216-L249
[ "def", "_record_call", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "global", "global_error_context", "# log a call as about to take place", "if", "global_error_context", "is", "n...
ec98e453084b0037d69d8c3245f6822a5422593d
train
ErrorContext.generate_report
Handle an error generated in a routine decorated with the pyQuil error handler. :param exception: Exception object that generated this error. :param trace: inspect.trace object from the frame that caught the error. :return: ErrorReport object
pyquil/api/_error_reporting.py
def generate_report(self, exception, trace): """ Handle an error generated in a routine decorated with the pyQuil error handler. :param exception: Exception object that generated this error. :param trace: inspect.trace object from the frame that caught the error. :return: ErrorR...
def generate_report(self, exception, trace): """ Handle an error generated in a routine decorated with the pyQuil error handler. :param exception: Exception object that generated this error. :param trace: inspect.trace object from the frame that caught the error. :return: ErrorR...
[ "Handle", "an", "error", "generated", "in", "a", "routine", "decorated", "with", "the", "pyQuil", "error", "handler", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_error_reporting.py#L143-L166
[ "def", "generate_report", "(", "self", ",", "exception", ",", "trace", ")", ":", "stack_trace", "=", "[", "StacktraceFrame", "(", "name", "=", "item", ".", "function", ",", "filename", "=", "item", ".", "filename", ",", "line_number", "=", "item", ".", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
ucc_circuit
Implements exp(-i theta X_{0}Y_{1}) :param theta: rotation parameter :return: pyquil.Program
examples/1.3_vqe_demo.py
def ucc_circuit(theta): """ Implements exp(-i theta X_{0}Y_{1}) :param theta: rotation parameter :return: pyquil.Program """ generator = sX(0) * sY(1) initial_prog = Program().inst(X(1), X(0)) # compiled program program = initial_prog + exponentiate(float(theta) * generator) ...
def ucc_circuit(theta): """ Implements exp(-i theta X_{0}Y_{1}) :param theta: rotation parameter :return: pyquil.Program """ generator = sX(0) * sY(1) initial_prog = Program().inst(X(1), X(0)) # compiled program program = initial_prog + exponentiate(float(theta) * generator) ...
[ "Implements" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/1.3_vqe_demo.py#L46-L60
[ "def", "ucc_circuit", "(", "theta", ")", ":", "generator", "=", "sX", "(", "0", ")", "*", "sY", "(", "1", ")", "initial_prog", "=", "Program", "(", ")", ".", "inst", "(", "X", "(", "1", ")", ",", "X", "(", "0", ")", ")", "# compiled program", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
objective_fun
Evaluate the Hamiltonian bny operator averaging :param theta: :param hamiltonian: :return:
examples/1.3_vqe_demo.py
def objective_fun(theta, hamiltonian=None, quantum_resource=QVMConnection(sync_endpoint='http://localhost:5000')): """ Evaluate the Hamiltonian bny operator averaging :param theta: :param hamiltonian: :return: """ if hamiltonian is None: # Hamiltonian is Identity ...
def objective_fun(theta, hamiltonian=None, quantum_resource=QVMConnection(sync_endpoint='http://localhost:5000')): """ Evaluate the Hamiltonian bny operator averaging :param theta: :param hamiltonian: :return: """ if hamiltonian is None: # Hamiltonian is Identity ...
[ "Evaluate", "the", "Hamiltonian", "bny", "operator", "averaging" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/examples/1.3_vqe_demo.py#L63-L88
[ "def", "objective_fun", "(", "theta", ",", "hamiltonian", "=", "None", ",", "quantum_resource", "=", "QVMConnection", "(", "sync_endpoint", "=", "'http://localhost:5000'", ")", ")", ":", "if", "hamiltonian", "is", "None", ":", "# Hamiltonian is Identity", "return", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_make_ram_program
Check that this program is a series of quantum gates with terminal MEASURE instructions; pop MEASURE instructions. :param program: The program :return: A new program with MEASURE instructions removed.
pyquil/pyqvm.py
def _make_ram_program(program): """ Check that this program is a series of quantum gates with terminal MEASURE instructions; pop MEASURE instructions. :param program: The program :return: A new program with MEASURE instructions removed. """ new_prog = program.copy_everything_except_instruct...
def _make_ram_program(program): """ Check that this program is a series of quantum gates with terminal MEASURE instructions; pop MEASURE instructions. :param program: The program :return: A new program with MEASURE instructions removed. """ new_prog = program.copy_everything_except_instruct...
[ "Check", "that", "this", "program", "is", "a", "series", "of", "quantum", "gates", "with", "terminal", "MEASURE", "instructions", ";", "pop", "MEASURE", "instructions", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/pyqvm.py#L147-L198
[ "def", "_make_ram_program", "(", "program", ")", ":", "new_prog", "=", "program", ".", "copy_everything_except_instructions", "(", ")", "last_qubit_operation", "=", "{", "}", "times_qubit_measured", "=", "defaultdict", "(", "lambda", ":", "0", ")", "ro_size", "=",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
AbstractQuantumSimulator.do_program
Perform a sequence of gates contained within a program. :param program: The program :return: self
pyquil/pyqvm.py
def do_program(self, program: Program) -> 'AbstractQuantumSimulator': """ Perform a sequence of gates contained within a program. :param program: The program :return: self """ for gate in program: if not isinstance(gate, Gate): raise ValueErro...
def do_program(self, program: Program) -> 'AbstractQuantumSimulator': """ Perform a sequence of gates contained within a program. :param program: The program :return: self """ for gate in program: if not isinstance(gate, Gate): raise ValueErro...
[ "Perform", "a", "sequence", "of", "gates", "contained", "within", "a", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/pyqvm.py#L81-L92
[ "def", "do_program", "(", "self", ",", "program", ":", "Program", ")", "->", "'AbstractQuantumSimulator'", ":", "for", "gate", "in", "program", ":", "if", "not", "isinstance", "(", "gate", ",", "Gate", ")", ":", "raise", "ValueError", "(", "\"Can only comput...
ec98e453084b0037d69d8c3245f6822a5422593d
train
PyQVM.find_label
Helper function that iterates over the program and looks for a JumpTarget that has a Label matching the input label. :param label: Label object to search for in program :return: Program index where ``label`` is found
pyquil/pyqvm.py
def find_label(self, label: Label): """ Helper function that iterates over the program and looks for a JumpTarget that has a Label matching the input label. :param label: Label object to search for in program :return: Program index where ``label`` is found """ fo...
def find_label(self, label: Label): """ Helper function that iterates over the program and looks for a JumpTarget that has a Label matching the input label. :param label: Label object to search for in program :return: Program index where ``label`` is found """ fo...
[ "Helper", "function", "that", "iterates", "over", "the", "program", "and", "looks", "for", "a", "JumpTarget", "that", "has", "a", "Label", "matching", "the", "input", "label", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/pyqvm.py#L319-L333
[ "def", "find_label", "(", "self", ",", "label", ":", "Label", ")", ":", "for", "index", ",", "action", "in", "enumerate", "(", "self", ".", "program", ")", ":", "if", "isinstance", "(", "action", ",", "JumpTarget", ")", ":", "if", "label", "==", "act...
ec98e453084b0037d69d8c3245f6822a5422593d
train
PyQVM.transition
Implements a QAM-like transition. This function assumes ``program`` and ``program_counter`` instance variables are set appropriately, and that the wavefunction simulator and classical memory ``ram`` instance variables are in the desired QAM input state. :return: whether the QAM should ...
pyquil/pyqvm.py
def transition(self): """ Implements a QAM-like transition. This function assumes ``program`` and ``program_counter`` instance variables are set appropriately, and that the wavefunction simulator and classical memory ``ram`` instance variables are in the desired QAM input state....
def transition(self): """ Implements a QAM-like transition. This function assumes ``program`` and ``program_counter`` instance variables are set appropriately, and that the wavefunction simulator and classical memory ``ram`` instance variables are in the desired QAM input state....
[ "Implements", "a", "QAM", "-", "like", "transition", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/pyqvm.py#L335-L500
[ "def", "transition", "(", "self", ")", ":", "instruction", "=", "self", ".", "program", "[", "self", ".", "program_counter", "]", "if", "isinstance", "(", "instruction", ",", "Gate", ")", ":", "if", "instruction", ".", "name", "in", "self", ".", "defined...
ec98e453084b0037d69d8c3245f6822a5422593d
train
PyQVM.execute
Execute a program on the QVM. Note that the QAM is stateful. Subsequent calls to :py:func:`execute` will not automatically reset the wavefunction or the classical RAM. If this is desired, consider starting your program with ``RESET``. :return: ``self`` to support method chaining.
pyquil/pyqvm.py
def execute(self, program: Program): """ Execute a program on the QVM. Note that the QAM is stateful. Subsequent calls to :py:func:`execute` will not automatically reset the wavefunction or the classical RAM. If this is desired, consider starting your program with ``RESET``. ...
def execute(self, program: Program): """ Execute a program on the QVM. Note that the QAM is stateful. Subsequent calls to :py:func:`execute` will not automatically reset the wavefunction or the classical RAM. If this is desired, consider starting your program with ``RESET``. ...
[ "Execute", "a", "program", "on", "the", "QVM", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/pyqvm.py#L502-L526
[ "def", "execute", "(", "self", ",", "program", ":", "Program", ")", ":", "# TODO: why are DEFGATEs not just included in the list of instructions?", "for", "dg", "in", "program", ".", "defined_gates", ":", "if", "dg", ".", "parameters", "is", "not", "None", ":", "r...
ec98e453084b0037d69d8c3245f6822a5422593d
train
get_benchmarker
Retrieve an instance of the appropriate AbstractBenchmarker subclass for a given endpoint. :param endpoint: Benchmarking sequence server address. Defaults to the setting in the user's pyQuil config. :param timeout: Number of seconds to wait before giving up on a call. :return: Instance...
pyquil/api/_benchmark.py
def get_benchmarker(endpoint: str = None, timeout: float = 10): """ Retrieve an instance of the appropriate AbstractBenchmarker subclass for a given endpoint. :param endpoint: Benchmarking sequence server address. Defaults to the setting in the user's pyQuil config. :param timeout:...
def get_benchmarker(endpoint: str = None, timeout: float = 10): """ Retrieve an instance of the appropriate AbstractBenchmarker subclass for a given endpoint. :param endpoint: Benchmarking sequence server address. Defaults to the setting in the user's pyQuil config. :param timeout:...
[ "Retrieve", "an", "instance", "of", "the", "appropriate", "AbstractBenchmarker", "subclass", "for", "a", "given", "endpoint", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_benchmark.py#L144-L157
[ "def", "get_benchmarker", "(", "endpoint", ":", "str", "=", "None", ",", "timeout", ":", "float", "=", "10", ")", ":", "if", "endpoint", "is", "None", ":", "config", "=", "PyquilConfig", "(", ")", "endpoint", "=", "config", ".", "quilc_url", "return", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
BenchmarkConnection.apply_clifford_to_pauli
r""" Given a circuit that consists only of elements of the Clifford group, return its action on a PauliTerm. In particular, for Clifford C, and Pauli P, this returns the PauliTerm representing CPC^{\dagger}. :param Program clifford: A Program that consists only of Clifford oper...
pyquil/api/_benchmark.py
def apply_clifford_to_pauli(self, clifford, pauli_in): r""" Given a circuit that consists only of elements of the Clifford group, return its action on a PauliTerm. In particular, for Clifford C, and Pauli P, this returns the PauliTerm representing CPC^{\dagger}. :param ...
def apply_clifford_to_pauli(self, clifford, pauli_in): r""" Given a circuit that consists only of elements of the Clifford group, return its action on a PauliTerm. In particular, for Clifford C, and Pauli P, this returns the PauliTerm representing CPC^{\dagger}. :param ...
[ "r", "Given", "a", "circuit", "that", "consists", "only", "of", "elements", "of", "the", "Clifford", "group", "return", "its", "action", "on", "a", "PauliTerm", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_benchmark.py#L45-L79
[ "def", "apply_clifford_to_pauli", "(", "self", ",", "clifford", ",", "pauli_in", ")", ":", "# do nothing if `pauli_in` is the identity", "if", "is_identity", "(", "pauli_in", ")", ":", "return", "pauli_in", "indices_and_terms", "=", "list", "(", "zip", "(", "*", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
BenchmarkConnection.generate_rb_sequence
Construct a randomized benchmarking experiment on the given qubits, decomposing into gateset. If interleaver is not provided, the returned sequence will have the form C_1 C_2 ... C_(depth-1) C_inv , where each C is a Clifford element drawn from gateset, C_{< depth} are randomly selected, ...
pyquil/api/_benchmark.py
def generate_rb_sequence(self, depth, gateset, seed=None, interleaver=None): """ Construct a randomized benchmarking experiment on the given qubits, decomposing into gateset. If interleaver is not provided, the returned sequence will have the form C_1 C_2 ... C_(depth-1) C_inv , ...
def generate_rb_sequence(self, depth, gateset, seed=None, interleaver=None): """ Construct a randomized benchmarking experiment on the given qubits, decomposing into gateset. If interleaver is not provided, the returned sequence will have the form C_1 C_2 ... C_(depth-1) C_inv , ...
[ "Construct", "a", "randomized", "benchmarking", "experiment", "on", "the", "given", "qubits", "decomposing", "into", "gateset", ".", "If", "interleaver", "is", "not", "provided", "the", "returned", "sequence", "will", "have", "the", "form" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/api/_benchmark.py#L82-L141
[ "def", "generate_rb_sequence", "(", "self", ",", "depth", ",", "gateset", ",", "seed", "=", "None", ",", "interleaver", "=", "None", ")", ":", "# Support QubitPlaceholders: we temporarily index to arbitrary integers.", "# `generate_rb_sequence` handles mapping back to the origi...
ec98e453084b0037d69d8c3245f6822a5422593d
train
unpack_qubit
Get a qubit from an object. :param qubit: An int or Qubit. :return: A Qubit instance
pyquil/quilatom.py
def unpack_qubit(qubit): """ Get a qubit from an object. :param qubit: An int or Qubit. :return: A Qubit instance """ if isinstance(qubit, integer_types): return Qubit(qubit) elif isinstance(qubit, Qubit): return qubit elif isinstance(qubit, QubitPlaceholder): re...
def unpack_qubit(qubit): """ Get a qubit from an object. :param qubit: An int or Qubit. :return: A Qubit instance """ if isinstance(qubit, integer_types): return Qubit(qubit) elif isinstance(qubit, Qubit): return qubit elif isinstance(qubit, QubitPlaceholder): re...
[ "Get", "a", "qubit", "from", "an", "object", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L107-L121
[ "def", "unpack_qubit", "(", "qubit", ")", ":", "if", "isinstance", "(", "qubit", ",", "integer_types", ")", ":", "return", "Qubit", "(", "qubit", ")", "elif", "isinstance", "(", "qubit", ",", "Qubit", ")", ":", "return", "qubit", "elif", "isinstance", "(...
ec98e453084b0037d69d8c3245f6822a5422593d
train
unpack_classical_reg
Get the address for a classical register. :param c: A list of length 2, a pair, a string (to be interpreted as name[0]), or a MemoryReference. :return: The address as a MemoryReference.
pyquil/quilatom.py
def unpack_classical_reg(c): """ Get the address for a classical register. :param c: A list of length 2, a pair, a string (to be interpreted as name[0]), or a MemoryReference. :return: The address as a MemoryReference. """ if isinstance(c, list) or isinstance(c, tuple): if len(c) > 2 or...
def unpack_classical_reg(c): """ Get the address for a classical register. :param c: A list of length 2, a pair, a string (to be interpreted as name[0]), or a MemoryReference. :return: The address as a MemoryReference. """ if isinstance(c, list) or isinstance(c, tuple): if len(c) > 2 or...
[ "Get", "the", "address", "for", "a", "classical", "register", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L124-L146
[ "def", "unpack_classical_reg", "(", "c", ")", ":", "if", "isinstance", "(", "c", ",", "list", ")", "or", "isinstance", "(", "c", ",", "tuple", ")", ":", "if", "len", "(", "c", ")", ">", "2", "or", "len", "(", "c", ")", "==", "0", ":", "raise", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
format_parameter
Formats a particular parameter. Essentially the same as built-in formatting except using 'i' instead of 'j' for the imaginary number. :param element: {int, float, long, complex, Parameter} Formats a parameter for Quil output.
pyquil/quilatom.py
def format_parameter(element): """ Formats a particular parameter. Essentially the same as built-in formatting except using 'i' instead of 'j' for the imaginary number. :param element: {int, float, long, complex, Parameter} Formats a parameter for Quil output. """ if isinstance(element, integer...
def format_parameter(element): """ Formats a particular parameter. Essentially the same as built-in formatting except using 'i' instead of 'j' for the imaginary number. :param element: {int, float, long, complex, Parameter} Formats a parameter for Quil output. """ if isinstance(element, integer...
[ "Formats", "a", "particular", "parameter", ".", "Essentially", "the", "same", "as", "built", "-", "in", "formatting", "except", "using", "i", "instead", "of", "j", "for", "the", "imaginary", "number", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L195-L236
[ "def", "format_parameter", "(", "element", ")", ":", "if", "isinstance", "(", "element", ",", "integer_types", ")", "or", "isinstance", "(", "element", ",", "np", ".", "int_", ")", ":", "return", "repr", "(", "element", ")", "elif", "isinstance", "(", "e...
ec98e453084b0037d69d8c3245f6822a5422593d
train
substitute_array
Apply ``substitute`` to all elements of an array ``a`` and return the resulting array. :param Union[np.array,List] a: The expression array to substitute. :param Dict[Parameter,Union[int,float]] d: Numerical substitutions for parameters. :return: An array of partially substituted Expressions or numbers. ...
pyquil/quilatom.py
def substitute_array(a, d): """ Apply ``substitute`` to all elements of an array ``a`` and return the resulting array. :param Union[np.array,List] a: The expression array to substitute. :param Dict[Parameter,Union[int,float]] d: Numerical substitutions for parameters. :return: An array of partially...
def substitute_array(a, d): """ Apply ``substitute`` to all elements of an array ``a`` and return the resulting array. :param Union[np.array,List] a: The expression array to substitute. :param Dict[Parameter,Union[int,float]] d: Numerical substitutions for parameters. :return: An array of partially...
[ "Apply", "substitute", "to", "all", "elements", "of", "an", "array", "a", "and", "return", "the", "resulting", "array", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L311-L321
[ "def", "substitute_array", "(", "a", ",", "d", ")", ":", "a", "=", "np", ".", "asarray", "(", "a", ",", "order", "=", "\"C\"", ")", "return", "np", ".", "array", "(", "[", "substitute", "(", "v", ",", "d", ")", "for", "v", "in", "a", ".", "fl...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_expression_to_string
Recursively converts an expression to a string taking into account precedence and associativity for placing parenthesis :param Expression expression: expression involving parameters :return: string such as '%x*(%y-4)' :rtype: str
pyquil/quilatom.py
def _expression_to_string(expression): """ Recursively converts an expression to a string taking into account precedence and associativity for placing parenthesis :param Expression expression: expression involving parameters :return: string such as '%x*(%y-4)' :rtype: str """ if isinsta...
def _expression_to_string(expression): """ Recursively converts an expression to a string taking into account precedence and associativity for placing parenthesis :param Expression expression: expression involving parameters :return: string such as '%x*(%y-4)' :rtype: str """ if isinsta...
[ "Recursively", "converts", "an", "expression", "to", "a", "string", "taking", "into", "account", "precedence", "and", "associativity", "for", "placing", "parenthesis" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L483-L513
[ "def", "_expression_to_string", "(", "expression", ")", ":", "if", "isinstance", "(", "expression", ",", "BinaryExp", ")", ":", "left", "=", "_expression_to_string", "(", "expression", ".", "op1", ")", "if", "isinstance", "(", "expression", ".", "op1", ",", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_contained_parameters
Determine which parameters are contained in this expression. :param Expression expression: expression involving parameters :return: set of parameters contained in this expression :rtype: set
pyquil/quilatom.py
def _contained_parameters(expression): """ Determine which parameters are contained in this expression. :param Expression expression: expression involving parameters :return: set of parameters contained in this expression :rtype: set """ if isinstance(expression, BinaryExp): return ...
def _contained_parameters(expression): """ Determine which parameters are contained in this expression. :param Expression expression: expression involving parameters :return: set of parameters contained in this expression :rtype: set """ if isinstance(expression, BinaryExp): return ...
[ "Determine", "which", "parameters", "are", "contained", "in", "this", "expression", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L516-L531
[ "def", "_contained_parameters", "(", "expression", ")", ":", "if", "isinstance", "(", "expression", ",", "BinaryExp", ")", ":", "return", "_contained_parameters", "(", "expression", ".", "op1", ")", "|", "_contained_parameters", "(", "expression", ".", "op2", ")...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_check_for_pi
Check to see if there exists a rational number r = p/q in reduced form for which the difference between element/np.pi and r is small and q <= 8. :param element: float :return element: pretty print string if true, else standard representation.
pyquil/quilatom.py
def _check_for_pi(element): """ Check to see if there exists a rational number r = p/q in reduced form for which the difference between element/np.pi and r is small and q <= 8. :param element: float :return element: pretty print string if true, else standard representation. """ frac = F...
def _check_for_pi(element): """ Check to see if there exists a rational number r = p/q in reduced form for which the difference between element/np.pi and r is small and q <= 8. :param element: float :return element: pretty print string if true, else standard representation. """ frac = F...
[ "Check", "to", "see", "if", "there", "exists", "a", "rational", "number", "r", "=", "p", "/", "q", "in", "reduced", "form", "for", "which", "the", "difference", "between", "element", "/", "np", ".", "pi", "and", "r", "is", "small", "and", "q", "<", ...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/quilatom.py#L534-L558
[ "def", "_check_for_pi", "(", "element", ")", ":", "frac", "=", "Fraction", "(", "element", "/", "np", ".", "pi", ")", ".", "limit_denominator", "(", "8", ")", "num", ",", "den", "=", "frac", ".", "numerator", ",", "frac", ".", "denominator", "sign", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
add_noise_to_program
Add generic damping and dephasing noise to a program. .. warning:: This function is deprecated. Please use :py:func:`add_decoherence_noise` instead. :param prog: A pyquil program consisting of I, RZ, CZ, and RX(+-pi/2) instructions :param Union[Dict[int,float],float] T1: The T1 amplitude damping ...
pyquil/kraus.py
def add_noise_to_program(prog, T1=30e-6, T2=30e-6, gate_time_1q=50e-9, gate_time_2q=150e-09, ro_fidelity=0.95): """ Add generic damping and dephasing noise to a program. .. warning:: This function is deprecated. Please use :py:func:`add_decoherence_noise` instead. :pa...
def add_noise_to_program(prog, T1=30e-6, T2=30e-6, gate_time_1q=50e-9, gate_time_2q=150e-09, ro_fidelity=0.95): """ Add generic damping and dephasing noise to a program. .. warning:: This function is deprecated. Please use :py:func:`add_decoherence_noise` instead. :pa...
[ "Add", "generic", "damping", "and", "dephasing", "noise", "to", "a", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/kraus.py#L34-L60
[ "def", "add_noise_to_program", "(", "prog", ",", "T1", "=", "30e-6", ",", "T2", "=", "30e-6", ",", "gate_time_1q", "=", "50e-9", ",", "gate_time_2q", "=", "150e-09", ",", "ro_fidelity", "=", "0.95", ")", ":", "warnings", ".", "warn", "(", "\"pyquil.kraus.a...
ec98e453084b0037d69d8c3245f6822a5422593d
train
all_bitstrings
All bitstrings in lexicographical order as a 2d np.ndarray. This should be the same as ``np.array(list(itertools.product([0,1], repeat=n_bits)))`` but faster.
pyquil/unitary_tools.py
def all_bitstrings(n_bits): """All bitstrings in lexicographical order as a 2d np.ndarray. This should be the same as ``np.array(list(itertools.product([0,1], repeat=n_bits)))`` but faster. """ n_bitstrings = 2 ** n_bits out = np.zeros(shape=(n_bitstrings, n_bits), dtype=np.int8) tf = np.a...
def all_bitstrings(n_bits): """All bitstrings in lexicographical order as a 2d np.ndarray. This should be the same as ``np.array(list(itertools.product([0,1], repeat=n_bits)))`` but faster. """ n_bitstrings = 2 ** n_bits out = np.zeros(shape=(n_bitstrings, n_bits), dtype=np.int8) tf = np.a...
[ "All", "bitstrings", "in", "lexicographical", "order", "as", "a", "2d", "np", ".", "ndarray", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L26-L45
[ "def", "all_bitstrings", "(", "n_bits", ")", ":", "n_bitstrings", "=", "2", "**", "n_bits", "out", "=", "np", ".", "zeros", "(", "shape", "=", "(", "n_bitstrings", ",", "n_bits", ")", ",", "dtype", "=", "np", ".", "int8", ")", "tf", "=", "np", ".",...
ec98e453084b0037d69d8c3245f6822a5422593d
train
qubit_adjacent_lifted_gate
Lifts input k-qubit gate on adjacent qubits starting from qubit i to complete Hilbert space of dimension 2 ** num_qubits. Ex: 1-qubit gate, lifts from qubit i Ex: 2-qubit gate, lifts from qubits (i+1, i) Ex: 3-qubit gate, lifts from qubits (i+2, i+1, i), operating in that order In general, this ta...
pyquil/unitary_tools.py
def qubit_adjacent_lifted_gate(i, matrix, n_qubits): """ Lifts input k-qubit gate on adjacent qubits starting from qubit i to complete Hilbert space of dimension 2 ** num_qubits. Ex: 1-qubit gate, lifts from qubit i Ex: 2-qubit gate, lifts from qubits (i+1, i) Ex: 3-qubit gate, lifts from qubit...
def qubit_adjacent_lifted_gate(i, matrix, n_qubits): """ Lifts input k-qubit gate on adjacent qubits starting from qubit i to complete Hilbert space of dimension 2 ** num_qubits. Ex: 1-qubit gate, lifts from qubit i Ex: 2-qubit gate, lifts from qubits (i+1, i) Ex: 3-qubit gate, lifts from qubit...
[ "Lifts", "input", "k", "-", "qubit", "gate", "on", "adjacent", "qubits", "starting", "from", "qubit", "i", "to", "complete", "Hilbert", "space", "of", "dimension", "2", "**", "num_qubits", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L48-L92
[ "def", "qubit_adjacent_lifted_gate", "(", "i", ",", "matrix", ",", "n_qubits", ")", ":", "n_rows", ",", "n_cols", "=", "matrix", ".", "shape", "assert", "n_rows", "==", "n_cols", ",", "'Matrix must be square'", "gate_size", "=", "np", ".", "log2", "(", "n_ro...
ec98e453084b0037d69d8c3245f6822a5422593d
train
two_swap_helper
Generate the permutation matrix that permutes two single-particle Hilbert spaces into adjacent positions. ALWAYS swaps j TO k. Recall that Hilbert spaces are ordered in decreasing qubit index order. Hence, j > k implies that j is to the left of k. End results: j == k: nothing happens j...
pyquil/unitary_tools.py
def two_swap_helper(j, k, num_qubits, qubit_map): """ Generate the permutation matrix that permutes two single-particle Hilbert spaces into adjacent positions. ALWAYS swaps j TO k. Recall that Hilbert spaces are ordered in decreasing qubit index order. Hence, j > k implies that j is to the left of ...
def two_swap_helper(j, k, num_qubits, qubit_map): """ Generate the permutation matrix that permutes two single-particle Hilbert spaces into adjacent positions. ALWAYS swaps j TO k. Recall that Hilbert spaces are ordered in decreasing qubit index order. Hence, j > k implies that j is to the left of ...
[ "Generate", "the", "permutation", "matrix", "that", "permutes", "two", "single", "-", "particle", "Hilbert", "spaces", "into", "adjacent", "positions", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L95-L140
[ "def", "two_swap_helper", "(", "j", ",", "k", ",", "num_qubits", ",", "qubit_map", ")", ":", "if", "not", "(", "0", "<=", "j", "<", "num_qubits", "and", "0", "<=", "k", "<", "num_qubits", ")", ":", "raise", "ValueError", "(", "\"Permutation SWAP index no...
ec98e453084b0037d69d8c3245f6822a5422593d
train
permutation_arbitrary
Generate the permutation matrix that permutes an arbitrary number of single-particle Hilbert spaces into adjacent positions. Transposes the qubit indices in the order they are passed to a contiguous region in the complete Hilbert space, in increasing qubit index order (preserving the order they are pas...
pyquil/unitary_tools.py
def permutation_arbitrary(qubit_inds, n_qubits): """ Generate the permutation matrix that permutes an arbitrary number of single-particle Hilbert spaces into adjacent positions. Transposes the qubit indices in the order they are passed to a contiguous region in the complete Hilbert space, in increa...
def permutation_arbitrary(qubit_inds, n_qubits): """ Generate the permutation matrix that permutes an arbitrary number of single-particle Hilbert spaces into adjacent positions. Transposes the qubit indices in the order they are passed to a contiguous region in the complete Hilbert space, in increa...
[ "Generate", "the", "permutation", "matrix", "that", "permutes", "an", "arbitrary", "number", "of", "single", "-", "particle", "Hilbert", "spaces", "into", "adjacent", "positions", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L143-L226
[ "def", "permutation_arbitrary", "(", "qubit_inds", ",", "n_qubits", ")", ":", "# Begin construction of permutation", "perm", "=", "np", ".", "eye", "(", "2", "**", "n_qubits", ",", "dtype", "=", "np", ".", "complex128", ")", "# First, sort the list and find the medi...
ec98e453084b0037d69d8c3245f6822a5422593d
train
lifted_gate_matrix
Lift a unitary matrix to act on the specified qubits in a full ``n_qubits``-qubit Hilbert space. For 1-qubit gates, this is easy and can be achieved with appropriate kronning of identity matrices. For 2-qubit gates acting on adjacent qubit indices, it is also easy. However, for a multiqubit gate acting...
pyquil/unitary_tools.py
def lifted_gate_matrix(matrix: np.ndarray, qubit_inds: List[int], n_qubits: int): """ Lift a unitary matrix to act on the specified qubits in a full ``n_qubits``-qubit Hilbert space. For 1-qubit gates, this is easy and can be achieved with appropriate kronning of identity matrices. For 2-qubit gate...
def lifted_gate_matrix(matrix: np.ndarray, qubit_inds: List[int], n_qubits: int): """ Lift a unitary matrix to act on the specified qubits in a full ``n_qubits``-qubit Hilbert space. For 1-qubit gates, this is easy and can be achieved with appropriate kronning of identity matrices. For 2-qubit gate...
[ "Lift", "a", "unitary", "matrix", "to", "act", "on", "the", "specified", "qubits", "in", "a", "full", "n_qubits", "-", "qubit", "Hilbert", "space", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L229-L260
[ "def", "lifted_gate_matrix", "(", "matrix", ":", "np", ".", "ndarray", ",", "qubit_inds", ":", "List", "[", "int", "]", ",", "n_qubits", ":", "int", ")", ":", "n_rows", ",", "n_cols", "=", "matrix", ".", "shape", "assert", "n_rows", "==", "n_cols", ","...
ec98e453084b0037d69d8c3245f6822a5422593d
train
lifted_gate
Lift a pyquil :py:class:`Gate` in a full ``n_qubits``-qubit Hilbert space. This function looks up the matrix form of the gate and then dispatches to :py:func:`lifted_gate_matrix` with the target qubits. :param gate: A gate :param n_qubits: The total number of qubits. :return: A 2^n by 2^n lifted v...
pyquil/unitary_tools.py
def lifted_gate(gate: Gate, n_qubits: int): """ Lift a pyquil :py:class:`Gate` in a full ``n_qubits``-qubit Hilbert space. This function looks up the matrix form of the gate and then dispatches to :py:func:`lifted_gate_matrix` with the target qubits. :param gate: A gate :param n_qubits: The to...
def lifted_gate(gate: Gate, n_qubits: int): """ Lift a pyquil :py:class:`Gate` in a full ``n_qubits``-qubit Hilbert space. This function looks up the matrix form of the gate and then dispatches to :py:func:`lifted_gate_matrix` with the target qubits. :param gate: A gate :param n_qubits: The to...
[ "Lift", "a", "pyquil", ":", "py", ":", "class", ":", "Gate", "in", "a", "full", "n_qubits", "-", "qubit", "Hilbert", "space", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L263-L281
[ "def", "lifted_gate", "(", "gate", ":", "Gate", ",", "n_qubits", ":", "int", ")", ":", "if", "len", "(", "gate", ".", "params", ")", ">", "0", ":", "matrix", "=", "QUANTUM_GATES", "[", "gate", ".", "name", "]", "(", "*", "gate", ".", "params", ")...
ec98e453084b0037d69d8c3245f6822a5422593d
train
program_unitary
Return the unitary of a pyQuil program. :param program: A program consisting only of :py:class:`Gate`.: :return: a unitary corresponding to the composition of the program's gates.
pyquil/unitary_tools.py
def program_unitary(program, n_qubits): """ Return the unitary of a pyQuil program. :param program: A program consisting only of :py:class:`Gate`.: :return: a unitary corresponding to the composition of the program's gates. """ umat = np.eye(2 ** n_qubits) for instruction in program: ...
def program_unitary(program, n_qubits): """ Return the unitary of a pyQuil program. :param program: A program consisting only of :py:class:`Gate`.: :return: a unitary corresponding to the composition of the program's gates. """ umat = np.eye(2 ** n_qubits) for instruction in program: ...
[ "Return", "the", "unitary", "of", "a", "pyQuil", "program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L284-L298
[ "def", "program_unitary", "(", "program", ",", "n_qubits", ")", ":", "umat", "=", "np", ".", "eye", "(", "2", "**", "n_qubits", ")", "for", "instruction", "in", "program", ":", "if", "isinstance", "(", "instruction", ",", "Gate", ")", ":", "unitary", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
lifted_pauli
Takes a PauliSum object along with a list of qubits and returns a matrix corresponding the tensor representation of the object. Useful for generating the full Hamiltonian after a particular fermion to pauli transformation. For example: Converting a PauliSum X0Y1 + Y1X0 into the matrix .. code...
pyquil/unitary_tools.py
def lifted_pauli(pauli_sum: Union[PauliSum, PauliTerm], qubits: List[int]): """ Takes a PauliSum object along with a list of qubits and returns a matrix corresponding the tensor representation of the object. Useful for generating the full Hamiltonian after a particular fermion to pauli transfor...
def lifted_pauli(pauli_sum: Union[PauliSum, PauliTerm], qubits: List[int]): """ Takes a PauliSum object along with a list of qubits and returns a matrix corresponding the tensor representation of the object. Useful for generating the full Hamiltonian after a particular fermion to pauli transfor...
[ "Takes", "a", "PauliSum", "object", "along", "with", "a", "list", "of", "qubits", "and", "returns", "a", "matrix", "corresponding", "the", "tensor", "representation", "of", "the", "object", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L301-L340
[ "def", "lifted_pauli", "(", "pauli_sum", ":", "Union", "[", "PauliSum", ",", "PauliTerm", "]", ",", "qubits", ":", "List", "[", "int", "]", ")", ":", "if", "isinstance", "(", "pauli_sum", ",", "PauliTerm", ")", ":", "pauli_sum", "=", "PauliSum", "(", "...
ec98e453084b0037d69d8c3245f6822a5422593d
train
tensor_up
Takes a PauliSum object along with a list of qubits and returns a matrix corresponding the tensor representation of the object. This is the same as :py:func:`lifted_pauli`. Nick R originally wrote this functionality and really likes the name ``tensor_up``. Who can blame him? :param pauli_sum: Paul...
pyquil/unitary_tools.py
def tensor_up(pauli_sum: Union[PauliSum, PauliTerm], qubits: List[int]): """ Takes a PauliSum object along with a list of qubits and returns a matrix corresponding the tensor representation of the object. This is the same as :py:func:`lifted_pauli`. Nick R originally wrote this functionality an...
def tensor_up(pauli_sum: Union[PauliSum, PauliTerm], qubits: List[int]): """ Takes a PauliSum object along with a list of qubits and returns a matrix corresponding the tensor representation of the object. This is the same as :py:func:`lifted_pauli`. Nick R originally wrote this functionality an...
[ "Takes", "a", "PauliSum", "object", "along", "with", "a", "list", "of", "qubits", "and", "returns", "a", "matrix", "corresponding", "the", "tensor", "representation", "of", "the", "object", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L343-L356
[ "def", "tensor_up", "(", "pauli_sum", ":", "Union", "[", "PauliSum", ",", "PauliTerm", "]", ",", "qubits", ":", "List", "[", "int", "]", ")", ":", "return", "lifted_pauli", "(", "pauli_sum", "=", "pauli_sum", ",", "qubits", "=", "qubits", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
lifted_state_operator
Take a TensorProductState along with a list of qubits and return a matrix corresponding to the tensored-up representation of the states' density operator form. Developer note: Quil and the QVM like qubits to be ordered such that qubit 0 is on the right. Therefore, in ``qubit_adjacent_lifted_gate``, ``lifte...
pyquil/unitary_tools.py
def lifted_state_operator(state: TensorProductState, qubits: List[int]): """Take a TensorProductState along with a list of qubits and return a matrix corresponding to the tensored-up representation of the states' density operator form. Developer note: Quil and the QVM like qubits to be ordered such that qu...
def lifted_state_operator(state: TensorProductState, qubits: List[int]): """Take a TensorProductState along with a list of qubits and return a matrix corresponding to the tensored-up representation of the states' density operator form. Developer note: Quil and the QVM like qubits to be ordered such that qu...
[ "Take", "a", "TensorProductState", "along", "with", "a", "list", "of", "qubits", "and", "return", "a", "matrix", "corresponding", "to", "the", "tensored", "-", "up", "representation", "of", "the", "states", "density", "operator", "form", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/unitary_tools.py#L359-L377
[ "def", "lifted_state_operator", "(", "state", ":", "TensorProductState", ",", "qubits", ":", "List", "[", "int", "]", ")", ":", "mat", "=", "1.0", "for", "qubit", "in", "qubits", ":", "oneq_state", "=", "state", "[", "qubit", "]", "assert", "oneq_state", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_abbrev_program
Create an abbreviated string representation of a Program. This will join all instructions onto a single line joined by '; '. If the number of instructions exceeds ``max_len``, some will be excluded from the string representation.
pyquil/operator_estimation.py
def _abbrev_program(program: Program, max_len=10): """Create an abbreviated string representation of a Program. This will join all instructions onto a single line joined by '; '. If the number of instructions exceeds ``max_len``, some will be excluded from the string representation. """ program_lin...
def _abbrev_program(program: Program, max_len=10): """Create an abbreviated string representation of a Program. This will join all instructions onto a single line joined by '; '. If the number of instructions exceeds ``max_len``, some will be excluded from the string representation. """ program_lin...
[ "Create", "an", "abbreviated", "string", "representation", "of", "a", "Program", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L229-L243
[ "def", "_abbrev_program", "(", "program", ":", "Program", ",", "max_len", "=", "10", ")", ":", "program_lines", "=", "program", ".", "out", "(", ")", ".", "splitlines", "(", ")", "if", "max_len", "is", "not", "None", "and", "len", "(", "program_lines", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
to_json
Convenience method to save pyquil.operator_estimation objects as a JSON file. See :py:func:`read_json`.
pyquil/operator_estimation.py
def to_json(fn, obj): """Convenience method to save pyquil.operator_estimation objects as a JSON file. See :py:func:`read_json`. """ with open(fn, 'w') as f: json.dump(obj, f, cls=OperatorEncoder, indent=2, ensure_ascii=False) return fn
def to_json(fn, obj): """Convenience method to save pyquil.operator_estimation objects as a JSON file. See :py:func:`read_json`. """ with open(fn, 'w') as f: json.dump(obj, f, cls=OperatorEncoder, indent=2, ensure_ascii=False) return fn
[ "Convenience", "method", "to", "save", "pyquil", ".", "operator_estimation", "objects", "as", "a", "JSON", "file", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L379-L386
[ "def", "to_json", "(", "fn", ",", "obj", ")", ":", "with", "open", "(", "fn", ",", "'w'", ")", "as", "f", ":", "json", ".", "dump", "(", "obj", ",", "f", ",", "cls", "=", "OperatorEncoder", ",", "indent", "=", "2", ",", "ensure_ascii", "=", "Fa...
ec98e453084b0037d69d8c3245f6822a5422593d
train
read_json
Convenience method to read pyquil.operator_estimation objects from a JSON file. See :py:func:`to_json`.
pyquil/operator_estimation.py
def read_json(fn): """Convenience method to read pyquil.operator_estimation objects from a JSON file. See :py:func:`to_json`. """ with open(fn) as f: return json.load(f, object_hook=_operator_object_hook)
def read_json(fn): """Convenience method to read pyquil.operator_estimation objects from a JSON file. See :py:func:`to_json`. """ with open(fn) as f: return json.load(f, object_hook=_operator_object_hook)
[ "Convenience", "method", "to", "read", "pyquil", ".", "operator_estimation", "objects", "from", "a", "JSON", "file", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L397-L403
[ "def", "read_json", "(", "fn", ")", ":", "with", "open", "(", "fn", ")", "as", "f", ":", "return", "json", ".", "load", "(", "f", ",", "object_hook", "=", "_operator_object_hook", ")" ]
ec98e453084b0037d69d8c3245f6822a5422593d
train
_one_q_sic_prep
Prepare the index-th SIC basis state.
pyquil/operator_estimation.py
def _one_q_sic_prep(index, qubit): """Prepare the index-th SIC basis state.""" if index == 0: return Program() theta = 2 * np.arccos(1 / np.sqrt(3)) zx_plane_rotation = Program([ RX(-pi / 2, qubit), RZ(theta - pi, qubit), RX(-pi / 2, qubit), ]) if index == 1: ...
def _one_q_sic_prep(index, qubit): """Prepare the index-th SIC basis state.""" if index == 0: return Program() theta = 2 * np.arccos(1 / np.sqrt(3)) zx_plane_rotation = Program([ RX(-pi / 2, qubit), RZ(theta - pi, qubit), RX(-pi / 2, qubit), ]) if index == 1: ...
[ "Prepare", "the", "index", "-", "th", "SIC", "basis", "state", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L406-L427
[ "def", "_one_q_sic_prep", "(", "index", ",", "qubit", ")", ":", "if", "index", "==", "0", ":", "return", "Program", "(", ")", "theta", "=", "2", "*", "np", ".", "arccos", "(", "1", "/", "np", ".", "sqrt", "(", "3", ")", ")", "zx_plane_rotation", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_one_q_pauli_prep
Prepare the index-th eigenstate of the pauli operator given by label.
pyquil/operator_estimation.py
def _one_q_pauli_prep(label, index, qubit): """Prepare the index-th eigenstate of the pauli operator given by label.""" if index not in [0, 1]: raise ValueError(f'Bad Pauli index: {index}') if label == 'X': if index == 0: return Program(RY(pi / 2, qubit)) else: ...
def _one_q_pauli_prep(label, index, qubit): """Prepare the index-th eigenstate of the pauli operator given by label.""" if index not in [0, 1]: raise ValueError(f'Bad Pauli index: {index}') if label == 'X': if index == 0: return Program(RY(pi / 2, qubit)) else: ...
[ "Prepare", "the", "index", "-", "th", "eigenstate", "of", "the", "pauli", "operator", "given", "by", "label", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L430-L453
[ "def", "_one_q_pauli_prep", "(", "label", ",", "index", ",", "qubit", ")", ":", "if", "index", "not", "in", "[", "0", ",", "1", "]", ":", "raise", "ValueError", "(", "f'Bad Pauli index: {index}'", ")", "if", "label", "==", "'X'", ":", "if", "index", "=...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_one_q_state_prep
Prepare a one qubit state. Either SIC[0-3], X[0-1], Y[0-1], or Z[0-1].
pyquil/operator_estimation.py
def _one_q_state_prep(oneq_state: _OneQState): """Prepare a one qubit state. Either SIC[0-3], X[0-1], Y[0-1], or Z[0-1]. """ label = oneq_state.label if label == 'SIC': return _one_q_sic_prep(oneq_state.index, oneq_state.qubit) elif label in ['X', 'Y', 'Z']: return _one_q_pauli_...
def _one_q_state_prep(oneq_state: _OneQState): """Prepare a one qubit state. Either SIC[0-3], X[0-1], Y[0-1], or Z[0-1]. """ label = oneq_state.label if label == 'SIC': return _one_q_sic_prep(oneq_state.index, oneq_state.qubit) elif label in ['X', 'Y', 'Z']: return _one_q_pauli_...
[ "Prepare", "a", "one", "qubit", "state", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L456-L467
[ "def", "_one_q_state_prep", "(", "oneq_state", ":", "_OneQState", ")", ":", "label", "=", "oneq_state", ".", "label", "if", "label", "==", "'SIC'", ":", "return", "_one_q_sic_prep", "(", "oneq_state", ".", "index", ",", "oneq_state", ".", "qubit", ")", "elif...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_local_pauli_eig_meas
Generate gate sequence to measure in the eigenbasis of a Pauli operator, assuming we are only able to measure in the Z eigenbasis. (Note: The unitary operations of this Program are essentially the Hermitian conjugates of those in :py:func:`_one_q_pauli_prep`)
pyquil/operator_estimation.py
def _local_pauli_eig_meas(op, idx): """ Generate gate sequence to measure in the eigenbasis of a Pauli operator, assuming we are only able to measure in the Z eigenbasis. (Note: The unitary operations of this Program are essentially the Hermitian conjugates of those in :py:func:`_one_q_pauli_prep`) ...
def _local_pauli_eig_meas(op, idx): """ Generate gate sequence to measure in the eigenbasis of a Pauli operator, assuming we are only able to measure in the Z eigenbasis. (Note: The unitary operations of this Program are essentially the Hermitian conjugates of those in :py:func:`_one_q_pauli_prep`) ...
[ "Generate", "gate", "sequence", "to", "measure", "in", "the", "eigenbasis", "of", "a", "Pauli", "operator", "assuming", "we", "are", "only", "able", "to", "measure", "in", "the", "Z", "eigenbasis", ".", "(", "Note", ":", "The", "unitary", "operations", "of...
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L470-L483
[ "def", "_local_pauli_eig_meas", "(", "op", ",", "idx", ")", ":", "if", "op", "==", "'X'", ":", "return", "Program", "(", "RY", "(", "-", "pi", "/", "2", ",", "idx", ")", ")", "elif", "op", "==", "'Y'", ":", "return", "Program", "(", "RX", "(", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
construct_tpb_graph
Construct a graph where an edge signifies two experiments are diagonal in a TPB.
pyquil/operator_estimation.py
def construct_tpb_graph(experiments: TomographyExperiment): """ Construct a graph where an edge signifies two experiments are diagonal in a TPB. """ g = nx.Graph() for expt in experiments: assert len(expt) == 1, 'already grouped?' expt = expt[0] if expt not in g: ...
def construct_tpb_graph(experiments: TomographyExperiment): """ Construct a graph where an edge signifies two experiments are diagonal in a TPB. """ g = nx.Graph() for expt in experiments: assert len(expt) == 1, 'already grouped?' expt = expt[0] if expt not in g: ...
[ "Construct", "a", "graph", "where", "an", "edge", "signifies", "two", "experiments", "are", "diagonal", "in", "a", "TPB", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L486-L512
[ "def", "construct_tpb_graph", "(", "experiments", ":", "TomographyExperiment", ")", ":", "g", "=", "nx", ".", "Graph", "(", ")", "for", "expt", "in", "experiments", ":", "assert", "len", "(", "expt", ")", "==", "1", ",", "'already grouped?'", "expt", "=", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
group_experiments_clique_removal
Group experiments that are diagonal in a shared tensor product basis (TPB) to minimize number of QPU runs, using a graph clique removal algorithm. :param experiments: a tomography experiment :return: a tomography experiment with all the same settings, just grouped according to shared TPBs.
pyquil/operator_estimation.py
def group_experiments_clique_removal(experiments: TomographyExperiment) -> TomographyExperiment: """ Group experiments that are diagonal in a shared tensor product basis (TPB) to minimize number of QPU runs, using a graph clique removal algorithm. :param experiments: a tomography experiment :return...
def group_experiments_clique_removal(experiments: TomographyExperiment) -> TomographyExperiment: """ Group experiments that are diagonal in a shared tensor product basis (TPB) to minimize number of QPU runs, using a graph clique removal algorithm. :param experiments: a tomography experiment :return...
[ "Group", "experiments", "that", "are", "diagonal", "in", "a", "shared", "tensor", "product", "basis", "(", "TPB", ")", "to", "minimize", "number", "of", "QPU", "runs", "using", "a", "graph", "clique", "removal", "algorithm", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L515-L535
[ "def", "group_experiments_clique_removal", "(", "experiments", ":", "TomographyExperiment", ")", "->", "TomographyExperiment", ":", "g", "=", "construct_tpb_graph", "(", "experiments", ")", "_", ",", "cliqs", "=", "clique_removal", "(", "g", ")", "new_cliqs", "=", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_max_weight_operator
Construct a PauliTerm operator by taking the non-identity single-qubit operator at each qubit position. This function will return ``None`` if the input operators do not share a natural tensor product basis. For example, the max_weight_operator of ["XI", "IZ"] is "XZ". Asking for the max weight ope...
pyquil/operator_estimation.py
def _max_weight_operator(ops: Iterable[PauliTerm]) -> Union[None, PauliTerm]: """Construct a PauliTerm operator by taking the non-identity single-qubit operator at each qubit position. This function will return ``None`` if the input operators do not share a natural tensor product basis. For exampl...
def _max_weight_operator(ops: Iterable[PauliTerm]) -> Union[None, PauliTerm]: """Construct a PauliTerm operator by taking the non-identity single-qubit operator at each qubit position. This function will return ``None`` if the input operators do not share a natural tensor product basis. For exampl...
[ "Construct", "a", "PauliTerm", "operator", "by", "taking", "the", "non", "-", "identity", "single", "-", "qubit", "operator", "at", "each", "qubit", "position", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L538-L557
[ "def", "_max_weight_operator", "(", "ops", ":", "Iterable", "[", "PauliTerm", "]", ")", "->", "Union", "[", "None", ",", "PauliTerm", "]", ":", "mapping", "=", "dict", "(", ")", "# type: Dict[int, str]", "for", "op", "in", "ops", ":", "for", "idx", ",", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_max_weight_state
Construct a TensorProductState by taking the single-qubit state at each qubit position. This function will return ``None`` if the input states are not compatible For example, the max_weight_state of ["(+X, q0)", "(-Z, q1)"] is "(+X, q0; -Z q1)". Asking for the max weight state of something like ["(+X,...
pyquil/operator_estimation.py
def _max_weight_state(states: Iterable[TensorProductState]) -> Union[None, TensorProductState]: """Construct a TensorProductState by taking the single-qubit state at each qubit position. This function will return ``None`` if the input states are not compatible For example, the max_weight_state of ["(+...
def _max_weight_state(states: Iterable[TensorProductState]) -> Union[None, TensorProductState]: """Construct a TensorProductState by taking the single-qubit state at each qubit position. This function will return ``None`` if the input states are not compatible For example, the max_weight_state of ["(+...
[ "Construct", "a", "TensorProductState", "by", "taking", "the", "single", "-", "qubit", "state", "at", "each", "qubit", "position", "." ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L560-L577
[ "def", "_max_weight_state", "(", "states", ":", "Iterable", "[", "TensorProductState", "]", ")", "->", "Union", "[", "None", ",", "TensorProductState", "]", ":", "mapping", "=", "dict", "(", ")", "# type: Dict[int, _OneQState]", "for", "state", "in", "states", ...
ec98e453084b0037d69d8c3245f6822a5422593d
train
_max_tpb_overlap
Given an input TomographyExperiment, provide a dictionary indicating which ExperimentSettings share a tensor product basis :param tomo_expt: TomographyExperiment, from which to group ExperimentSettings that share a tpb and can be run together :return: dictionary keyed with ExperimentSetting (specif...
pyquil/operator_estimation.py
def _max_tpb_overlap(tomo_expt: TomographyExperiment): """ Given an input TomographyExperiment, provide a dictionary indicating which ExperimentSettings share a tensor product basis :param tomo_expt: TomographyExperiment, from which to group ExperimentSettings that share a tpb and can be run to...
def _max_tpb_overlap(tomo_expt: TomographyExperiment): """ Given an input TomographyExperiment, provide a dictionary indicating which ExperimentSettings share a tensor product basis :param tomo_expt: TomographyExperiment, from which to group ExperimentSettings that share a tpb and can be run to...
[ "Given", "an", "input", "TomographyExperiment", "provide", "a", "dictionary", "indicating", "which", "ExperimentSettings", "share", "a", "tensor", "product", "basis" ]
rigetti/pyquil
python
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/operator_estimation.py#L580-L628
[ "def", "_max_tpb_overlap", "(", "tomo_expt", ":", "TomographyExperiment", ")", ":", "# initialize empty dictionary", "diagonal_sets", "=", "{", "}", "# loop through ExperimentSettings of the TomographyExperiment", "for", "expt_setting", "in", "tomo_expt", ":", "# no need to gro...
ec98e453084b0037d69d8c3245f6822a5422593d