Skip to content

Make xmon gates parameterizable #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2018
Merged

Make xmon gates parameterizable #427

merged 4 commits into from
May 30, 2018

Conversation

kevinsung
Copy link
Collaborator

@kevinsung kevinsung commented May 25, 2018

Fixes #428

@kevinsung kevinsung requested a review from Strilanc May 25, 2018 20:27
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label May 25, 2018
@kevinsung
Copy link
Collaborator Author

Can't we just have Exp11Gate and ExpZGate subclass Rot11Gate and RotZGate?

@kevinsung
Copy link
Collaborator Author

run: ('mypy', '--config-file=/home/travis/build/quantumlib/Cirq/continuous-integration/mypy.ini', '[...]')
cirq/circuits/circuit.py:413: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/circuits/circuit.py:472: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/circuits/circuit.py:506: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/google/sim/xmon_simulator.py:137: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/google/sim/xmon_simulator.py:172: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/google/sim/xmon_simulator.py:252: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/google/sim/xmon_simulator.py:301: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/contrib/quirk/linearize_circuit.py:40: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"
cirq/contrib/qcircuit_diagram.py:121: error: Invalid type "cirq.ops.qubit_order.QubitOrderOrList"

What is this? Why didn't this come up before?

@Strilanc
Copy link
Contributor

Strilanc commented May 26, 2018

Can't we just have Exp11Gate and ExpZGate subclass Rot11Gate and RotZGate?

No. They define their matrices in different ways. (Different global phase.)

What is this? Why didn't this come up before?

Not sure why, but mypy sometimes gets confused by these kinds of type values. This is worked around as part of #429 by moving the assignment to its own file. The really weird thing is it doesn't reproduce across machines.

@kevinsung
Copy link
Collaborator Author

No. They define their matrices in different ways. (Different global phase.)

I don't understand. The matrices for Exp11Gate and ExpZGate are

    def matrix(self):
        if not self.has_matrix():
            raise ValueError("Don't have a known matrix.")
        return ops.Rot11Gate(half_turns=self.half_turns).matrix()

and

    def matrix(self):
        if not self.has_matrix():
            raise ValueError("Don't have a known matrix.")
        return ops.RotZGate(half_turns=self.half_turns).matrix()

respectively. How are these different from Rot11Gate and RotZGate?

@kevinsung
Copy link
Collaborator Author

Travis is failing due to the same bug at #430

@@ -108,8 +107,12 @@ def transform_job(self, job):
errors = np.random.random(self.realizations) < self.p
if any(errors):
key = self._parameter_name + str(error_number)
new_error_gate = copy.deepcopy(gate)
new_error_gate.half_turns = Symbol(key)
if isinstance(gate, xmon_gates.ExpWGate):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want special-case code for specific types of gates. A better approach is for the list of depolarizing gates to provide a mechanism for making each gate.

ops.PhaseableGate,
PotentialImplementation):
ops.Rot11Gate):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid mixing the Xmon gate hierarchy with the the basic gate hierarchy, so that we are free to modify the definitions of the gates. For example, if we choose to change the global phase of the gate then this inheritance relationship breaks.

Yes, that does mean that the xmon gates are (nearly) copy-pastes of the usual gates.

def matrix(self):
if not self.has_matrix():
raise ValueError("Don't have a known matrix.")
return ops.RotZGate(half_turns=self.half_turns).matrix()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. This line was actually wrong. It doesn't match the definition given in the docs.

def __hash__(self):
return hash((ExpZGate, self.half_turns))
return hash((type(self), self.half_turns))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reasoning for changing this? This new definition means that a gate deriving from ExpZ is automatically not equal to any ExpZ gate, instead of just being e.g. an ExpZ with some extra methods.

@Strilanc
Copy link
Contributor

I don't understand. The matrices for Exp11Gate and ExpZGate are [the same as Rot.. gates]

Ah, the ExpZGate isn't supposed to have the same matrix. The Exp11Gate matrix being the same is something that I see as incidental as opposed to being related to how the Rot11Gate is defined.

@Strilanc
Copy link
Contributor

#430 has now fixed that mypy bug by pinning the version. Once that's merged and synced, your builds should start to pass.

@kevinsung
Copy link
Collaborator Author

Ok I mostly reverted back to the old code and fixed the ExpZGate matrix.

Copy link
Contributor

@Strilanc Strilanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I'll switch these over to EigenGate at some point.

@kevinsung kevinsung merged commit 3b19e04 into quantumlib:master May 30, 2018
@kevinsung kevinsung deleted the parameterize_xmon_gates branch May 30, 2018 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants