Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Add print circuit method #59

Merged
merged 1 commit into from
May 3, 2019

Conversation

danbev
Copy link
Contributor

@danbev danbev commented May 2, 2019

Summary

This commit introduces a print method to the Circuit class. The idea is
to give a visual representation of the quantum circuit.

Details and comments

The motivation for this is as a learning aid to help understand the
circuit created. The implementation can probably be made more efficient
but I wanted to get some feedback on this feature and if it is
worth pursuing/spending time on (or perhaps it could be useful as is
and developed further as required).

Node REPL example:
> const { Circuit, Gate } = require('./index.js');
undefined

> const c = Circuit.createCircuit(1);
undefined
> c.addGate(Gate.x, 0, 0).print()

          column 0
wire 0 ---[x]-----------

undefined
> c.addGate(Gate.cx, 1, [0, 1]).print()

          column 0      column 1
wire 0 ---[x]-----------[cx]----------
                         |
wire 1 -----------------[*]-----------
Node example:
const { Circuit, Gate } = require('./index.js');
const c = Circuit.createCircuit(2);
c.addGate(Gate.x, 0, 0).print()
c.addGate(Gate.cx, 1, [0, 1]).print()
$ node example

          column 0
wire 0 ---[x]-----------

wire 1 -----------------


          column 0      column 1
wire 0 ---[x]-----------[cx]----------
                         |
wire 1 -----------------[*]-----------

@danbev danbev requested a review from jesusprubio May 2, 2019 11:37
@danbev
Copy link
Contributor Author

danbev commented May 2, 2019

CI failures happen to me locally on the master branch. I've not seen this before but perhaps others have?

@omarcostahamido
Copy link
Member

nice implementation, @danbev .
No idea regarding the Travis CI error. Do you want to give it another try to create the pull request?

O

@danbev
Copy link
Contributor Author

danbev commented May 2, 2019

@omarcostahamido The tests are now passing for me locally on the master branch so hopefully this should just be a matter of re-running the Travis build (I don't have the rights to do so). I can force push which should trigger it too I think but I'll hold off a little before doing so.

This commit introduces a print method to the Circuit class. The idea is
to give a visual representation of the quantum circuit.

The motivation for this is as a learning aid to help understand the
circuit created. The implementation can probably be made more efficient
but I wanted to get some feedback on this feature and if it is
worth pursuing/spending time on (or perhaps it could be useful as is
and developed further as required).
@jesusprubio
Copy link
Contributor

Sorry I was travelling. I will check because it happens from time to time, maybe with a little retry setup we could avoid it.

BTW, really nice PR, thanks 😄

@jesusprubio jesusprubio merged commit f9657c5 into qiskit-community:master May 3, 2019
@danbev danbev deleted the printCircuit branch May 3, 2019 07:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants