question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Json serialize `cirq.ion.ion_gates.MSGate`

See original GitHub issue

Replace the existing class: https://github.com/quantumlib/Cirq/blob/ec9fc4506da394ce103c4cccc02d4993b91449ac/cirq-core/cirq/ion/ion_gates.py#L27

with


class MSGate(ops.XXPowGate):
    """The Mølmer–Sørensen gate, a native two-qubit operation in ion traps.
    A rotation around the XX axis in the two-qubit bloch sphere.
    The gate implements the following unitary:
        exp(-i t XX) = [ cos(t)   0        0       -isin(t)]
                       [ 0        cos(t)  -isin(t)  0      ]
                       [ 0       -isin(t)  cos(t)   0      ]
                       [-isin(t)  0        0        cos(t) ]
    """

    def __init__(self, *, rads: float):  # Forces keyword args.
        ops.XXPowGate.__init__(self, exponent=rads * 2 / np.pi, global_shift=-0.5)
        self.rads = rads

    def _with_exponent(self: 'MSGate', exponent: value.TParamVal) -> 'MSGate':
        return type(self)(rads=exponent * np.pi / 2)

    def _circuit_diagram_info_(
        self, args: 'cirq.CircuitDiagramInfoArgs'
    ) -> Union[str, 'protocols.CircuitDiagramInfo']:
        angle_str = self._format_exponent_as_angle(args, order=4)
        symbol = f'MS({angle_str})'
        return protocols.CircuitDiagramInfo(wire_symbols=(symbol, symbol))

    def __str__(self) -> str:
        if self._exponent == 1:
            return 'MS(π/2)'
        return f'MS({self._exponent!r}π/2)'

    def __repr__(self) -> str:
        if self._exponent == 1:
            return 'cirq.ms(np.pi/2)'
        return f'cirq.ms({self._exponent!r}*np.pi/2)'

    def _json_dict_(self) -> Dict[str, Any]:
        return cirq.protocols.obj_to_dict_helper(self, ["rads"])

    @classmethod
    def _from_json_dict_(cls, rads: float, **kwargs: Any) -> Any:
        return cls(rads=rads)


Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
vtomolecommented, Oct 28, 2021
0reactions
kyteinskycommented, Oct 28, 2021

Oh man, I just forked the repo. You beat me to it. 🤣

Read more comments on GitHub >

github_iconTop Results From Across the Web

cirq_ionq.ionq_native_gates.MSGate | Cirq | Google Quantum AI
A cirq.Gate representing self controlled by the given control values and qubits. This is a cirq.ControlledGate in the base implementation, ...
Read more >
Module: cirq_ionq | Cirq - Google Quantum AI
serializer module: Support for serializing gates supported by IonQ's API. ... (MS) gate is a two qubit gate native to trapped ions.
Read more >
Module: cirq_ionq.ionq_native_gates | Cirq | Google Quantum AI
Native gates for IonQ hardware. ... class MSGate : The Mølmer–Sørensen (MS) gate is a two qubit gate native to trapped ions.
Read more >
cirq_ionq.ionq_devices.IonQAPIDevice | Cirq
A device that uses the QIS gates exposed by the IonQ API.
Read more >
Module: cirq_ionq.serializer | Cirq - Google Quantum AI
... the serialized portions of a cirq.Circuit . class Serializer : Takes gates supported by IonQ's API and converts them to IonQ json...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found