parityos_addons — ParityOS 2.1.1 documentation

# parityos_addons

class parityos_addons.interfaces.CirqExporter(parameter_map: Mapping[str, object] = None, qubit_map: Mapping[Qubit, NamedQubit] = None)

  Tool to convert ParityOS circuits to Cirq circuits.

  Instantiate the CirqExporter with a qubit map and a parameter map. Then use the to_cirq method to convert ParityOS circuits to Cirq circuits.

  EXAMPLE:

    qubit_map = {Qubit(i): cirq.NamedQubit(str(i)) for i in range(10)} parameter_map = {‘theta’: sympy.Symbol(‘theta’), ‘gamma’: sympy.Symbol(‘gamma’)} cirq_exporter = CirqExporter(qubit_map, parameter_map) cirq_circuit = cirq_exporter.to_cirq(parityos_circuit)

  __init__(parameter_map: Mapping[str, object] = None, qubit_map: Mapping[Qubit, NamedQubit] = None)

    Converts the circuit to a cirq circuit.

    Parameters:

      - parameter_map – a mapping of the form {parameter_name: parameter_value}, where the parameter_name is a string that is used as a parameter_name in the ParityOS circuit, and parameter_value is a number like object (int, float, numpy float or a Sympy symbol are all valid). Optional. If not given, then an empty dictionary is used instead.

      - qubit_map – a mapping of the form {ParityOS_qubit: cirq_qubit}, where cirq_qubit is a Cirq NamedQubit instance. Optional. If not given, then ParityOS Qubits are automatically converted into cirq.NamedQubit instances with the same label.

  gate_to_cirq(gate: Gate) → GateOperation

    Converts a gate to a Cirq gate operation.

    Parameters:

      gate – a ParityOS gate instance.

    Returns:

      a Cirq gate operation.

  to_cirq(circuit: Gate | Circuit) → Circuit

    Converts the circuit to a Cirq circuit.

    Parameters:

      circuit – a ParityOS circuit of quantum gates.

    Returns:

      a Cirq circuit.

class parityos_addons.interfaces.QiskitExporter(parameter_map: Mapping[str, object] = None, qubit_map: Mapping[Qubit, int] = None, qubits: Iterable[Qubit] = None)

  Tool to convert ParityOS circuits to Qiskit quantum circuits.

  Instantiate the QiskitExporter with a qubit map and a parameter map. Then use the to_qiskit method to convert a ParityOS circuit to Qiskit quantum circuit.

  EXAMPLE:

    from qiskit.circuit import Parameter parameter_map = {‘theta’: Parameter(‘$theta$’), ‘gamma’: Parameter(‘$gamma$’)} qiskit_exporter = QiskitExporter(parameter_map) qiskit_circuit = qiskit_exporter.to_qiskit(parityos_circuit)

  __init__(parameter_map: Mapping[str, object] = None, qubit_map: Mapping[Qubit, int] = None, qubits: Iterable[Qubit] = None)

    Converts the circuit to a Qiskit circuit.

    Parameters:

      - parameter_map – a mapping of the form {parameter_name: parameter_value}, where the parameter_name is a string that is used as a parameter_name in the ParityOS circuit, and parameter_value is a number like object (int, float, numpy float or a Qiskit Parameter object are all valid). Optional. If not given, then an empty dictionary is used instead.

      - qubit_map – a mapping of the form {ParityOS_qubit: qubit_index}, where qubit_index is the integer index of the qubit in the Qiskit qubit register. Optional.

      - qubits – an iterable of ParityOS qubits. This is used to generate a qubit_map where each qubit is mapped onto its index in the sequence. Optional. Either a qubit_map or a qubits iterable must be given.

  append_qiskit_gate(qiskit_circuit: <module 'qiskit.circuit' from '/usr/local/lib/python3.11/site-packages/qiskit/circuit/__init__.py'>, gate: ~parityos.base.gates.Gate)

    Creates a qiskit gate corresponding to the ParityOS Gate instance and appends it to the qiskit circuit. :param qiskit_circuit: the qiskit circuit to which we want to append the gate :param gate: the ParityOS Gate that is appended to the circuit

  to_qiskit(circuit: Gate | Circuit) → QuantumCircuit

    Converts the circuit to a Qiskit quantum circuit.

    Parameters:

      circuit – a ParityOS circuit of quantum gates.

    Returns:

      a Qiskit QuantumCircuit object.

parityos_addons.qaoa.generate_qaoa(parityos_output: ParityOSOutput, unitary_pattern: str) → tuple[Circuit, dict[str, tuple[float, float]]]

  Generates a QAOA quantum circuit and a dictionary with parameter bounds. The QAOA quantum circuit is composed of several unitary propagators, related to the problem Hamiltonian, driver terms and Parity constraints. The parameter bounds dictionary maps the parameter names used in the quantum circuit onto a (lower bound, upper bound) tuple of floats for each classical QAOA parameter in the QAOA circuit.

  Parameters:

    - parityos_output (ParityOSOutput) –

      The compiler output as an object of ParityOSOutput, containing information about the compiled problem and the raw constraint circuit, as defined in the response schema. Assumptions:

      > 1. the device has only 2-body connections;

      > 2. the interaction coefficients are explicit numbers, not strings.

    - unitary_pattern (str) –

      the pattern of unitaries to use in each repetition. Should be a string with the following characters:

      > - Z: the problem Hamiltonian

      > - X: the driver Hamiltonian

      > - C: the constraint Hamiltonian

      The string is expressed in time order, from left to right.

  Example:

    To create a ParityOS QAOA circuit of order p=3, create the circuit from a ParityOSOutput object with a unitary_pattern of order 3: qaoa_circuit, parameter_bounds = generate_qaoa(parityos_output, ‘XCZXCZXCZ’)

class parityos_addons.spin_hamiltonians.SpinZ(label: str | int | tuple[int, ...] | Qubit)

  Represents a classical Ising spin value (+1 or -1) or the Z-eigenvalue of a Pauli Z operator.

parityos_addons.spin_hamiltonians.spinz_to_constraint(product: Mul) → EqualityConstraint

  Convert a product of SpinZ objects into an EqualityConstraint object :param product: product of SpinZ objects and an optional integer factor that is +1 or -1. :return: an EqualityConstraint object

parityos_addons.spin_hamiltonians.spinz_to_hamiltonian(expr: Add | Mul, spinz_constraints: Iterable = ()) → ProblemRepresentation

  Convert an expression containing sums of products of SpinZ objects into a ParityOS problem representation.

  Parameters:

    - expr – an expression containing sums of products of SpinZ objects

    - spinz_constraints – an iterable of products of SpinZ objects that define additional constraints for the optimization problem.

  Returns:

    a ProblemRepresentation object

parityos_addons.spin_hamiltonians.untie_spinz_product(product: Mul) → tuple[frozenset[Qubit], object]

  Spilt a product of spinz and other factors into a pure product of SpinZ object and the product of all the remaining factors.

  Parameters:

    product – A product of SpinZ objects and other Sympy objects or numbers

  Returns:

    a tuple where the first item is the product of SpinZ objects and the second item is the product of all the other factors in the term