parityos_addons
- class parityos_addons.interfaces.CirqExporter(parameter_map: Mapping[str, Any] | None = None, qubit_map: Mapping[Qubit, NamedQubit] | None = 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, Any] | None = None, qubit_map: Mapping[Qubit, NamedQubit] | None = 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.
- class parityos_addons.interfaces.QiskitExporter(parameter_map: Mapping[str, Any] | None = None, qubit_map: Mapping[Qubit, int] | None = None, qubits: Iterable[Qubit] | None = 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, Any] | None = None, qubit_map: Mapping[Qubit, int] | None = None, qubits: Iterable[Qubit] | None = 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.
- gate_to_qiskit(gate) Tuple[Gate, Iterator[int]]
Converts a gate to a (Qiskit instruction, qubit_indices) tuple.
- Parameters:
gate – a ParityOS gate instance.
- Returns:
a (Qiskit instruction, qubit_indices) tuple.
- 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:
the device has only 2-body connections;
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[Hashable, ...] | 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], Any]
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