Skip to content

Commit d0f20a8

Browse files
committed
Made randCirc produce random circuits with more of the gate set. Some cleanup in window.cpp
1 parent b0dba46 commit d0f20a8

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

src/QCViewer/window.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Authors: Alex Parent, Jacob Parker
3838
#include "QCLib/subcircuit.h"
3939

4040
using namespace std;
41-
void QCViewer::setup_gate_button (Gtk::Button* btn, GateIcon *g, vector<Gtk::TargetEntry> &listTargets)
41+
void QCViewer::setup_gate_button (Gtk::Button* btn, GateIcon *g)
4242
{
4343
btn->set_image (*g);
4444
btn->drag_source_set (listTargets);
@@ -120,15 +120,20 @@ void QCViewer::set_raxis ()
120120
shared_ptr<Gate> g = c.getSelectedGate ();
121121
if (g->type != Gate::RGATE) {
122122
cout << "UNEXPECTED THING HAPPENED!!!! " << __FILE__ << __LINE__ << endl;
123-
return;
124-
}
125-
RGate::Axis na;
126-
if (btn_RX.get_active ()) na = RGate::X;
127-
else if (btn_RY.get_active ()) na = RGate::Y;
128-
else na = RGate::Z;
129-
if (na != ((RGate*)g.get())->get_axis ()) {
130-
((RGate*)g.get())->set_axis (na);
131-
c.force_redraw ();
123+
} else {
124+
shared_ptr<RGate> rg = dynamic_pointer_cast<RGate>(g);
125+
RGate::Axis na;
126+
if (btn_RX.get_active ()) {
127+
na = RGate::X;
128+
} else if (btn_RY.get_active ()) {
129+
na = RGate::Y;
130+
} else {
131+
na = RGate::Z;
132+
}
133+
if (na != rg->get_axis ()) {
134+
rg->set_axis (na);
135+
c.force_redraw ();
136+
}
132137
}
133138
}
134139

@@ -137,22 +142,23 @@ void QCViewer::set_rval ()
137142
shared_ptr<Gate> g = c.getSelectedGate ();
138143
if (g->type != Gate::RGATE) {
139144
cout << "UNEXPECTED THING HAPPENED!!!! " << __FILE__ << __LINE__ << endl;
140-
return;
141-
}
142-
istringstream ss (m_RValEntry.get_text ());
143-
float nr;
144-
ss >> nr;
145-
if (ss.fail ()) {
146-
stringstream ss;
147-
ss << ((RGate*)g.get())->get_rotVal ();
148-
m_RValEntry.set_text (ss.str ());
149-
Gtk::MessageDialog dialog(*this, "Error");
150-
dialog.set_secondary_text("Rotation factor must be a floating point number.");
151-
dialog.run();
152-
return;
145+
} else {
146+
shared_ptr<RGate> rg = dynamic_pointer_cast<RGate>(g);
147+
istringstream ss (m_RValEntry.get_text ());
148+
float nr;
149+
ss >> nr;
150+
if (ss.fail ()) {
151+
stringstream ss;
152+
ss << rg->get_rotVal ();
153+
m_RValEntry.set_text (ss.str ());
154+
Gtk::MessageDialog dialog(*this, "Error");
155+
dialog.set_secondary_text("Rotation factor must be a floating point number.");
156+
dialog.run();
157+
return;
158+
}
159+
rg->set_rotVal (nr);
160+
c.force_redraw ();
153161
}
154-
((RGate*)g.get())->set_rotVal (nr);
155-
c.force_redraw ();
156162
}
157163

158164
void QCViewer::on_menu_about ()
@@ -432,8 +438,9 @@ void QCViewer::set_selection (vector<Selection> s)
432438
} else if (selections.size () == 1) {
433439
shared_ptr<Gate> gate = c.getSelectedGate();
434440
if (gate != NULL && gate->type == Gate::RGATE) {
441+
shared_ptr<RGate> rg = dynamic_pointer_cast<RGate>(gate);
435442
m_RGateEditFrame.show ();
436-
switch (((RGate*)gate.get())->get_axis ()) {
443+
switch (rg->get_axis ()) {
437444
case RGate::X:
438445
btn_RX.set_active ();
439446
break;
@@ -445,7 +452,7 @@ void QCViewer::set_selection (vector<Selection> s)
445452
break;
446453
}
447454
stringstream ss;
448-
ss << ((RGate*)gate.get())->get_rotVal ();
455+
ss << rg->get_rotVal ();
449456
m_RValEntry.set_text (ss.str ());
450457
} else {
451458
m_RGateEditFrame.hide ();
@@ -495,7 +502,8 @@ void QCViewer::set_subcircuit_name()
495502
{
496503
shared_ptr<Gate> g = c.getSelectedGate();
497504
if (g != NULL && g->type==Gate::SUBCIRC) {
498-
((Subcircuit*)g.get())->setName(m_SubcircNameEntry.get_text());
505+
shared_ptr<Subcircuit> sub = dynamic_pointer_cast<Subcircuit>(g);
506+
sub->setName(m_SubcircNameEntry.get_text());
499507
c.force_redraw();
500508
}
501509
}
@@ -505,7 +513,8 @@ void QCViewer::expand_subcirc()
505513
{
506514
shared_ptr<Gate> g = c.getSelectedGate();
507515
if (g != NULL && g->type==Gate::SUBCIRC) {
508-
((Subcircuit*)g.get())->expand = !((Subcircuit*)g.get())->expand;
516+
shared_ptr<Subcircuit> sub = dynamic_pointer_cast<Subcircuit>(g);
517+
sub->expand = !sub->expand;
509518
c.force_redraw();
510519
}
511520
}
@@ -519,7 +528,8 @@ void QCViewer::unroll_subcirc()
519528
{
520529
shared_ptr<Gate> g = c.getSelectedGate();
521530
if (g != NULL && g->type==Gate::SUBCIRC) {
522-
((Subcircuit*)g.get())->unroll = !((Subcircuit*)g.get())->unroll;
531+
shared_ptr<Subcircuit> sub = dynamic_pointer_cast<Subcircuit>(g);
532+
sub->unroll = !sub->unroll;
523533
c.force_redraw();
524534
}
525535
}
@@ -770,7 +780,7 @@ void QCViewer::setup_gate_icons()
770780
}
771781
for (unsigned int i = 0, y = 0, x = 0; i < gate_icons.size(); i++) {
772782
gate_buttons.push_back(manage(new Gtk::Button()));
773-
setup_gate_button (gate_buttons[i], gate_icons[i], listTargets);
783+
setup_gate_button (gate_buttons[i], gate_icons[i]);
774784
m_GatesTable.attach (*gate_buttons[i],x,x+1,y,y+1);
775785
x++;
776786
if (x > 3) {
@@ -804,4 +814,3 @@ void QCViewer::add_stock_item(const Glib::RefPtr<Gtk::IconFactory>& factory, con
804814
Gtk::Stock::add(Gtk::StockItem(stock_id, label));
805815
}
806816
}
807-

src/QCViewer/window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class QCViewer : public Gtk::Window
5353
void load_state (State* s);
5454
protected:
5555
void dummy(const Glib::RefPtr<Gdk::DragContext>&, Gtk::SelectionData&, guint, guint);
56-
void setup_gate_button (Gtk::Button*, GateIcon*, std::vector<Gtk::TargetEntry> &);
56+
void setup_gate_button (Gtk::Button*, GateIcon*);
5757

5858
// Signal handlers:
5959
virtual bool on_key_release_event(GdkEventKey* event);

utils/randCirc/randCirc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
def randCirc(qubits,gates):
44
s = ""
55
r = ""
6-
gateset = ["T","H","X","Y","Z","RZ(0.25)","RZ(0.5)"]
6+
gateset = ["T","T*","H","X","Y","Z","RX(1 pi/8)","RY(1 pi/4)","RZ(1 pi/2)"]
77
for i in range(qubits):
88
s += " "+str(i)
99
r += ".v"+s+"\n"

0 commit comments

Comments
 (0)