Skip to content
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

First iteration of the outputting to Quil. #2903

Merged
merged 14 commits into from
May 8, 2020
Merged

Conversation

ajhanus
Copy link
Contributor

@ajhanus ajhanus commented Apr 13, 2020

Fixes: #2386.

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Apr 13, 2020
@ajhanus
Copy link
Contributor Author

ajhanus commented Apr 13, 2020

See #2386.

Copy link
Collaborator

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

@hanusaj Make sure all the Travis builds pass.

@@ -126,6 +127,17 @@ def _qasm_(self, args: 'cirq.QasmArgs',
args.validate_version('2.0')
return args.format('swap {0},{1};\n', qubits[0], qubits[1])


# SwapPowGate in QUIL is equivalent to the PSWAP Gate in QUIL
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's this for?

output_func(protocols.quil(decomposed_op, formatter=self.formatter))

def rename_defgates(output: str):
result = output
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add docstring


@value.value_equality(approximate=True)
class QuilOneQubitGate(ops.SingleQubitGate):

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add docstring

import numpy as np

def to_quil_complex_format(num):
cnum = complex(str(num))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add docstring

@@ -666,6 +685,11 @@ def _circuit_diagram_info_(self, args: 'cirq.CircuitDiagramInfoArgs'
wire_symbols=('H',),
exponent=self._diagram_exponent(args))

def _has_stabilizer_effect_(self) -> Optional[bool]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that it only said we added this because of the addition of the quil function. I tried moving this below the _quil_ function to see if that will remove the change.

@@ -807,17 +833,24 @@ def _circuit_diagram_info_(self, args: 'cirq.CircuitDiagramInfoArgs'
wire_symbols=('@', '@'),
exponent=self._diagram_exponent(args))

def _has_stabilizer_effect_(self) -> Optional[bool]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@@ -972,17 +1005,23 @@ def controlled(self,
result.control_qid_shape[:-1])
return result

def _has_stabilizer_effect_(self) -> Optional[bool]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.


@value.value_equality
class QuilTwoQubitGate(ops.TwoQubitGate):

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add docstring


if len(op.qubits) == 1:
return QuilOneQubitGate(mat).on(*op.qubits)
return QuilTwoQubitGate(mat).on(*op.qubits)
Copy link
Contributor Author

@ajhanus ajhanus Apr 21, 2020

Choose a reason for hiding this comment

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

I've been trying to find a way to cover the above three lines. It seems like all of the gates decompose into gates that we have defined _quil_ functions for. My thoughts are to make a basic custom one and two qubit gate that wouldn't decompose but I haven't been able to figure out a good way to do that. @vtomole Do you know of anywhere in the repository I could find an example that may have done something similar?

Copy link
Collaborator

Choose a reason for hiding this comment

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

qasm_output_test.py doesn't help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. qasm_output_test.py doesn't help because QASM had basic gates that were not implemented. Whereas with QUIL, all gates I have found decompose into QUIL standard gates which do not require the fallback function from protocols.decompose

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm going to merge and file an issue for this.

@vtomole vtomole changed the title First implementation of the outputting to Quil. First iteration of the outputting to Quil. May 8, 2020
@vtomole vtomole added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 8, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label May 8, 2020
@CirqBot CirqBot merged commit a98041d into quantumlib:master May 8, 2020
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels May 8, 2020
tonybruguier pushed a commit to tonybruguier/Cirq that referenced this pull request Aug 23, 2020
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.

Implement quil_output.py
4 participants