text
stringlengths
81
112k
Left-multiplies the given axes of the wf tensor by the given gate matrix. Compare with :py:func:`targeted_einsum`. The semantics of these two functions should be identical, except this uses ``np.tensordot`` instead of ``np.einsum``. :param gate: What to left-multiply the target tensor by. :param wf: A...
Get the probabilities of measuring a qubit. :param wf: The statevector with a dimension for each qubit :param qubit: The qubit to measure. We will sum over every axis except this one. :return: A vector of classical probabilities. def get_measure_probabilities(wf, qubit): """ Get the probabilities ...
Given a gate ``Instruction``, turn it into a matrix and extract qubit indices. :param gate: the instruction :return: tensor, qubit_inds. def _get_gate_tensor_and_qubits(gate: Gate): """Given a gate ``Instruction``, turn it into a matrix and extract qubit indices. :param gate: the instruction :ret...
Sample bitstrings from the distribution defined by the wavefunction. Qubit 0 is at ``out[:, 0]``. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits) def sample_bitstrings(self, n_samples): """ Sample bitstrings from the distri...
Measure a qubit, collapse the wavefunction, and return the measurement result. :param qubit: Index of the qubit to measure. :return: measured bit def do_measurement(self, qubit: int) -> int: """ Measure a qubit, collapse the wavefunction, and return the measurement result. :pa...
Perform a gate. :return: ``self`` to support method chaining. def do_gate(self, gate: Gate): """ Perform a gate. :return: ``self`` to support method chaining. """ gate_matrix, qubit_inds = _get_gate_tensor_and_qubits(gate=gate) # Note to developers: you can use...
Apply an arbitrary unitary; not necessarily a named gate. :param matrix: The unitary matrix to apply. No checks are done :param qubits: A list of qubits to apply the unitary to. :return: ``self`` to support method chaining. def do_gate_matrix(self, matrix: np.ndarray, qu...
Reset the wavefunction to the |000...00> state. :return: ``self`` to support method chaining. def reset(self): """ Reset the wavefunction to the |000...00> state. :return: ``self`` to support method chaining. """ self.wf.fill(0) self.wf[(0,) * self.n_qubits] = ...
Sample bitstrings from the distribution defined by the wavefunction. Qubit 0 is at ``out[:, 0]``. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits) def sample_bitstrings(self, n_samples): """ Sample bitstrings from the distri...
Perform a gate. :return: ``self`` to support method chaining. def do_gate(self, gate: Gate): """ Perform a gate. :return: ``self`` to support method chaining. """ unitary = lifted_gate(gate=gate, n_qubits=self.n_qubits) self.wf = unitary.dot(self.wf) re...
Apply an arbitrary unitary; not necessarily a named gate. :param matrix: The unitary matrix to apply. No checks are done. :param qubits: The qubits to apply the unitary to. :return: ``self`` to support method chaining. def do_gate_matrix(self, matrix: np.ndarray, qubits: Sequence[int]): ...
Compute the expectation of an operator. :param operator: The operator :return: The operator's expectation value def expectation(self, operator: Union[PauliTerm, PauliSum]): """ Compute the expectation of an operator. :param operator: The operator :return: The operator'...
Sample bitstrings from the distribution defined by the wavefunction. Qubit 0 is at ``out[:, 0]``. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits) def sample_bitstrings(self, n_samples): """ Sample bitstrings from the distri...
Perform a gate. :return: ``self`` to support method chaining. def do_gate(self, gate: Gate) -> 'AbstractQuantumSimulator': """ Perform a gate. :return: ``self`` to support method chaining. """ unitary = lifted_gate(gate=gate, n_qubits=self.n_qubits) self.densit...
Apply an arbitrary unitary; not necessarily a named gate. :param matrix: The unitary matrix to apply. No checks are done :param qubits: A list of qubits to apply the unitary to. :return: ``self`` to support method chaining. def do_gate_matrix(self, matrix: np.ndarray, qu...
Measure a qubit and collapse the wavefunction :return: The measurement result. A 1 or a 0. def do_measurement(self, qubit: int) -> int: """ Measure a qubit and collapse the wavefunction :return: The measurement result. A 1 or a 0. """ if self.rs is None: ra...
Run the ANTLR parser. :param str quil: a single or multiline Quil program :return: list of instructions that were parsed def run_parser(quil): # type: (str) -> List[AbstractInstruction] """ Run the ANTLR parser. :param str quil: a single or multiline Quil program :return: list of instruct...
NB: Order of operations is already dealt with by the grammar. Here we can simply match on the type. def _expression(expression): # type: (QuilParser.ExpressionContext) -> Any """ NB: Order of operations is already dealt with by the grammar. Here we can simply match on the type. """ if isinstance(ex...
Apply an operator to two expressions. Start by evaluating both sides of the operator. def _binary_exp(expression, op): # type: (QuilParser.ExpressionContext, Callable) -> Number """ Apply an operator to two expressions. Start by evaluating both sides of the operator. """ [arg1, arg2] = expression.e...
Like the default getExpectedTokens method except that it will fallback to the rule name if the token isn't a literal. For instance, instead of <INVALID> for integer it will return the rule name: INT def get_expected_tokens(self, parser, interval_set): # type: (QuilParser, IntervalSet) -> Iterator ...
PyQuil has no constructs yet for representing gate instructions within a DEFCIRCUIT (ie. gates where the qubits are inputs to the call to the circuit). Therefore we parse them as a raw instructions. def exitCircuitGate(self, ctx: QuilParser.CircuitGateContext): """ PyQuil has no constructs yet ...
Helper function for typechecking / type-coercing arguments to constructors for binary classical operators. :param classical_reg1: Specifier for the classical memory address to be modified. :param classical_reg2: Specifier for the second argument: a classical memory address or an immediate value. :return: A...
Helper function for typechecking / type-coercing arguments to constructors for ternary classical operators. :param classical_reg1: Specifier for the classical memory address to be modified. :param classical_reg2: Specifier for the left operand: a classical memory address. :param classical_reg3: Specifier f...
Produces the RX gate:: RX(phi) = [[cos(phi / 2), -1j * sin(phi / 2)], [-1j * sin(phi / 2), cos(phi / 2)]] This gate is a single qubit X-rotation. :param angle: The angle to rotate around the x-axis on the bloch sphere. :param qubit: The qubit apply the gate to. :returns: A ...
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...
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...
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. def PHASE(angle, qubit): ...
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...
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, ...
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...
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], ...
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 ...
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...
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. def MEASURE(qubit, classical_reg): """ Produce a MEASURE instruction. :param qubit: The qubit to measure. :param class...
Produce a TRUE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE. def TRUE(classical_reg): """ Produce a TRUE instruction. :param classical_reg: A classical register to modify. :return: An instruction object repr...
Produce a FALSE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE. def FALSE(classical_reg): """ Produce a FALSE instruction. :param classical_reg: A classical register to modify. :return: An instruction object r...
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. def AND(classical_reg1, classical...
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. def IOR(classical_reg1, classical_reg2): """ Produce an inclusive OR instruction....
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. def XOR(classical_reg1, classical_reg2): """ Produce an exclusive OR instruction....
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. def MOVE(classical_reg1, classical_reg2): """ Produce a MOVE instruction. :param cl...
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. def EXCHANGE(classical_reg1, classical_reg2): """ Produce an EXCHANGE instruc...
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. def LOAD(target_reg, region_name, offset_reg): ""...
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. def ADD(classical_reg, right): """ Produce an ADD instruction. :param class...
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. def SUB(classical_reg, right): """ Produce a SUB instruction. :param classic...
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. def MUL(classical_reg, right): """ Produce a MUL instruction. :param classic...
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. def DIV(classical_reg, right): """ Produce an DIV instruction. :param class...
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. def EQ(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 instance. def LT(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 instance. def LE(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 instance. def GT(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 instance. def GE(classical_reg1, classical_reg2, classical_reg3): ...
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...
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...
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...
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...
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...
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....
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. def _get_label(placeholder, label_mapping, label_i): """Helper function to either get the appropriate label for a given placeholder or ge...
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. def instantiate_labels(instructions): """ Takes an iterable of instructions which may contain label placeholder...
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] ...
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...
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...
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. def get_classical_addresses_from_program(progr...
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. def percolate_declares(program: Program) -> Program: """ Move all the DECLARE statements to t...
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. def validate_protoquil(program: Program) -> None: """ Ensure that a program is valid ProtoQuil, ot...
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...
Copy all the members that live on a Program object. :return: a new Program 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._def...
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 def copy(self): """ Perform a shallow copy of this program. QuilAtom and AbstractIn...
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 ...
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 ...
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...
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...
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...
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...
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 ...
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] ...
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...
Converts the Quil program to a readable string. :param allow_placeholders: Whether to complain if the program contains placeholders. def _out(self, allow_placeholders): """ Converts the Quil program to a readable string. :param allow_placeholders: Whether to complain if the program co...
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...
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 conjugat...
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` ...
A decorator that sets up an error context, captures errors, and tears down the context. 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...
A decorator that logs a call into the global error context. This is probably for internal use only. 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): globa...
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 def generate_report(self, exception, trace): ...
Implements exp(-i theta X_{0}Y_{1}) :param theta: rotation parameter :return: pyquil.Program 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().in...
Evaluate the Hamiltonian bny operator averaging :param theta: :param hamiltonian: :return: def objective_fun(theta, hamiltonian=None, quantum_resource=QVMConnection(sync_endpoint='http://localhost:5000')): """ Evaluate the Hamiltonian bny operator averaging :param theta: ...
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. def _make_ram_program(program): """ Check that this program is a series of quantum gates with ter...
Perform a sequence of gates contained within a program. :param program: The program :return: self def do_program(self, program: Program) -> 'AbstractQuantumSimulator': """ Perform a sequence of gates contained within a program. :param program: The program :return: self...
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 def find_label(self, label: Label): """ Helper function that ...
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 ...
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. def ...
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...
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...
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, ...
Get a qubit from an object. :param qubit: An int or Qubit. :return: A Qubit instance 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 isinstan...
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. def unpack_classical_reg(c): """ Get the address for a classical register. :param c: A list of length 2, a pair...
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. def format_parameter(element): """ Formats a particular parameter. Essential...
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. ...
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 def _expression_to_string(expression): """ Recursively converts ...
Determine which parameters are contained in this expression. :param Expression expression: expression involving parameters :return: set of parameters contained in this expression :rtype: set def _contained_parameters(expression): """ Determine which parameters are contained in this expression. ...